r/learnprogramming • • 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 Upvotes

9 comments sorted by

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/Pure_Function7183 10d ago edited 10d ago

Well, right now the only thing using the engine is the editor, but from what I’ve learned, you typically have another executable (and probably more) that links the engine, which is the game runtime(?) that I guess would be shipped and played by someone so I’m not sure if the game needs ImGui.

1

u/Pure_Function7183 8d ago

Running the engine headless would mean without the editor? Why would you need to do that or what can you do by doing that?

1

u/mooglinux 8d ago

Multiplayer servers can be run that way, most common example off the top of my head would be Godot.

Speaking of, Godot is also a good example for separating the engine and editor: you don’t. The editor is just a Godot “game”; in fact many editors for games are like that.

1

u/CrossScarMC 10d ago

I mean you could always just make it an optional component of the engine if you need 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/Pure_Function7183 8d ago

Probably gonna have the editor run the game inside its viewport, although I’m considering it as a separate process because I recently discovered how to do that and want to learn new stuff. I’m guessing it makes a difference in how I do things?

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:

  • imgui as 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 separate GImGui contexts where your engine's debug panels draw into one and the editor into the other.
  • engine with 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 links engine + imgui and implements those hooks with your existing debug panels.

Then the editor links engine + engine_debugui + imgui, and the shipped game runtime links just engine (plus engine_debugui in 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 Application with Run() and a stack of layers (OnUpdate, OnRender, OnDebugUI) is the common pattern. The editor pushes an EditorLayer, the game pushes a GameLayer, 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.