Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity How to change the Rendering Order of A canvas

I'm using unity 5.3 and I'm trying to change the Rendering Order of two overlayed cross platform controls which each reside in their own canvas.

In previous versions you could bring the window into focus using

GUI.FocusWindow(0);

However this does not work with the new system. I've also tried modifying the order in the editor window which has done nothing.

Does anyone know how I can move a control to be on top of the other?

like image 664
johnny 5 Avatar asked Jun 08 '16 00:06

johnny 5


People also ask

What determines the Order in which objects are rendered in Unity?

In the Built-in Render Pipeline, the order in which Unity renders objects is based on two things: which render queue the object is in, and how Unity sorts objects within that render queue. Unity sorts objects into groups called render queues.

How do you sort renderers in Unity?

Conventionally renderers in Unity will be sorted by several criteria such as Order in Layer or distance from camera. However, it was not possible to ensure that a group of renderers that share a common root be sorted together. Well, until now…

How do I change the default render queue in Unity?

By default, Unity places objects in the render queue specified in their Unity shader. You define this value using the [Queue] SubShader tag. You can override this value on a per-material basis. In the Unity Editor, you can do this in the material Inspector by setting the Render Queue property.

Is there a way to sort layers on multiple canvas renderers?

You can set Sorting Layer and Order on a Canvas, so juggling multiple canvases is an awkward, but possible solution. I found this script on Unity Answers (can't find the original link) and there are similar scripts elsewhere. It exposes sorting layer/order for ALL mesh renderers!


2 Answers

After doing some research I found the proper way to change the Canvas Rendering Order. There is a property in the Canvas for the Sort Order, which is really the render order.

enter image description here.

Just as a note remember the controls you want to be on top should have a larger order than the control on bottom.

like image 159
johnny 5 Avatar answered Sep 22 '22 07:09

johnny 5


Order in the editor window should work here. Are you sure you're changing the order of elements inside one canvas element?

Note that the order of elements in the Canvas game object is the order everything is rendered in - so the last thing you have in canvas will be the last thing drawn, so it will be on top of everything.

Here's how it works: editor window with canvas ordering example

This is demonstrated with Unity 5.3.4, with much older Unity it can be different (there was a change of the way how children were enumerated somewhere in 5.0 or 5.1 AFAIK).

like image 38
Krzysztof Bociurko Avatar answered Sep 21 '22 07:09

Krzysztof Bociurko