Macro generated_ UCLASS_ Body () and generated_ Analysis of body ()


Classes that inherit from the UE4 engine generate some macro code. The purpose of this macro code is to help generate constructors and associated member functions

UCLASS()
class SECTION1_API ASUsableActor : public AActor
{
	GENERATED_BODY()
	
public:	
		
	
};
UCLASS()
class SURVIVALGAME_API ASUsableActor : public AActor
{
	GENERATED_UCLASS_BODY()

public:

	
};

F12 jumps to the declaration file for both macros

#define GENERATED_BODY() \
PRAGMA_DISABLE_DEPRECATION_WARNINGS \
public: \
	ASUsableActor_RPC_WRAPPERS_NO_PURE_DECLS \
	ASUsableActor_CALLBACK_WRAPPERS \
	ASUsableActor_INCLASS_NO_PURE_DECLS \
	ASUsableActor_ENHANCED_CONSTRUCTORS \
private: \
PRAGMA_POP

GENERATED_BODY() will be replaced by a series of macros that replace the bottommost member with private: that is, after GENERATED_BODY() without significantly changing the member’s access mode, it will be private

#define GENERATED_UCLASS_BODY() \
PRAGMA_DISABLE_DEPRECATION_WARNINGS \
public: \
	ASUsableActor_RPC_WRAPPERS \
	ASUsableActor_CALLBACK_WRAPPERS \
	ASUsableActor_INCLASS \
	ASUsableActor_STANDARD_CONSTRUCTORS \
public: \
PRAGMA_POP

and the member variable after GENERATED_UCLASS_BODY() is public.

#define ASUsableActor_RPC_WRAPPERS
#define ASUsableActor_CALLBACK_WRAPPERS

these two are empty macros, in C/C++ hollow macros will be replaced by Spaces mostly used to indicate comments

The two non-null macros in GENERATED_UCLASS_BODY() are declared as

#define ASUsableActor_INCLASS \
	private: \
	static void StaticRegisterNativesASUsableActor(); \
	friend SECTION1_API class UClass* Z_Construct_UClass_ASUsableActor(); \
	public: \
	DECLARE_CLASS(ASUsableActor, AActor, COMPILED_IN_FLAGS(0), 0, Section1, NO_API) \
	DECLARE_SERIALIZER(ASUsableActor) \
	/** Indicates whether the class is compiled into the engine */    enum {IsIntrinsic=COMPILED_IN_INTRINSIC}; \
	UObject* _getUObject() const { return const_cast<ASUsableActor*>(this); }

The main purpose of these lines is to declare some member methods for the class

#define ASUsableActor_STANDARD_CONSTRUCTORS \
	/** Standard constructor, called after all reflected properties have been initialized */ \
	NO_API ASUsableActor(const FObjectInitializer& ObjectInitializer); \
	DEFINE_DEFAULT_OBJECT_INITIALIZER_CONSTRUCTOR_CALL(ASUsableActor) \
private: \
	/** Private copy-constructor, should never be used */ \
	NO_API ASUsableActor(const ASUsableActor& InCopy); \
public:

Here you can see that a public constructor and a private copy constructor are declared, with the public constructor taking a reference constant for FObjectInitializer. The copy constructor is declared private, indicating that the copy constructor is not available

The following two are non-null macro declarations referenced in GENERATED_BODY()

#define ASUsableActor_RPC_WRAPPERS_NO_PURE_DECLS \
	static inline void StaticChecks_Implementation_Validate() \
	{ \
	}

#define ASUsableActor_INCLASS_NO_PURE_DECLS \
	private: \
	static void StaticRegisterNativesASUsableActor(); \
	friend SECTION1_API class UClass* Z_Construct_UClass_ASUsableActor(); \
	public: \
	DECLARE_CLASS(ASUsableActor, AActor, COMPILED_IN_FLAGS(0), 0, Section1, NO_API) \
	DECLARE_SERIALIZER(ASUsableActor) \
	/** Indicates whether the class is compiled into the engine */    enum {IsIntrinsic=COMPILED_IN_INTRINSIC}; \
	UObject* _getUObject() const { return const_cast<ASUsableActor*>(this); }
#define ASUsableActor_ENHANCED_CONSTRUCTORS \
private: \
	/** Private copy-constructor, should never be used */ \
	NO_API ASUsableActor(const ASUsableActor& InCopy); \
public: \
	DEFINE_DEFAULT_CONSTRUCTOR_CALL(ASUsableActor)

DEFINE_DEFAULT_CONSTRUCTOR_CALL didn’t track where and how to declare it in VS, so the literal definition is to define the default constructor, which is the basic constructor.
Also the copy constructor is not available

From the above analysis, you can think of GENERATED_BODY() as generating the default constructor for us, and GENERATED_UCLASS_BODY() as generating the constructor with the specified parameter type for us

Read More: