# How to Integrate ImGui with Unity or Unreal Engine: Complete Backend Guide

> Learn how to integrate ImGui with Unity or Unreal Engine using the standard platform and renderer backends provided in the ocornut/imgui repository. Get your UI setup quickly.

- Repository: [omar/imgui](https://github.com/ocornut/imgui)
- Tags: how-to-guide
- Published: 2026-07-13

---

**Integrating Dear ImGui with Unity or Unreal Engine requires implementing a platform backend for input handling and a renderer backend for draw-call submission, both of which are provided as standard implementations in the `backends/` folder of the ocornut/imgui repository.**

Dear ImGui is a pure C++ immediate-mode UI library that ships with no platform or graphics dependencies. To use it inside Unity or Unreal Engine, you must bridge the engine's existing windowing and graphics abstractions to ImGui's **backend architecture**. This approach leverages the standard backends located in `backends/`—such as [`imgui_impl_win32.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_win32.cpp) or [`imgui_impl_opengl3.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_opengl3.cpp)—to handle the heavy lifting of input polling and rendering.

## Understanding the Backend Architecture

Dear ImGui separates concerns into three distinct layers. Understanding this separation is critical for a successful integration.

1. **Core Library** ([`imgui.cpp`](https://github.com/ocornut/imgui/blob/main/imgui.cpp) / [`imgui.h`](https://github.com/ocornut/imgui/blob/main/imgui.h)) – Contains all UI widgets, layout logic, and the immediate-mode API. No platform or graphics code resides here.

2. **Platform Backend** – Supplies mouse, keyboard, gamepad, cursor shape, timing, and window size to the `ImGuiIO` structure. Standard implementations include [`imgui_impl_win32.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_win32.cpp) for Windows applications and [`imgui_impl_glfw.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_glfw.cpp) for cross-platform GLFW windows.

3. **Renderer Backend** – Creates the font texture, uploads vertex/index buffers, and issues draw calls for each `ImDrawCmd`. Common implementations include [`imgui_impl_dx11.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_dx11.cpp) for DirectX 11 and [`imgui_impl_opengl3.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_opengl3.cpp) for OpenGL 3/4.

The integration workflow follows a strict per-frame sequence: initialize the backends once, then each frame call `ImGui_Impl<Platform>_NewFrame()`, `ImGui_Impl<Renderer>_NewFrame()`, `ImGui::NewFrame()`, build your UI, call `ImGui::Render()`, and finally submit the draw data via `ImGui_Impl<Renderer>_RenderDrawData(ImGui::GetDrawData())`.

## Integration Paths by Engine

### Unity (C# + Native Plugin)

Unity requires a two-layer approach because the engine runtime is C#. You must compile ImGui and its backends into a native plugin (DLL on Windows, framework on macOS/iOS) and expose a C API using **cimgui** (the official C binding generator at https://github.com/cimgui/cimgui).

The managed C# side forwards input events and drives the frame loop via P/Invoke, while the native side hosts the platform and renderer backends. In the example below, the native plugin uses [`imgui_impl_glfw.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_glfw.cpp) for platform input and [`imgui_impl_opengl3.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_opengl3.cpp) for rendering, assuming Unity exposes a GLFW window handle.

```csharp
// UnitySide.cs – C# wrapper (simplified)

using System;
using System.Runtime.InteropServices;

public static class ImGuiUnity
{
    [DllImport("ImGuiPlugin")]
    public static extern IntPtr ImGui_CreateContext(IntPtr sharedFontAtlas);
    
    [DllImport("ImGuiPlugin")]
    public static extern void ImGui_NewFrame();
    
    [DllImport("ImGuiPlugin")]
    public static extern void ImGui_Render();

    public static void UpdateInput()
    {
        var mousePos = UnityEngine.Input.mousePosition;
        ImGui_ImGuiIO_AddMousePosEvent((int)mousePos.x, (int)mousePos.y);
        // Forward buttons, keyboard, scroll, etc.
    }
}

```

```cpp
// ImGuiPlugin.cpp – native plugin (Windows DLL)
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <GLFW/glfw3.h>

extern "C" __declspec(dllexport) void ImGui_Init(void* glfw_window)
{
    ImGui::CreateContext();
    ImGui_ImplGlfw_InitForOpenGL((GLFWwindow*)glfw_window, true);
    ImGui_ImplOpenGL3_Init("#version 130");
}

extern "C" __declspec(dllexport) void ImGui_NewFrame()
{
    ImGui_ImplGlfw_NewFrame();
    ImGui_ImplOpenGL3_NewFrame();
    ImGui::NewFrame();
}

extern "C" __declspec(dllexport) void ImGui_RenderDrawData()
{
    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

```

### Unreal Engine (C++ Module)

Unreal Engine integration is more direct because the project uses C++. You can add ImGui source files directly to your module's `Public` and `Private` folders and initialize the backends using engine-provided handles.

For a DirectX 11 RHI (the default on Windows), use [`imgui_impl_win32.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_win32.cpp) for the platform layer and [`imgui_impl_dx11.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_dx11.cpp) for rendering. Obtain the native window handle via `FSlateApplication::Get().GetNativeWindow()->GetOSWindowHandle()` and the DirectX device from `GDynamicRHI`.

```cpp
// MyImGuiModule.cpp – Unreal Engine module
#include "MyImGuiModule.h"
#include "imgui.h"
#include "backends/imgui_impl_win32.h"
#include "backends/imgui_impl_dx11.h"
#include "Windows/WindowsApplication.h"
#include "DX11/DX11Device.h"

void FMyImGuiModule::StartupModule()
{
    ImGui::CreateContext();
    
    HWND hwnd = (HWND)FSlateApplication::Get().GetNativeWindow()->GetOSWindowHandle();
    ImGui_ImplWin32_Init(hwnd);
    
    ID3D11Device* dxDevice = GDynamicRHI->RHIGetDevice()->GetDevice();
    ID3D11DeviceContext* dxContext = GDynamicRHI->RHIGetDevice()->GetImmediateContext();
    ImGui_ImplDX11_Init(dxDevice, dxContext);
}

void FMyImGuiModule::ShutdownModule()
{
    ImGui_ImplDX11_Shutdown();
    ImGui_ImplWin32_Shutdown();
    ImGui::DestroyContext();
}

void FMyImGuiModule::Tick(float DeltaTime)
{
    ImGuiIO& io = ImGui::GetIO();
    io.DeltaTime = DeltaTime;
    io.DisplaySize = ImVec2(GEngine->GameViewport->Viewport->GetSizeXY().X,
                             GEngine->GameViewport->Viewport->GetSizeXY().Y);

    ImGui_ImplWin32_NewFrame();
    ImGui_ImplDX11_NewFrame();
    ImGui::NewFrame();

    // Build UI here: ImGui::Begin("Demo"); ImGui::Text("Hello"); ImGui::End();

    ImGui::Render();
    ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
}

```

## Key Backend Files in the Repository

The ocornut/imgui repository provides everything required for engine integration. These standard backends eliminate the need to write platform-specific input or rendering code from scratch.

- **[`backends/imgui_impl_win32.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_win32.cpp)** / **[`imgui_impl_win32.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_win32.h)** – Handles Win32 window messages, cursor shapes, timing, and keyboard/mouse input for Windows-based applications.

- **[`backends/imgui_impl_glfw.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_glfw.cpp)** / **[`imgui_impl_glfw.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_glfw.h)** – Cross-platform GLFW backend suitable for Unity native plugins that expose a GLFW window or custom OpenGL applications.

- **[`backends/imgui_impl_dx11.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_dx11.cpp)** / **[`imgui_impl_dx11.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_dx11.h)** – DirectX 11 renderer backend that creates font textures and submits draw calls using `ID3D11Device` and `ID3D11DeviceContext`.

- **[`backends/imgui_impl_opengl3.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_opengl3.cpp)** / **[`imgui_impl_opengl3.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_opengl3.h)** – OpenGL 3/4 renderer backend using modern GL3W loader support. Creates the font atlas and manages vertex buffer objects (VBOs).

- **[`backends/imgui_impl_vulkan.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_vulkan.cpp)** / **[`imgui_impl_vulkan.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_vulkan.h)** – Vulkan renderer backend for engines running on Vulkan RHI (relevant for UE Vulkan builds).

- **[`imgui.cpp`](https://github.com/ocornut/imgui/blob/main/imgui.cpp)** / **[`imgui.h`](https://github.com/ocornut/imgui/blob/main/imgui.h)** – The core Dear ImGui library containing `ImGui::CreateContext()`, `ImGui::NewFrame()`, and all widget functions.

## Summary

- **Dear ImGui** requires two standard backends: one for platform input (window events) and one for rendering (draw-call submission).
- **Unity** integration compiles ImGui into a native plugin using **cimgui** to generate a C API, while the C# side forwards input via P/Invoke.

- **Unreal Engine** integrates directly via C++ modules, initializing `ImGui_ImplWin32_Init()` with the native window handle and `ImGui_ImplDX11_Init()` with the engine's DirectX device.
- The per-frame lifecycle is consistent across engines: Platform NewFrame → Renderer NewFrame → ImGui NewFrame → UI Construction → Render → RenderDrawData.
- Using the standard backends in `backends/` provides automatic support for multi-viewport windows, clipboard integration, and gamepad input without additional code.

## Frequently Asked Questions

### Can I use Vulkan instead of DirectX 11 in Unreal Engine?

Yes. If your Unreal Engine project uses the Vulkan RHI, replace [`imgui_impl_dx11.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_dx11.cpp) with **[`imgui_impl_vulkan.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_impl_vulkan.cpp)**. Initialize the Vulkan backend using your existing `VkDevice`, `VkPhysicalDevice`, `VkQueue`, and `VkPipelineCache` handles obtained from the engine's RHI interface. The per-frame workflow remains identical.

### Does Unity's IL2CPP build affect ImGui integration?

No. The integration occurs at the native plugin level, which exists outside of C# bytecode compilation. Your native DLL (containing [`imgui.cpp`](https://github.com/ocornut/imgui/blob/main/imgui.cpp) and the backends) is pre-compiled machine code loaded by Unity at runtime, making it compatible with both Mono and IL2CPP scripting backends.

### How do I handle multiple viewports or docking in engine integrations?

The standard backends in `backends/` automatically support the **multi-viewport** feature when you enable `io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable` in your `ImGuiIO` configuration. The platform backend handles the creation of auxiliary OS windows, and the renderer backend issues draw calls for each viewport. This works in both Unity and Unreal without engine-specific modifications.

### Where should I place the ImGui source files in an Unreal Engine project?

Add the ImGui source files to your module's `Source/[ModuleName]/Private/` directory (for implementation files) and `Source/[ModuleName]/Public/` (for headers). Update your [`Build.cs`](https://github.com/ocornut/imgui/blob/main/Build.cs) file to include the appropriate module dependencies (e.g., `Slate`, `SlateCore`, `RHI`, `D3D11RHI` for DirectX 11 support). Do not place them in the engine's source tree to avoid merge conflicts during engine updates.