[Template/Tutorial] HUD System: Based on Unity 3D's 'OnGUI'

Hey Guys!

I know there are loads of good HUD tutorials on the wiki/forums, but I decided to take a swing at a more objectified approach.

So far it contains the ability to use object based:

  • Labels
  • Textures
  • Materials
  • Animated Materials
  • Buttons
  • Animated Buttons
  • Horizontal Sliders
  • Vertical Sliders

I’m working on GUI Windows and GUI Layouts, so as to further match the OnGUI system.

I should be putting up a video soon!

What I’m really happy with, is everything is fully blue-printable.
At least for the defaults anyways.

Everything, such as button states, animation states, etc, are all controlled in editor/material editor,
meaning very little scripting is needed to meet your requirements.

The next version will be able to do everything, without having to touch script at all.
Blueprinted versions of the objects and their functions, so your entire HUD can be done in the Graph editor.
(Without MASSES of nodes for simple UV animations).

Without further ado! Here you go!**
Unity Style HUD system!

****A lovely wee example!

if(GUI.Button(new Rect(200,400,200,50),"Text"))
    //Click stuff here


if(Button(TestButton, this, 0, "Text", 0, FLinearColor::White, MousePos, 300, 600, 300, 120, 0.75f))
    //Stuff goes here for when button is clicked

I don’ think this is too bad for a 3 day power session! xD
(1351 Lines… Cry…)

If anyone has any queries or anything, feel free to PM me, or respond here in this thread!
Also feel free to contribute and work on any UObject Memory Management issues that may crop up!
Only been using Unreal’s C++ for a few weeks, so there may be a few… (A LOT) of problems!


Now make the full automatic GuiLayout too!

Awesome, nice work!

This is so cool! Thanks for sharing this to public.

Very Nice! I am currently working on something similar and wanted to release it as a tutorial when its finished…but you were much faster than me :slight_smile:


This is amazing for only being a few weeks into UE4 C++!

I can’t wait to see what more you come up with Loken!



Looks nice, will definitely check it out later!

This sounds great! I’d love to use this if it can be used within blueprints.

It can! …soon.

if(GUI.Button(new Rect(200,400,200,50),"Text"))

In C++, this is a memory leak. In C++, every “new” MUST be balanced with a “delete,” because it is a memory allocation.
In C#, “new” just initializes objects, and if they are value objects, they live on the stack and it’s no big deal. This is VERY DIFFERENT.

If you want to take a rect-pointer in C++, the code should look like this:

Rect r(0, 1, 2, 3);
if (GUI.Button(&r, ...)) {

Although, because it’s never the right thing to NOT take a rect here, you’d be better off using a reference here:

class GuiStuff {
bool Button(Rect const &r, ...) { ... }
GuiStuff GUI;

if (Gui.Button(Rect(0, 1, 2, 3), ...)) { ...

Hey jwatte!

I made sure it only instantiates the object once, and it’s held as a non-GC’d ‘UPROPERTY()’.
The first call allocates the memory space and instantiates, and then the next call only updates it.

If I’m not mistaken (although I can’t be sure), won’t Unreal’s GC will still wipe all dynamically allocated memory when the game is stopped?

However, if I’m wrong, it shouldn’t be too hard to fix right? =]

Although I objectified it because I didn’t want to have to create and delete an object every frame,
meaning it could internally hold animation frame positions, etc.

If it’s a serious issue, then I don’t mind updating it to avoid the problem =]


I’ve just noticed… xD

You’re talking about the Unity Example I gave. xD
My example is underneath, which doesn’t use ‘New’ or ‘Rect’

I was giving a comparison of the two, showing the similarity and differences.
I avoid the issue entirely :3