- Home /
Cannot destroy GameObject while it is being activated or deactivated.
Cannot destroy GameObject while it is being activated or deactivated.
What does it mean ? How can i check object is being activated or deactivated ?
I want to destroy gameobject on OnDisable(). How can i do that ?
This is odd. By definition the GameObject is being deactivated during OnDisable. I destroy objects quite frequently during OnDisable, and have never had a problem.
Unless this is something new in 4.6?
@bubzy There are use cases for Destroy as part of OnDisable. I use it for object pooling. The pooled object calls SetActive(false). Another component then checks if it needs to be returned to the pool. If the object is not to be returned Destroy is called.
Parent have 30 child object. When parent object was disabled , I want to destory all child objects . but exception occur in Windows Phone 8 device
Answer by koray1396 · Nov 28, 2014 at 05:12 PM
you may use;
void OnDisable(){
foreach(Transform t in transform){
Destroy(t.gameObject);
}
}
Yes I am using same codes and error occur in Windows Phone 8.Any idea ?
Your answer
Follow this Question
Related Questions
OnDisable() getting called from Destroy() 6 Answers
If destroyed? how to check if destroyed? 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Detect when GameObject has been deleted / removed from scene 10 Answers
How to remove an object from an array once it has been destroyed 1 Answer