On version 4.6.5f1; which I need to stay on for a while (don’t ask! xD)
According to the docs, which using the override I should be able to get all components on the given GameObject and all of its children, regardless of any of the objects being active. Or perhaps I am reading that slightly wrong?
Couple of questions:
Should this care if the component is enabled / disabled (which is frustrating)
Does anyone actually find this works with inactive objects (see example code)
Bounds lBounds = new Bounds();
GameObject lGo = new GameObject(“PARENT”);
lGo.AddComponent();
lGo.transform.localScale = new Vector3(50, 50, 50);
lGo.SetActive(false);
GameObject lChildGo = new GameObject(“CHILD”);
lChildGo.AddComponent();
lChildGo.transform.parent = lGo.transform;
lChildGo.transform.localScale = new Vector3(20, 20, 20);
//encapsulate all collider bounds
if (lColliders != null &&
lColliders.Length > 0)
{
lEnumerator = lColliders.GetEnumerator();
while (lEnumerator.MoveNext() == true)
{
lBounds.Encapsulate(((Collider)lEnumerator.Current).bounds);
}
}
Debug.Log(lBounds.size);
This code returns 0 size always
I would expect bounds to be 1000, which works when the GameObject is active
If the child is inactive and the parent is active, the size is 50
So inactive objects are always ignored?
Same result if component is disabled as inactive
Thanks guys, your right the GetComponentsInChildren is working fine!
Bounds is return as always 0 size when object / component is inactive
Although still frustrating