Unreal Engine 4.x Scripting with C++ Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

UE4 generates and manages a significant amount of code for your custom UCLASS. This code is generated as a result of the use of the UE4 macros such as UPROPERTY, UFUNCTION, and the UCLASS macro itself. The generated code is put into UserProfile.generated.h. You must #include the UCLASSNAME.generated.h file with the UCLASSNAME.h file for compilation to succeed, which is why, by default, the editor includes this automatically. Without including the UCLASSNAME.generated.h file, compilation would fail.

It is also important to note that the UCLASSNAME.generated.h file must be included as the last #include in the list of #include in UCLASSNAME.h.

Here's a correct example:

#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"

#include <list> // Newly added include

// CORRECT: generated file is the last file included
#include "UserProfile.generated.h"

And here is an incorrect one:

#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "UserProfile.generated.h"

// WRONG: NO INCLUDES AFTER .generated.h FILE
#include <list> // Newly added include

If the UCLASSNAME.generated.h file is not the last item within the list of #include statements shown in the previous code sample, you will get the following error:

>> #include found after .generated.h file - the .generated.h file 
should always be the last #include in a header