Symptoms:
- I have multiple cameras but require them to render and update in a particular order.
Cause:
Unity has multiple Render Pipelines. We will show how to change the camera render order for each one.
Resolution:
Built-In Render Pipeline
When you create a new camera in Unity, it will generate that camera with a depth of zero. Take a look at this screenshot to see where the Depth field shows up in the default component inspector.
The depth is considered the rendering order. The lower the depth value, the earlier it will be in the rendering stack.
If you have more than one camera, all you need to do is set the depth value of each camera in ascending order for which they will draw. For example:
Camera A - Depth Value of 0 //This will render first.
Camera B - Depth Value of 1 //This will render second.
Camera C - Depth Value of 2 //This will render last.
Here is an example:
If you have two cameras with the same depth, they will render in the order they were added to the scene. We don't recommend leaving cameras on the same depth, and you should always explicitly order them.
The depth value can be edited via script using the camera.depth property.
When using OnRenderImage for an image effect, the image effect will always be applied directly after its attached camera. Given the same scenario as above, if all three cameras have a single image effect attached to them, the render order would look like this:
Camera A - Depth Value of 0 //This will render first.
ImageEffect1
Camera B - Depth Value of 1 //This will render second.
ImageEffect2
High Definition Render Pipeline (HDRP)
For HDRP, you can find the depth attribute in the Output section of the Camera component.
This attribute works similar to the Depth attribute in the built-in render pipeline but, for advanced effects, including camera stacking, we recommend checking HDRP's Graphics Compositor.
Universal Render Pipeline (URP)
For URP, you can find the Priority attribute under the Camera component's Rendering section.
The Priority attribute works similarly to the Depth attribute in the built-in render pipeline. If you want to use this attribute for camera staking, we recommend you check the URP built-in solution: URP Camera Stacking.
More Information: