Now since setActiveRecursively obsolete in Unity4 I’m trying to change all lines I used after upgrading the project.
I have a problem with cases like below How do you do the same job? this.gameObject.SetActiveRecursively(false); this.gameObject.active = true;
Actording to Unity 3.5 to 4 guideline they say “setting GameObject.active is equivalent to calling GameObject.SetActive(). Calling GameObject.SetActiveRecursively() is equivalent to calling GameObject.SetActive() on the GameObject and all of it’s children.”
So from looking here it should be this.gameObject.SetActive(false); this.gameObject.SetActive(true); which is nonsense
Should I loop all children and make them SetActive false? – again I think nonsense…
So if you have any idea or solution please share Cheers
That’s the call you have to perform now. They simply changed the way it works. From Unity’s point of view it is nonsense to have a game object that is inactive, but the children of it are active. That’s why they did this change.
That is not needed. The idea behind this makes sense to me, but the method name is misleading if you are used to older Unity versions.
I don’t think you get the idea. What I’m trying is not making active the child and disable the parent. What I’m trying to do is,
Deactivate all childs
And only activate the parent game object so say you have three GameObjects, A, B and C, so that B and C are children of A.
I want to deactivate B and C and only activate A.
I think only way to do that is looping through B and C and make them SetActive false. And A.SetActive(true).
That’s exactly something that should not be done anymore, that’s why Unity changed the api. But there are alternatives. You may have another child of A named D. And D takes over the role of A. So A can always be active and when you want the deactivate A from the previous implementation, you simply do it with D.
I think there may be a misunderstanding - he’s trying to have the parent active and the children inactive - which is completely legal in Unity4. There just isn’t a one-command way to do it anymore, unless I’m missing it.
Note that while you can loop through the children and SetActive(false) on each one, this will produce different results in Unity4 than Unity3, because it’s setting the activeSelf state of the objects to false. Meaning that if you later SetActive the parent to true, the children will stay inactive.
What`s the solution than?
I deactivated all children objects(not trough the parent,rather with a method findgameobjectswithtag(“things i want to switch on off”)),but when I activated the parent(in which I put those objects and who was always enabeled anyway) the children did not reactivate.
C# explanation please.
If you explicitly deactivated all children they would not get activated just because you re-activated their parent. That is a normal and correct behavior. You as a developer is in control what is and what isn’t activated at any given time. If you made a decision to deactivate all children then Unity cannot decide to reactivate it for you. If you need to control children individually then control them individually (you shouldn’t be finding them with a tag though - use getChildren() maybe recursively).