|
I'd like to be notified when object is about to be destroyed. I don't see a GameObject.OnDestroy method, any way to know this?
(comments are locked)
|
|
Edit: OnDestroy now exists in Unity 3.2. No need for hacks anymore! Use OnDisable. You can determine whether the script is being disabled or the object is destroyed/deactivated like this:
NOTE! The above code longer works the same in Unity 3. It works like this instead, which seems less useful: Thanks for the quick reply!
Apr 30 '10 at 08:27 PM
jc_lvngstn 1
Note, that OnDisable will be called (with the gameObject set to inactive) when loading a new level, even if DontDestroyOnLoad has been called.
Oct 30 '10 at 12:55 PM
Matthew A
Is there any way to have a OnDestroy callback?? this would be really usefull when child objects get destroyed and some cleanup needs to be done...
Jan 11 '11 at 02:12 PM
David St-Hilaire
The way to get an OnDestroy callback is for UT to program one into Unity.
Jan 11 '11 at 10:04 PM
Eric5h5
I just tried your code examples with Unity 3.3, and it behaves as described in your first code fragment, the second code fragment is not correct for 3.3.
Jun 15 '11 at 03:53 PM
Wolfram
(comments are locked)
|
