So, I wanted to test the unity 4.0 version, yeah !
But not really …
Some functions are obsolete (that’s ok, this is how we improve softwares), but I don’t find equivalent methods (and this is not really ok …)
The active attribute was hidden behind an accessor (SetActive), good. I’m now looking for the equivalent for SetActiveRecursively. If someone has an idea to avoid me to implement a recursive method to overload it, please, tell me
EDIT : To be clear, I don’t criticize this choice, I’m just annoyed that there is no obvious method to do this recursivity…
We’ve just upgraded to Unity 4 from 3.5, and have a decent sized project to deal with. Most of the cases where we were using SetActiveRecursively, we were simply toggling on/off the entire tree beneath. However in some cases we have a situation where some of the scene objects underneath a particular GameObject were inactive, and we did in fact want to iterate over all of them and make them active, regardless of their previous state. Since for us a warning is an error, continuing to rely on the deprecated SetActiveRecursively GameObject function wasn’t an option. Instead we changed to using a static helper method, shown below, which replicates the behaviour of SetActiveRecursively on any given game object.
/// Our own version of GameObject.SetActiveRecursively,
/// for those cases where we have known
/// inactive objects somewhere beneath the root
/// and do want to activate or deactivate all of them.
public static void SetActiveRecursively(GameObject rootObject, bool active)
foreach (Transform childTransform in rootObject.transform)
From the Unity 4 release notes:
We have changed how the active state of GameObjects is handled. GameObjects active state will now affect child GameObjects, so setting a GameObject to inactive will now turn the entire sub-hierarchy inactive. This may change the behavior of your projects. GameObject.active and GameObject.SetActiveRecursively() have been deprecated. Instead, you should now use the GameObject.activeSelf and GameObject.activeInHierarchy getters and the GameObject.SetActive() method.