imgui-godot

repository·master·Indexed 21 days ago

https://github.com/pkdawson/imgui-godot

A Dear ImGui plugin for Godot 4 that enables rapid UI development for debugging and tools using C#, C++, and GDScript. It provides integration for rendering ImGui windows and widgets within Godot, including support for SubViewports, custom font management via the Fonts class, and thread-safe layout updates using the imgui_layout signal. The plugin can be installed via godotenv, the Godot AssetLib, or built as a custom module from source.

Tokens
3.9K
Snippets
17
Records
27
Agent score
75%

What's inside imgui-godot

  1. ImGui Widgets and Viewports

    master

    The plugin provides several specialized methods and wrappers:

    • Image and ImageButton: Simple convenience wrappers for displaying images and buttons.
    • SubViewport: Displays an interactive viewport that receives input events. Requirement: You must set the SubViewport's Update Mode to Always for it to function correctly.

    All widget calls must occur within _Process or an imgui_layout callback.

  2. Build the ImGui Godot Module from source

    master

    To build the ImGui module as a custom module for Godot, you must first clone the Dear ImGui repository and check out a compatible docking branch, then clone the Godot engine source. Use scons to build Godot while pointing to your custom modules directory.

    Prerequisites:

    • scons installed
    • A compatible version of Dear ImGui (e.g., v1.91.6-docking)
    • Godot engine source code
    • The imgui-godot module placed in a directory accessible to the custom_modules flag.
    # 1. Setup Dear ImGui
    git clone https://github.com/ocornut/imgui
    git -C imgui checkout v1.91.6-docking
    
    # 2. Setup Godot
    git clone https://github.com/godotengine/godot
    cd godot
    
    # 3. Build Godot with the custom module
    scons custom_modules=../modules
    
    # 4. Run the project
    cd ../project
    godotenv addons install
    ../godot/bin/godot.* -e
  3. Use the imgui_layout signal for thread safety

    master

    If you are using Godot 4.1 or later with process thread groups, it is strongly recommended to connect to the imgui_layout signal and execute your ImGui code within the handling method rather than _process.

    ImGuiGD.Connect(OnImGuiLayout);
  4. Install the Dear ImGui plugin for Godot 4

    master

    You can install the plugin using one of the following methods:

    Manual Installation

    1. Download the full package (includes GDExtension binaries) or the csharp-only package from the GitHub Releases.
    2. Copy the addons folder into your Godot project directory.
    3. In the Godot editor, go to Project > Project Settings > Plugins and enable the plugin.

    Using GodotEnv (C# only)

    If you only require C# support without GDExtension, you can use GodotEnv with the following configuration:

    {
      "addons": {
        "imgui-godot": {
          "url": "https://github.com/pkdawson/imgui-godot",
          "checkout": "6.x",
          "subfolder": "addons/imgui-godot"
        }
      }
    }
  5. Set up Dear ImGui for C# projects

    master

    To use ImGui with C#, follow these additional steps after installing the plugin:

    1. Ensure your project has a C# solution (Project > Tools > C# > Create C# solution).
    2. In your IDE (e.g., Visual Studio), enable unsafe code in your project settings.
    3. Install the ImGui.NET NuGet package.
    4. Set your target framework to .NET 8 or later.
    5. Important: If using the GDExtension version, you must use an ImGui.NET version that matches the version the GDExtension was built with.
    6. In Godot, click Build to compile the solution.
    7. Enable the plugin in Project > Project Settings > Plugins.
  6. Build and setup the GDExt example project

    master

    To build the GDExt example and set up its environment, run the following commands in sequence:

    1. Build the project using scons.
    2. Navigate into the project directory.
    3. Use godotenv addons install to install the necessary addons for the project.
    scons
    cd project
    godotenv addons install