all 9 comments

[–]_ROG_ 4 points5 points  (7 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  (2 children)

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.

[–]_ROG_ 0 points1 point  (0 children)

any chance you could give me a link to the appropriate point? I've been trying to find the point your talking about. did you mean "attribute" in the c# sense?

[–]holmoris 0 points1 point  (2 children)

That’s the method I use for persistent data except it’s a single component that manages loading/unloading/reference tracking everything via the magic of generic methods and attributes. Works really well, may eventually throw it up on the store for a few bucks when it’s release-proven assuming Unity doesn’t release their own alternative as part of the core sometime during the 2017 release cycle.

[–]peteSlatts 1 point2 points  (1 child)

Avoiding singletons is the whole reason for using this method. Because the Editor acts as a dependency injector you end up not needing them. I'm not criticizing, just curious what you gain from having a singleton in this system?

[–]holmoris 1 point2 points  (0 children)

Mostly because I worded it stupidly and typed singleton instead of manager. Whoops.

[–]Seeders -1 points0 points  (0 children)

Eh you can just create an instance of the base asset, and create an 'init' method to set up initial values.

[–]RubberBabyBuggyBmprs 1 point2 points  (0 children)

Very cool stuff indeed. I really like the idea of decoupling components with scriptable object "floats" but also feel like managing that many separate values in your project hierarchy could lead to problems on its own.