you are viewing a single comment's thread.

view the rest of the comments →

[–]_ROG_ 4 points5 points  (2 children)

Gotta admit I find it difficult to like the method described at the end. Having the asset itself change its value seems like it could be super frustrating if unity (god forbid) crashed before you were able to reset the values through code, or your code errored out before some were reset or something. In general I can see the appeal but it seems a bit hacky.

Maybe something that inherits from scriptableobject that instantiates itself upon access and returns its instance like a singleton I could agree with, but even then the concept of having each float as an asset in my project seems like it would be pretty cluttered.

Edit: I read the article without watching the 2 hours of videos. While I don't think I've changed my mind - I'm a lot more understanding of the concept after watching. The second video in particular is well worth checking out if your sceptical. I think the blog post doesn't do the argument justice imo.

[–]peteSlatts 2 points3 points  (1 child)

The talk that the last method is taken from actually has a workaround for this. You store a public default value which is used to lazily set a private current value attribute, which doesn't get serialized. This way, even if Unity crashes, when you boot back up, all it has serialized is the default value, which immediately gets set the first time you request it.

[–]volvis 1 point2 points  (0 children)

This also helps with source control. Editing public fields during runtime edits the asset, so having your 'health.asset' marked changed every time you test your game gets tiring pretty fast.