- Home /
How to check if OnDestroy has finished?
I have a script that adds a LineRenderer to the parent GameObject. When I try to destroy and readd that script to the same GameObject, it will tell me that the script can not add a LineRenderer because the old one has not been destroyed yet, even though I destroy the LineRenderer component in the OnDestroy function.
My Code:
The function that readds the component:
void OnWeaponBehaviourUpdate(string weaponBehaviourName){
Destroy(weaponInstance.GetComponent(weaponBehaviourStringOld));
weaponInstance.AddComponent(weaponBehaviourString);
}
(weaponBehaviourStringOld == weaponBehaviourString)
And this is the OnDestroy function in the readded script:
void OnDestroy(){
Destroy (lineRenderer);
}
I hope I have gave you enough code and look forward to an answer!
Thanks in advance, Xera
Answer by Eric5h5 · Mar 21, 2013 at 10:29 PM
As the docs say, "Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering." You could use DestroyImmediate instead.
Your answer