Create a multi-window application
Configure your Unity project to add a secondary window at runtime with a script.
Read time 4 minutesLast updated 14 days ago
Use the Windowing APIs to create multiple windows for your application at runtime. Each window can display content from a camera, allowing you to render different content across multiple windows.
Unity creates the main window by default. The following steps demonstrate how you can use the Windowing APIs to add a secondary window to your application at runtime. You can use the same approach to create up to eight windows in total, including the main window.
Prerequisites
- Set up the Unity Editor to build for Embedded Linux or QNX. For more information, refer to the documentation on Get started with Embedded Linux and Get started with QNX.
- Access to the target hardware where you can run the application to verify the multi-window behavior. For more information, refer to the documentation on Configurations for embedded platforms.
1. Configure the scene and camera components
Set up your Unity project with the required build profiles for the target platform and configure cameras for each window as follows:
-
In your Unity project, create a build profile for the target platform.
-
Create a scene for the build profile.
-
Add a second camera to the scene (menu:>GameObject
?
).Camera?
-
Select the second camera.
-
In thewindow, open the Output section, and set the Target Display to Display 2.Inspector
?
This configuration ensures that the second camera renders to Display 2 which corresponds to the second window you want to create at runtime.
Display UI only on the second window (Optional)
Follow these steps if you want to display UI elements on the second window:
- Create a canvas (menu: GameObject > UI (Canvas) > Canvas).
- Select the canvas.
- In the Inspector window, set the Render Mode to Screen Space - Overlay and Target Display to Display 2.
2. Create the second window using C# script
Use a script that creates the second window to display content from the camera you configured in Step 1.
-
In the Project window, create a C# script (context menu: Create > MonoBehaviour Script).
-
Replace the default script with the following:using System.Collections.Generic;using UnityEngine;using UnityEngine.Windowing;public class CreateWindowExample : MonoBehaviour{ List<DisplayInfo> displayInfos = new List<DisplayInfo>(); void Start() { DisplayInfo.GetLayout(displayInfos); var settings = new GameWindowCreationSettings( title: "Second Window", width: 600, height: 400, position: new Vector2Int(0, 0), cameraDisplayIndex: 1, // Target Display index of the camera displayInfo: displayInfos[0] // Physical display that will contain the window ); var op = GameWindowManager.Create(settings); op.completed += (AsyncOperation o) => { // Triggers when the window creation is complete Debug.Log($"Window Created: {op.window.GetTitle()}"); }; }}
-
Configure the following key parameters as required.
- : Specifies which physical display contains the window. Retrieve the display information using
displayInfo(recommended) orDisplayInfo.GetLayout. In the example,Screen.GetDisplayLayoutuses the first physical display.displayInfos[0] - Specifies which camera's content to display based on the camera's Target Display setting from Step 1. For example, use
cameraDisplayIndex:for Display 1, and0for Display 2.1
-
Attach the script to a GameObject in the scene.
Notes:
- Call and wait for the operation to complete before using the new window. Do not access the new window until the operation is complete as this results in a null reference error.
GameWindowManager.Create - To monitor the changes in the window state, use the class methods such as PositionChangedThisFrame or ResolutionChangedThisFrame.
GameWindow
3. Build and run the application on target hardware
- Build the Player for the Embedded Linux or QNX build profile.
- Deploy and run the Player on the target hardware to verify whether the additional window appears on the correct display.
Limitations
Consider the following limitations when designing a multi-window application:
- Unity supports a maximum of eight target displays, which limits the number of windows you can create.
- In fullscreen mode, secondary windows use the resolution of the physical display they appear on. Changing the window resolution through the method isn't supported.
GameWindow.SetResolution - GetLogicalDpi is currently not supported on Embedded Linux or QNX platforms. The method returns a default value of on these platforms.
0