So the docs are a little vague about it so I wanted to double-check that I understand Scriptables right:
In Unity Editor if I change my ScriptableObjects’ data (in Play Mode or manually) those changes will persist.
When the project is compiled and published the data from ScriptableObjects is saved into the compiled project. This data can be accessed and even edited. But all the data in all ScriptableObjects is reloaded each session back to its “compiled” state. Am I correct?
So if compile the project that has Coins ScriptableObject with the value of 0, then those Coins data can be seen and edited but it is still reloaded back to 0 each play session. Is that right?
Yes thats correct. They are assets. In Editor if you make a change to an asset then the change is written(providing the asset is set dirty and the project is saved), however in the player we never write, we only read from the asset data and so no changes persist between runs as the changes are only stored in memory, not on disk.
Thank you for your answer! Can you also tell me one more thing, please?
If I use CreateInstance inside compiled project, this function will create a ScriptableObject but it will be deleted when the session will be over, is that right?
And also, if my gameobject creates some amount of ScriptableObjects should I bother calling Destroy function to clear all of the spawned Sciptables before destroying the gameobject itself? Or it will happen automatically?
Yes. You need to write to/load from a persistent media yourself if you want to preserve the state between sessions.
Technically they will be destroyed automatically when there are no other references to them.
See garbage collection in Unity and the potential problems with it.
Pretty sure that’s not the case - ScriptableObjects are UnityEngine.Objects, so they live both on the script side of the game and on the c++ engine side, so you have to tell the engine to destroy them (using Destroy), otherwise they’ll leak.
You’re right. I really need to stop to answer questions before my first coffee in the morning, I miss crucial elements without my caffeine infuse in my own thought-process.