UE 宏定义GENERATED_BODY

      在学习UE4的时候,看到C++工程中,在实现父类的BeginPlay()和Tick()以及SetupPlayerInputComponent()这些虚函数时,都能看到里面有用到Super类型,如下:

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AMyActor::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

}

      把鼠标放到Super上可以看到其定义是:typedef APawn AMyActor::Super。在子类中使用Super,是对父类APawn的成员函数、成员变量的调用。

      但是当我想按F12跳转到定义的时候,却发现总会跳转到AMyActor的头文件里的一个宏定义GENERATED_BODY()。找了半天,最后在Engine\Source\Runtime\CoreUObject\Public\UObject目录下的ObjectMarcro.h文件中找到了GENERATED_BODY()的定义,在620多行左右:

// This pair of macros is used to help implement GENERATED_BODY() and GENERATED_USTRUCT_BODY()
#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)

// Include a redundant semicolon at the end of the generated code block, so that intellisense parsers can start parsing
// a new declaration if the line number/generated code is out of date.
#define GENERATED_BODY_LEGACY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_,__LINE__,_GENERATED_BODY_LEGACY);
#define GENERATED_BODY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_,__LINE__,_GENERATED_BODY);

#define GENERATED_USTRUCT_BODY(...) GENERATED_BODY()
#define GENERATED_UCLASS_BODY(...) GENERATED_BODY_LEGACY()
#define GENERATED_UINTERFACE_BODY(...) GENERATED_BODY_LEGACY()
#define GENERATED_IINTERFACE_BODY(...) GENERATED_BODY_LEGACY()

      更深入的理解找到了这篇博客:深入理解UE4宏定义—— GENERATED_BODY_cartzhang的博客-CSDN博客_ue4宏,暂时看到还不是很明白,这里记录一下,以后慢慢理解。

你可能感兴趣的:(虚幻,UE4,GENERATED_BODY)