Unity3D Canvas Render Order Anomalies

I’m posting this here just so that other’s who experience similar issues know they are not alone and that there is indeed an issue within Unity. (Reported as Issue 707375)

The following occurred in Unity 4.6 and the current 5.1.1f however it did not occur in 5.0. Update: This is now fixed in Unity 5.1.2, thanks Unity!

I’ve spotted in a few different locations in projects that just occasionally, often for a frame or two in an animation a canvas image will flicker. On further inspection it is evident that the item in question gets rendered at the wrong time.

I’ve not been able to determine exactly what causes the issue as usually it’s in quite a complex scene and as soon as I start to edit it the issue goes away. However I have now created a simple test scene which shows up the issue.

Here’s the simple scene a screen space canvas (the bug occurs in other modes too) with red, white and blue Image components being rendered in that order as expected:

Screenshot_062515_011848_PM

Now all I do is add 7 Image components before these and bang the blue image component is now rendered before the white one.

Screenshot_062515_011740_PM

If I add an extra component or delete any of them the bug goes away. Of note the bug does reappear when there are more components in the scene, this scene started off life with 100’s of images in a complex hierarchy and I slowly removed components to get to this simplified version. During this process the sorting order would change but I have not managed to get the issue with anything simpler than this.

You can download this test project here: TestROrder5

I also have another scene which I have not managed to simplify (yet) which has a hierarchy of images which have their scale animated via Unity’s animation system, their active state is not changed and during 2-3 frames of a 50s animation a couple of images render before they should, disappearing behind something.

Leave a Reply