'Unity Parent's SetActive() influences child?
I discovered that when setting a parent true, that parent's children are all called 'OnEnable' function. Even though children are all set true already.
I don't want to call 'OnEnable' function even though it's already set true.
How can I prevent it?
Solution 1:[1]
This documentation on execution order may be useful to you.
If you have logic in the child objects that you do not want to call from the parent being set as active, than remove it from OnEnable and hook it up to your own delegate somewhere else.
You are going to have the same thing happen with the Start and Awake functions as well. Personally I would try and find a way to abstract your code a bit more to make sure the child object is not dependent on the parent.
Solution 2:[2]
SetActive() behavior is inherited by all of the children of that particular gameObject. In order to solve your problem you most likely have to restructure your GameObject hierarchy.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BenjaFriend |
| Solution 2 |
