Hi, after working with Unity 3.5.7 for so long, I’m now trying to migrate to Unity 4 due to the need to split the package into OBB files. SO, I’m asking about the difference of a GameObject’s active state between those two versions. So the SetActiveRecursively is obsolete, and the SetActive is always recursive now, correct? So, what’s the difference between GameObject.activeSelf and GameObject.activeInHierarchy? And what about the children gameobject’s components’s enabled state then, if I were to SetActive the parent? What about the components’s overridable callback functions OnDisable and OnEnable? Do they also also be called when I SetActive the parent, and not the child gameobject that has the said components?
The API documentation explains it fairly well, but here’s a quick synopsis.
In Unity 4 SetActive() is not recursive, it only affects the GameObject you call it on BUT in Unity 4 if a GameObject’s parents are inactive the GameObject itself is ALWAYS inactive regardless of its own instance state.
If you were setting children of inactive parents as active in U3 you will need to make changes. You may also have some issues when importing scenes and prefabs from U3 because of “mixed state”. The safest bet is to write a script that sets everything back to active in U4, and then go through and disable only the parent level objects.
Thanks for the answer. That’s what I thought. The activeSelf state will be overruled as false if the activeInHierarchy state is false, correct? But does the OnEnable and OnDisable of a child becalled if I were to activate / deactivate the parent? As I always use SetActiveRecursively in my project, the mixed state won’t matter. But I do use OnEnable and OnDisable quite a lot. So if calling SetActive on the parent didn’t call these callback functions, then I’ve got a lot of painful work to trace and remake all of them ahead of me.
Thanks for the answer. Just what I needed. But yeah, the first thing I will have to do is testing the OnEnable and OnDisable first. And if needed, I’ll implement that SetActiveRecursively function. Thanks again.