-
Hello, Great work on this bindings, it works very well. I use imgui to make in-game tools in my game. I was wondering if it is possible to completely remove it from a specific export preset (for example using feature tags) in order to not deliver content that is not used by the player ? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
First, the easy part: in the export dialog, go to Resources and add The tricky part is disabling your code that uses ImGui. For C#, you could add something like this to your .csproj: <PropertyGroup>
<DefineConstants Condition="'$(Configuration)'=='Debug' And
$(DefineConstants.Contains('GODOT_PC'))">$(DefineConstants);IMGUI</DefineConstants>
</PropertyGroup> And then conditionally enable your code that uses ImGui, like: #if IMGUI
ImGui.Begin("my window");
// ...
ImGui.End();
#endif For C++, same thing. Use the preprocessor. For GDScript, I don't have any great answers. You might be able to put all your tool scripts in one directory, and add that directory to the export exclusion filter. Let me know if you have any specific difficulty. The issue has come up a few times, so I'd like to document it better and maybe add an example project to show "best practices" for exporting. |
Beta Was this translation helpful? Give feedback.
-
Here is a recap to document the way I've done for my project following the advices of @pkdawson. I'm using C# version of Godot so I edited the csproj to add a new define when I want imgui to be activated: <PropertyGroup>
<DefineConstants Condition="$(DefineConstants.Contains('DEBUG')) And $(DefineConstants.Contains('GODOT_PC'))">$(DefineConstants);IMGUI</DefineConstants>
</PropertyGroup> then, I used this define to conditionally add a reference on ImGui.NET or to remove the addon code from the project: <ItemGroup Condition="$(DefineConstants.Contains('IMGUI'))">
<PackageReference Include="ImGui.NET" Version="1.90.8.1" />
</ItemGroup>
<ItemGroup Condition="!$(DefineConstants.Contains('IMGUI'))">
<Compile Remove="addons\imgui-godot\**" />
</ItemGroup> I changed the ImGuiRoot option depending on the release tag to un-reference the associated scene:
I excluded the imgui-godot addon from the resources defined in the export preset. To be able to make a "debug" build, I duplicated the export preset without this exclusion. Finally, I used the IMGUI define to include ImGUI uses: #if IMGUI
ImGui.Begin("my window");
// ...
ImGui.End();
#endif Thanks again for the help |
Beta Was this translation helpful? Give feedback.
-
Hi again, So, I spoke to fast, I did not tested enough what I've done ^^. My previous integration was only working for exported build. ImGui was not working when testing in editor. I tried different approaches, it is quite difficult to add new define constants in a godot project (so it works well in editor too). So I used Godot feature tags that seems to exist to do this kind of stuff. Sadly for now feature tags cannot be set in editor (but it will starting from Godot 4.3, see issue #373). Here is what I've done:
<Choose>
<When Condition="$(DefineConstants.Contains('GODOT_FEATURE_NO_IMGUI'))">
<ItemGroup>
<Compile Remove="addons\imgui-godot\**" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.90.8.1" />
</ItemGroup>
</Otherwise>
</Choose>
To be able to make a "debug" build that use imgui, I duplicated the export preset without this exclusion and flag.
#if !GODOT_FEATURE_NO_IMGUI This integration works well in export and in editor. I think I'll change to positive logic when 4.3 will be out, but this is fine that way and it's also allow to override some project settings depending on this new flag. |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing your work. I borrowed some of your ideas for the sample csproj, which works well in my testing with imgui-godot v6.0.0. No feature flags or exclusion filters necessary, you can just use the new settings in each export preset. And to fix the using directives for release export, you can just do: #if !IMGUI
namespace ImGuiNET { }
namespace ImGuiGodot { }
#endif |
Beta Was this translation helpful? Give feedback.
Hi again,
So, I spoke to fast, I did not tested enough what I've done ^^. My previous integration was only working for exported build. ImGui was not working when testing in editor.
I tried different approaches, it is quite difficult to add new define constants in a godot project (so it works well in editor too). So I used Godot feature tags that seems to exist to do this kind of stuff. Sadly for now feature tags cannot be set in editor (but it will starting from Godot 4.3, see issue #373).
So for now, I implemented it using negative logic, imgui is active by default, then I use a feature tag to deactivate it.
Here is what I've done: