Introduction
When you need to use U macros in your c++ file you need to include the xxxx.generated.h header file and add GENERATED_BODY() inside the class/struct definition.
Why include xxx.generated.h ?
When you compile your c++ code, UHT (Unreal Header Tool) will generate some code from the U macros (UCLASS, UPROPERTY, UFUNCTION, …). This code is written inside the .generated.h header file. A second file (.gen.cpp) will include it.
Why GENERATED_BODY() ?
It seems that this macro is a marker for UHT, so it knows where to paste some code inside the class/struct.
To put it simply
When you press compile, the following happens:
- UHT creates
.generated.hand.generated.cppfiles when needed. Umacros are used as markers for UHT or replaced with pasted text.- Since the
.generated.hfile is included in your regular.hfile the C++ compiler will compile your regular files with the UHT generated files.
Issues
UHT is a dumb text parser which means it can’t resolve C++ pre-processors.