- Home /
Method like Awake(), but for destroying an object?
Awake() is called when a script is being loaded. Is there a similar method for when a script is being unloaded or disabled? Or some other way that your script can know it's being unloaded? Should I just use a destructor?
Comment
Best Answer
Answer by Drakestar · Jul 05, 2012 at 02:31 PM
There's MonoBehavior.OnDestroy()
http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnDestroy.html
Duh! Awake() and Start() don't begin with "On", so I just glanced over all of the methods that begin with "On" in the documentation. Guess I should have been a little more careful. =P
Answer by whydoidoit · Jul 05, 2012 at 02:39 PM
You can also use OnDisable and OnEnable for information about an object being enabled and disabled in addition to OnDestroy().