Order of OnGUI on different objects

Hi all,

My OnGUI seems not to be working properly. Every now and again, placing one texture will cause all the others to turn off again, only to come on whenever the user touches the phone screen (anywhere). I have no idea why this might be happening. I found a workaround though, and that was to place those textures on a different OnGUI on another object, a child of the object that contains the main script. I’ve noticed that this places things BEFORE the main script (its parent). So for example, I need to place the background on the child object’s OnGUI, or it will cover the parent’s. Will this always be the case? Will the order for setting OnGUI always be child first, then parent?


It’s not related to objects or children in any way. Use GUI.depth to control rendering order. Without using GUI.depth, the order is undefined, so it may randomly appear to “work” depending on things like children etc., but that’s just coincidence and can’t be relied on at all.