r/learnprogramming • u/Pure_Function7183 • 10d ago
Should imgui be in the engine or editor?
I’d post to r/gameenginedevs but I feel like it’s too dumb lol. Anyways, I’ve been getting back into C++ graphics programming/game engine dev as a hobby and want to start dabbling with making an editor using ImGui.
I already use ImGui in the engine for some debug panels, but with the addition of an editor, the typical structure seems to be making the engine as a static library and the editor an executable that links the engine, and I’m not sure if ImGui should be the engine’s responsibility or moved to the editor?
I’m not very experienced with these multi project/build target setups, but from what I understand if I leave imgui on the engine anything that links it will have imgui which I’m not sure is practical?
Also, unrelated, but with this type of setup would it be make more sense for the engine to run the main loop instead of the editor? (inversion of control?).
2
u/mooglinux 10d ago
I don’t see a problem with just leaving it in the engine, unless you have some use case where you need to be able to run the engine headless.
1
u/StatsDota_Dmitrii 10d ago
not a real engine guy lol but on the main loop part: i think most engines own the loop and just give hooks like update and render, so editor and the game runtime both plug into same thing. otherwise you end up copypasting the loop in every exe and they slowly drift apart. is the editor going to run the game inside its viewport or as separate process?
1
u/EszterSantos72 10d ago
Put ImGui in the editor, not the engine, unless you need in-game debug panels in shipped builds. Keeping it out of the engine means your game projects link a cleaner engine library without dragging in editor-only dependencies or extra binary size.
1
u/CCodeSI 9d ago
Not a dumb question, this is the exact point where most hobby engines get tangled. A split that holds up well is three build targets instead of two:
imguias its own static library target (ImGui sources plus the backends you use). It should be compiled exactly once. If its sources end up in both the engine lib and the editor exe you get duplicate symbols, or worse, two separateGImGuicontexts where your engine's debug panels draw into one and the editor into the other.enginewith no ImGui dependency. Where it wants debug UI, give it a hook (virtual void OnDebugUI() {}on your layers/systems, or a callback) instead of calling ImGui directly.engine_debugui(optional, a CMake option) that linksengine+imguiand implements those hooks with your existing debug panels.Then the editor links
engine+engine_debugui+imgui, and the shipped game runtime links justengine(plusengine_debuguiin dev builds if you want the panels while playtesting). That answers your "should the game have ImGui" worry: only when you choose to.On the main loop: yes, have the engine own it. An
ApplicationwithRun()and a stack of layers (OnUpdate,OnRender,OnDebugUI) is the common pattern. The editor pushes anEditorLayer, the game pushes aGameLayer, and neither copies the loop. Look at how TheCherno's Hazel series structures its layer stack, it's a good worked example of exactly this setup.