Unreal Engine 2D: PlayerHUD question

so I’m following along with the lesson on creating the HUD. as I’ve done before I hop over to the source

file (cpp) and start defining the functions. void APlayerHUD::SetHP(int NewHP) { }

except VS is throwing up errors. I check the video and when the instructor defines the functions he uses

void UPlayerHUD::SetHP(...etc

he doesn’t mention why all of a sudden the function definition is now using U instead of A like every other class before it. Can someone explain why this class is different and when we would use U instead of A in the scope resolution operator?

Certain class types are based on U - typically these are based on UActorComponent so you create a HeathComponent class, it would be UHealthComponent. A is usually based on actor.
The actual definition of what they are is that the U classes are lighter than A classes - It’s an internal thing with the engine.

Widgets are one of these types that also use U instead of A.

There’s a (lack of) description here: Epic C++ Coding Standard for Unreal Engine | Unreal Engine 5.5 Documentation | Epic Developer Community

It’s a bit of a legacy where memory was more important than today so generally U-classes (UObject etc) were lighter and turn off a lot of things by default where as anything based on AActor will have replication on as default among other things.

For example, Most components have replication turned off as default and you have to enable it.

I hope this helps Robert and I hope you’re enjoying the course. Coming to Unreal and C++ is a tough way to start learning.

okay, so it is legacy code? a little annoying but I can deal. I take a lot of notes. Once again I appreciate the help!

It is but they still have valid reasons for doing it. The base class in each Prefix does behave differently and the classes with a U are lighter/have more switched off as default than the A Classes.

Unreal as an engine has been around since the original Unreal game. It had a whole editor built in and used Javascript but you could actually develop in it. It really wasn’t until the Unreal 2 before things like these became part of the engine - it wasn’t really that long ago either, well, 20 years ago. The naming stuck and has remained the same for as long as I’ve used UE4 and now 5.

It does make sense when you see what classes use these prefixes.

1 Like