what does it even expand to?
try looking at what your IDE’s autocomplete suggests - from a cursory glance at the symbols available in a
UCLASS()
-declared class, you will notice there are a few that are non-standard ones, such asStaticClass()
orSuper
. this is what theGENERATED_BODY()
macro ends up expanding to after all the preprocessing is done.
the thing is - it doesn’t.
GENERATED_BODY()
by itself is incredibly stupid:#define BODY_MACRO_COMBINE_INNER(A,B,C,D) A##B##C##D #define BODY_MACRO_COMBINE(A,B,C,D) BODY_MACRO_COMBINE_INNER(A,B,C,D) #define GENERATED_BODY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_,__LINE__,_GENERATED_BODY);
let’s disassemble it piece by piece.
so
GENERATED_BODY
combines the identifiersCURRENT_FILE_ID
,_
,__LINE__
, and_GENERATED_BODY
.CURRENT_FILE_ID
is a preprocessor macro defined by the UnrealBuildTool for each file. for simplicity’s sake, let’s assume it’s the filename with dots replaced by underscores. for instance,GameplayAbility_h
.the actual form it seems to take is
FID_{Path}
with{Path}
being the file path relative to the project root directory, with slashes and dots replaced with underscores. for:Engine/Source/Runtime/Engine/Classes/Engine/Blueprint.h
the file ID is:
FID_Engine_Source_Runtime_Engine_Classes_Engine_Blueprint_h
I haven’t inspected the UnrealBuildTool/UnrealHeaderTool sources though, so there may be more to it.
therefore for a simple file, let’s call it
MyClass.h
:#pragma once #include "UObject/Object.h" #include "MyClass.generated.h" UCLASS() class UMyClass : public UObject { GENERATED_BODY() };
after expanding the
GENERATED_BODY()
, we’ll get this:// -- snip -- UCLASS() class UMyClass : public UObject { MyClass_h_10_GENERATED_BODY };