I think you only need to include two things in the header file:
- The
generated.h
file (only if you have defined UCLASSes, USTRUCTs, or UENUMs). - The header of any parent class of classes defined in the file
If it’s not one of the cases above, and you have a property in your header whose type hasn’t been included yet, you can do what’s called forward declaration. Like this:
class UMaterialInterface* Material;
or
void SetMyMaterial(class UMaterialInterface* NewMaterial)
;
you could also do one forward declaration for the whole file by putting it outside any class declarations, like:
class UMaterialInterface;
Forward declaration is telling the compiler that it should treat UMaterialInterface
as a class, even though it hasn’t been included yet.
Keep as many of your #include
s as possible in the cpp file instead of the header. It improved compile times.