- Home /
GetComponentsInChildren not working
I have a small section of code that calculates a combined bounding box for a set of meshes.
Bounds allBounds = new Bounds(Vector3.zero,Vector3.zero);
Renderer[] theRenders = thePart.GetComponentsInChildren<Renderer>();
foreach(Renderer theRender in theRenders){
allBounds.Encapsulate(theRender.bounds);
}
This code works 99% of the time, but sometimes the GetComponetsInChildren call returns zero found objects. However, checking the same object (with no changes) the next frame, it will work.
Any ideas on what could be causing this? I only caught this ass it's part of my UI, I can't imagine the other bugs it could cause in my other code.
This code also runs flawlessly under unity 3.5.6, it was only after updating to unity 4 that the problem showed up.
No, it's being called in an Update loop. It is triggered when you hover over a UI item (using NGUI)
I resolved this for now by reverting back to unity 3.5, but I wanted to present this in case it's a bug.
Will do. Have to get around to replicating it in an example. I don't think they want a 15GB project :/
I would never put a GetComponentsInChildren inside an update loop. Can you not cache the array beforehand ins$$anonymous$$d? If not, you could double check the list, if it's null, redo the search.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Where are tesselation shaders? 1 Answer
Unity4 .Active replacement 2 Answers
How to import the object from server to unity 2 Answers
Setting Scroll View Width GUILayout 1 Answer