- Home /
What sets Canvas.renderOrder and why would it not respect the sorting order?
I have a very strange issue in my game at the moment. I have multiple canvases all using the 'screen space - overlay' render mode, and their sorting orders aren't being respected with out any good reason.
There are 4 Canvas's in the scene. They all have unique sorting orders. One is set to 0. the others are set to a higher value. Around 20-22.
What I am doing is that in game I am instancing these other canvas as a part of view system that pops up screens in our game. The crazy thing is that sometimes the in game ui, which has a sorting order of 0, sometimes shows above the others which have a higher sorting order. When we remove a couple of the canvas' then things stabilize and respect the sorting order. I am really not sure what is going on.
After looking at this all afternoon, and doing digging we found out that the canvases also have a .renderOrder value which isn't exposes to us. It seems to be the internal variable uses at run time to actual determine the final render order for each individual thing. This seems like a very valid and reasonable thing to exist, but it isn't respecting the sorting order due to unknown reasons.
I have a attached an image showing some debug logs where I pop open the new canvases 3 times. (I create and then delete them 3 times). They show at the time the canvases are created what the .renderOrder, .sortingOrder (we set), .overrideSorting variables. It shows how sometimes the values make sense and sometimes they don't at all.
The order of the debug groupings is as follows
Main Canvas for the instance group (instanced)
In game UI (already exists in scene)
Secondary for view group (instanced with first)
Tertiary for view group (instanced with first)
It would be very helpful to get some more insight to what determines the .renderOrder value is for a canvas in the game and possibly how multiple canvases may break the system. Thanks!