Multiple Cameras

Learn how to make a Unity project work with a multi-LeiaCamera setup.
A screenshot from the MultipleCameras sample scene included with the Leia Unity SDK
When developing Unity content for Leia displays, it is common practice that developers will want two separate cameras: one to render the 3d scene, and another to render the UI on top of it. This has several benefits, including ensuring the UI is always rendered on top and enabling having different lighting and camera settings for the UI than for the scene camera. The MultipleCameras sample scene provides an example demonstrating how a multi-camera setup can be implemented using the Leia Unity SDK. The sample scene can be found in Assets/LeiaLoft/Examples/MultipleCameras.
The hierarchy of the MultipleCameras sample scene has two cameras: the SceneCamera, and the UICamera. Both cameras are rendering 3d objects to the display simultaneously with the UICamera rendering on top and using alpha blending to show the SceneCamera below.
The UICamera renders the buttons:
What the UI Camera renders
While the SceneCamera renders the background, asteroids, player space ship, and everything else contained in the game scene:
What the scene camera renders


The following outlines a method to setup a multi-LeiaCamera configuration in your project for a 3d scene with a 3d UI rendered on top of it

Step 1 - Create Cameras

Create two cameras in your scene, and attach the LeiaCamera component to both. For this example, we will name the first one SceneCamera, and the second one UICamera.

Step 2 - Set the Camera's Depths

Set the scene camera's depth to a lower value, like -1, and the UI camera's depth to a higher value, like 1, to ensure the UI camera is rendered on top of the scene camera.

Step 3 - Set culling masks

Set the culling mask of the UI camera to "UI". Set the culling mask of the scene camera to include every layer except UI.

Step 4 - Set the layers of UI objects

Set the layer of all the 3d UI objects in your scene to "UI"

Step 5 - Set Clear Flags and Background Color Alpha

Set the clear flags for the UI camera to "Solid Color" and set the background color's alpha to 0.

Step 6 - Enable Alpha Blending

Check the "Enable Alpha Blending" checkbox in the LeiaDisplay component
Now when we run the game, we should see the 3d UI rendered on top of the rest of the scene.
The final result - UI camera rendering 3d UI buttons on top of the scene camera