I know that UCLASS() macro creates a seperate UClass for every UObject class ,but what is the need for this seperate class , how both of these classes relate to each other and what is the basic difference between both of them??


2 Answers 2


In Unreal Engine the base class used for every reference counted or garbage collected object is UObject. UObject is the base for classes like UActorComponent, AActor, APawn, AGameMode, etc. almost every single class in the entire engine.

UClass is also a UObject based class. UClass is a class that is used for meta/reflection.

Meta/reflection allows you to ask questions at runtime about the types in your project. What do I mean by types? I mean classes. A simple question might be. "What properties does this class have?" or "What methods does this class have?" A very helpful part of reflection is the ability to build very generic editors because all of the properties can be broken down into string entries, numeric fields, checkboxes, asset selectors, etc...

There are many classes used in Unreal's reflection system. UStruct, UField, UProperty, UEnum, UFunction, etc... Each one of these types maps to a different queryable attribute that a UObject based class can contain. As an aside you can also query meta/reflection on structs as well but only properties.

Meta/reflection is a common part of larger game engines but is not built into C++ natively. Some programming languages build that meta-data and reflection capabilities in, C# and Java both come to mind.

Because it isn't built into C++ natively game engines need to find a way of reflecting that data and making sure users know which data is reflected in an easy way. The unreal devs decided that marking your class with a syntax like UCLASS() and your methods with UFUNCTION() and properties with UPROPERTY() was a great way of explicitely defining which data/methods is going to be reflected.

Then during the compilation process they pre-process your header file and generate a new header file "yourfilename.generated.h" which includes all of the necessary reflection data that you marked up. They then run the rest of the compilation process and once your binaries/dlls are built they include reflection information, neat!

Here's a link to Unreal's article on reflection info. Unreal Property System (Reflection)


UCLASS(), UFUNCTION() and UPROPERTY() are macros that work with Unreal's reflection system to expose elements of the code to blueprints:

According to the doc:

Calling Functions across the C++ and Blueprint Boundary So far, we have shown how to expose properties to Blueprints, but there is one last introductory topic that we should cover before you dive deeper into the engine. Whilee creating gameplay systems, designers will need to be able to call functions created by a C++ programmer. The programmer will also need to be able to call functions implemented in Blueprints from C++ code. Let us start by first making the CalculateValues() function callable from Blueprints. Exposing a function to Blueprints is just as simple as exposing a property. It takes only one macro placed before the function declaration! The code snippet below shows what is needed for this.

UFUNCTION(BlueprintCallable, Category="Damage") 
void CalculateValues();

The UFUNCTION() macro handles exposing the C++ function to the reflection system. The BlueprintCallable option exposes it to the Blueprint virtual machine. Every Blueprint exposed function requires a category associated with it, so that the right click context menu works properly. The image below shows how the category affects the context menu:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .