GENERATED_UCLASS_BODY 和 GENERATED_BODY 区别

时间:2021-12-07 20:11:45

the GENERATED_BODY() macro allows the class to build without having a constructor defined. If you need a constructor, you can change that macro to the more familiar GENERATED_UCLASS_BODY(). If you do, you must provide a constructor for the class or you will not be able to build the project in Visual Studio. So your code will look something like this:

GENERATED_BODY()  宏允许类没有构造函数,如果你需要一个构造函数,你可以使用GENERATED_UCLASS_BODY(),当你这样做了,你就必须定义一个构造函数,否则无法编译成功。

红色都都是错误的,根据2014年论坛上Unreal员工的新回复(https://forums.unrealengine.com/showthread.php?52236-4-6-constructor-changes-am-confused),

GENERATED_UCLASS_BODY已经毫无用处,在需要构造函数的情况下,也应该使用GENERATED_BODY();

但GENERATED_BODY似乎并没有public修饰符,所以需要手动添加