Archive:
During the early stages of Lumo 2 development, I leaned heavily on Ben Ui’s ImGui for Unreal Engine 5 fork. I love Dear ImGui, and I’ve been using it off-and-on in projects for a few years. It’s simple to use, and having a nice debug UI to access cheat modes, and see internal state is a Godsend.
But it’s not perfect. Having to toggle the input mode is a pain in the ass, and, more annoyingly, I could only ever get it working reliably on Win64 builds, defeating the point somewhat.
I’ve started Next Thing, and I want to have a similar view on internal state. Cheat modes are easily handled through CheatManager
, and I’m using Data Driven CVars to toggle debug features on and off, so there’s no need for on-screen buttons.
I figure there must be a way to have debug text, on-screen, in fixed positions — not attached to actors as you normally see — as the engine’s Stat
commands do it. I’ve just never seen an explanation of how that works, or any documentation on it, so I thought I’d write it up in case I’m not alone.
AHud
has a DebugCanvas
, and you’re free to draw widgets onto this, as long as any attempts to do so happen within the A_Hud->DrawHUD()
call chain.
As for how to get text onto the canvas, I’m using FCanvasTextItem
:
/**
* Constructor.
*
* @param InPosition Draw position.
* @param InText String to draw.
* @param InFont Font to draw with.
* @param InColor Color to draw the text with.
* */
Followed by DebugCanvas->DrawItem(MyFCanvasTextItem);
My DrawHud
function now contains a series of calls to dump out internal state to canvas items and position them on-screen. This doesn’t look as fancy as ImGui, but it works everywhere, and having debug elements on console variable toggles is veh nice.
Buy My Stuff:
Source Code:
I'm slowly open sourcing as much of my code as possible. It's not generic — it was all written for a specific use-case, for specific games — but it could be useful, and it might spark a few ideas:
Friends:
If you like any of my work, please consider checking out some of the fantastic games made by the following super talented people: