# Create a multi-window application

> Configure your Unity project to add a secondary window at runtime with a script.

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](/engine/6000.6/manual/platform-specific/embedded-systems/embedded-linux/get-started.md) and [Get started with QNX](/engine/6000.6/manual/platform-specific/embedded-systems/qnx/get-started.md).
* 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](/engine/6000.6/manual/platform-specific/embedded-systems/embedded-platforms-configurations.md).

## 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:

1. In your Unity project, [create a build profile](/engine/6000.6/manual/building-and-publishing/build-settings/create-build-profile.md) for the target platform.

2. Create a scene for the build profile.

3. Add a second camera to the scene (menu: Editor > Editor).

   > **Note:**
   >
   > Unity includes a main camera by default. For a two window application, you need two cameras.

4. Select the second camera.

5. In the Editor window, open the **Output** section, and set the **Target Display** to **Display 2**.

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:

1. Create a canvas (menu: **GameObject** > **UI (Canvas)** > **Canvas**).
2. Select the canvas.
3. 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.

1. In the **Project** window, create a C# script (context menu: **Create** > **MonoBehaviour Script**).

2. Replace the default script with the following:

   ```lang-cs
   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()}");
           };
       }
   }
   ```

3. Configure the following key parameters as required.

   * `displayInfo`: Specifies which physical display contains the window. Retrieve the display information using [`DisplayInfo.GetLayout`](/engine/6000.6/script-reference/unityengine/displayinfo/getlayout.md) (recommended) or [`Screen.GetDisplayLayout`](/engine/6000.6/script-reference/unityengine/screen/getdisplaylayout.md). In the example, `displayInfos[0]` uses the first physical display.
   * `cameraDisplayIndex:` Specifies which camera's content to display based on the camera's **Target Display** setting from Step 1. For example, use `0` for **Display 1**, and `1` for **Display 2**.

4. Attach the script to a GameObject in the scene.

**Notes**:

* Call [`GameWindowManager.Create`](ScriptRef:Windowing.GameWindowManager.Create) 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.
* To monitor the changes in the window state, use the `GameWindow` class methods such as [PositionChangedThisFrame](ScriptRef:Windowing.GameWindow.PositionChangedThisFrame) or [ResolutionChangedThisFrame](ScriptRef:Windowing.GameWindow.ResolutionChangedThisFrame).

## 3. Build and run the application on target hardware

1. [Build the Player](/engine/6000.6/manual/building-and-publishing/build-settings/build-profiles-reference.md#build-options) for the Embedded Linux or QNX build profile.
2. 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 [`GameWindow.SetResolution`](ScriptRef:Windowing.GameWindow.SetResolution) method isn't supported.
* [GetLogicalDpi](ScriptRef:Windowing.GameWindow.GetLogicalDpi) is currently not supported on Embedded Linux or QNX platforms. The method returns a default value of `0` on these platforms.

## Additional resources

* [`GameWindowCreationSettings API reference`](ScriptRef:Windowing.GameWindowCreationSettings)
* [`CreateWindowAsyncOperation API reference`](ScriptRef:Windowing.CreateWindowAsyncOperation)
* [Develop for Embedded Linux](/engine/6000.6/manual/platform-specific/embedded-systems/embedded-linux/develop.md)
* [Develop for QNX](/engine/6000.6/manual/platform-specific/embedded-systems/qnx/develop.md)
