- Home /
scriptableObject as database "a question about memory"
Well 1st, I am a person who learns by himself from the resources available on the web, and I didn't have a college education in programming, so I hope everyone excuse me if this question sounds silly.
I am learning how to create dialogue; I made the component that will reference a ScriptableObject which is the dialogue database; it holds a list of dialogue class which is only a class containing a string and a nested type. It contains the name and image of the speaker , So i need to know if the number of elements effect the game's performance. Every conversation may contain about 20 classes or more, so if the game has 200 conversations this means the ScriptableObject will hold 4000 class instances. Is this right way to do this or should I do something about it? maybe split database into 2 or 3 scriptableObject ..
my question is: Do all of the 4000 class instances load into memory when i reference the scriptableObject database or does only the class that the component needs from database will load into memory?
I really need help or guide where I start to read or topic for search to improve my knowledge about this. Thanks for helping me learn
Answer by jackmw94 · Feb 20, 2021 at 04:53 PM
You are right to be concerned about that, when you load the main scriptable object it will load everything it's holding into memory too. ScriptableObjects are great but this is where they come undone a little.
I'd advise you to look into addressables as a way to only load the assets you need. Or sqllite is an option: https://medium.com/@rizasif92/sqlite-and-unity-how-to-do-it-right-31991712190
Thanx for your help
i will read about the topics you mentioned
i found thread about my question in unity fourm https://forum.unity.com/threads/resolved-when-reference-asset-from-scriptableobject-is-load-and-unload-from-memory.555358/
scriptableObject only loads when something in the scene reference it i made profile test the same they did in the thread and this my results
There is one thing if you null the reference and pressed on play the profiler will show there is ScriptableObject referenced even if it null on mono?!
my predictions is :it maybe happen because i made test in editor i mean the editor session still running so the null field still point to something i recompiled the code then the profiler showed it null in memory