- Home /
Scriptable object gets deleted with a class that holds it?
Hello guys, could you please help me?
There is a class that holds a scriptable object variable, with that variable being initialized. Therefore instance of scriptable object was loaded into this variable.
The question is, if I delete the class that holds such variable, will the scriptable object instance be destroyed as well? Or do I have to destroy the scriptable object first, and then delete the class?
Thank you very much!
Answer by Joyrider · Aug 11, 2013 at 05:20 PM
If your scriptable object isn't referenced anymore, Unity should handle the destruction of that scriptable object in your memory at the next Garbage Collection.
if you want to make sure it gets destroyed at the same time as the instance that references it, just do Destroy (myScriptableObject);
in the OnDestroy of the referencer. Or DestroyImmediate it it's referenced from an editor script.
Your answer
Follow this Question
Related Questions
Updating variable on another script. It is not working. 2 Answers
How to build up the class structure for an object 1 Answer
[C#] Is there a way to call static variables directly, independent from parent class? 3 Answers
[SOLVED] How do I change the values of an HDRP Volume Profile at Runtime? 1 Answer
Share Public Classes 1 Answer