Integrate Unity into Windows applications
Integrate the Unity Runtime Library into Windows.
Read time 2 minutesLast updated 8 days ago
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 - This is the easier option.
- Embed Unity within your existing operating system process
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 command line argument.
-parentHWND 'HWND' delayedWhen you pass , the Unity application hides while the command runs. To successfully embed the window, you must:
-parentHWND 'HWND' delayedFor 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 function:
GetWindowLongPtr- 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:
-
Loaddirectly into your Win32 application.
UnityPlayer.dll -
Call theentry point with the following signature:
UnityMainextern "C" int UnityMain2(HINSTANCE hInst, LPCWSTR customDataFolder, LPWSTR szCmdLine, int nCmdShow); -
Pass command line arguments to Unity via theparameter. You can use this to control settings such as resolution, job threads, or the parent HWND.
lpCmdLine
For a full list of valid arguments you can pass to , refer to the Unity Standalone Player command line arguments documentation.
lpCmdLine