Reputation: 4003
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:
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?
Upvotes: 4
Views: 3305
Reputation: 4620
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.
Upvotes: 3
Reputation: 104
Of course it does not impact child GameObjects
You can have an Object A, with 2 sub-objects B and C, have them configured with B Active and C Inactive.
Now you want your hierarchy active by calling A.SetActive(true)
, that doesn't mean you want to activate C.
The question is why your sub-objects are Inactive themself? Because an inactive parent is enough.
I suggest you to keep your sub-objects Active, or to develop your own SetActiveRecursively method looping through all Transform.
Upvotes: -1