Ingame debug / imgui menus - how to organise debug code?

Hi,

In my current project (Rocket Rabbit, started for the gamejam but didnt submit it because it was just not finished in any way..) I started for the first time to use Dear Imgui extension to add debug menus to the game, like changing levels, looking at some tables with function to adjust game data (like speed, force of jump etc..) while playing the game:

Coding these is fine. But what I struggle is WHERE to put this debug code such that it wont be all over the place and such that in a release build it just doesnt exist.
I will have a lot of in-game debug or even in-game live editor code, but I want it to be added on top of the real code base, so that I can just plug it off on release build.

How do you guys do that?
Do you use things like GitHub - defold/extension-lua-preprocessor: Small and simple Lua preprocessor for Defold · GitHub and just put all these inside #if DEBUG directives? Do you have a central debug module and things just register to it and Voilà! ?
I don’t even want the Imgui dependency to be bundle in the release version.

Some guidelines?

In my rendering pipeline project, I have a global settings module and numerous manager modules, and my debug gui changes settings and calls functions in those. The gui is also hidden behind a single script component that I can add or remove from the main collection.

For reference, my gui stuff is in here (most of the work is done in the modules in /panels): defrend/defrend/gui at main · akhleung/defrend · GitHub

More generally, I would suggest adding hooks in your modules, or messaging endpoints in your script components, that can be called by your debug gui. The gui should only be a thin layer that uses those hooks / endpoints.

2 Likes

Wouaw thanks this is really clean code! You’ve made render script modular and understandable, bravo!
And I discovered your project with billboards, decals etc. this is awesome!

Just a last question:
here your /defrend/gui/graphics_settings.go object is put into the main.collection example, so all the settings panels and imgui code will be bundled into the game.
Do you just delete this object when you bundle the release version?
Or is there a way to programmatically ignore this?

Thanks, I’m glad you find the project well-structured.

As for disabling the gui, you can do the following:

  • remove it from the project when you make a release build, as you suggested
  • send a disable message to its script component (in this case, the gui’s update function will still be called, but it will return immediately upon checking the enabled flag
  • delete the game object programmatically using go.delete (you could also spawn it using a factory component) – I haven’t tried this, but it seems like it should work