Version: Unity 6.6 (6000.6)
Language : English
Windows requirements and compatibility
Windows Player settings

Integrate Unity into Windows applications

You can use the Unity as a Library feature to integrate the Unity Runtime Library in Windows applications.

This feature enables you to include Unity-powered features in your application, such as:

  • 3D/2D Real-Time Rendering
  • AR Experience
  • 3D model interaction
  • 2D mini-games

The Unity Runtime Library exposes controls to manage when and how to load, activate, and unload content within the application.

On Windows, you can embed a Unity build into your application in the following ways:

Launch Unity as an external build

You can launch Unity as an external build from your application and specify a window in which Unity will initialize and render with the -parentHWND command line argument.

You can either pass the command the handle of your preferred window (for example, -parentHWND 12740), or pass a delay (-parentHWND delayed).

Pass the window handle directly

Pass the actual window handle (for example, -parentHWND 12740) to make Unity automatically create a child window and parent it to the specified handle on startup.

Pass a delay

Pass the delayed keyword (-parentHWND delayed) to start the Unity application hidden in the background. This gives your parent application time to finish loading or perform other tasks before you manually parent the window.

To embed the window when you use a delay:

  1. Wait for your parent application to be ready.
  2. Call SetParent from the Microsoft Developer library in your application to manually embed the window.

The Unity window respects the position and size defined in the STARTUPINFO structure that your parent application provides when launching the process.

For an example of a Unity application embedded in a window, refer to the EmbeddedWindow downloadable example.

Resize the window

To resize the Unity window, check its GWLP_USERDATA in Microsoft’s GetWindowLongPtr function:

  • Its lowest bit is set to 1 when the graphics initialize and it’s safe to resize.
  • Its second lowest bit is set to 1 after the Unity splash screen finishes displaying.

Embed Unity within your existing operating system process

To embed Unity within your existing operating system process:

  1. Load UnityPlayer.dll directly into your Win32 application.

  2. Call the UnityMain entry point with the following signature:

    extern "C" int UnityMain2(HINSTANCE hInst, LPCWSTR customDataFolder, LPWSTR szCmdLine, int nCmdShow);
    
  3. Pass command line arguments to Unity via the lpCmdLine parameter. You can use this to control settings such as resolution, job threads, or the parent HWND.

For a full list of valid arguments you can pass to lpCmdLine, refer to the Unity Standalone Player command line arguments documentation.

Additional resources

Windows requirements and compatibility
Windows Player settings