宏GENERATED_UCLASS_BODY()与GENERATED_BODY()的区别

在4.6版本中release note有以下说明:

You now define and use “normal” C++ constructors for your classes. You can use parameterless -constructors too now!
You no longer need to supply a category for your properties to expose them to the editor or Blueprints. You’ll get a default category now.
FPostContructInitializeProperties is deprecated. It’s replaced by FObjectInitializer, and you only have to specify it when you actually need it
“GENERATED_BODY” no longer resets your protection level to “public”. It will preserve your settings.
Please use the new “GENERATED_BODY” specifier instead of “GENERATED_UCLASS_BODY”. It enables many of these new improvements!

翻译过来

  • 可以定义和使用“常规”的C++构造函数,可以使用无参构造函数。
  • 不再需要为属性提供类别以将其显示给编辑器或蓝图。现在有默认类别
  • FPostContructInitializeProperties已经弃用,由FObjectInitializer代替,只需要在实际需要时指定它即可
  • GENERATED_BODY“不在重置你的成员为”Public”,它会保留你设置
  • 推荐使用“GENERATED_BODY

总结: 4.6以后的版本使用后者,不要使用前者。

题外话: 关于GENERATED_BODY()GENERATED_USTRUCT_BODY() 的区别
源码中关于这个两个宏定义,可以看出来

#define GENERATED_BODY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_,__LINE__,_GENERATED_BODY);
#define GENERATED_USTRUCT_BODY(...) GENERATED_BODY()

GENERATED_USTRUCT_BODY()GENERATED_BODY()的别名,这两个其实是一样的。

你可能感兴趣的:(笔记,UE4)