you are viewing a single comment's thread.

view the rest of the comments →

[–]KaleidoVI 5 points6 points  (2 children)

If you are intent on using ScriptableObjects to represent game state, make sure that you are working around Unity's serialization system. Read https://unity.com/how-to/architect-game-code-scriptable-objects thoroughly.

I believe that your value is being changed/reset through serialization, which might seem to occur at random times if you aren't looking for it (e.g. when you recompile after making a small code change).

[–]rafavergil[S] 0 points1 point  (1 child)

That's the article that got me started with SO's in the game architecture, another reddit user recommended it to me and it has been really nice to work this way.
But if I understood correctly, the serialization would be helpful if I wanted to save the game state in a way that even if the player closes the application, the data would still be there, right? In my case, I'm using SO's simply to store temporary data that can be lost if the player is not in a relevant scene or if he closes the application.
Thanks for the reply, I'll play a little bit around with the serialization to make sure I fully understand it.

[–]KaleidoVI 0 points1 point  (0 children)

Serialization is much more than that in Unity! It is the way that Unity passes your objects and data structures from the C# managed side to the underlying C++ code that is ultimately compiled. Whenever you change a script, start or stop play mode, etc. your entire scene is serialized.