Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity - SetActive() on GameObject dont works on child's objects

I have the following line of code:

GameObject.Find("_obstacles").SetActive(false);

It serves to leave an inactive object, but the children of this object are not getting with the same status.

My result is:

enter image description here

The objects children do not inherit the parent object state (as stated in the > documentation of Unity)!

But the obsolete method "SetActiveRecursively()" works for me! O.o The Very strange, no?

enter image description here

like image 959
Igor Avatar asked Oct 26 '25 03:10

Igor


1 Answers

Took a look into Unitys Docs and found this, seems like they havent removed it yet but its not recomended to use this either.

SetActiveRecursively has been kept in the API for 4.0 but its use is not recommended and it may be removed in the future

Basically all it does it loop through the parents children and set i active/inactive. Create a custom method just in case Unity removes the SetActiveRecursively completelty from thier API.

Link to SetActiveRecursively()

And last but not least, seems like Unitys created gameobject in play mode doesnt inherit that parents active state.

like image 66
JohannesAndersson Avatar answered Oct 29 '25 10:10

JohannesAndersson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!