美文网首页
UClass构造函数相关(GENERATED宏、构造函数Styl

UClass构造函数相关(GENERATED宏、构造函数Styl

作者: 珏_Gray | 来源:发表于2019-06-13 11:55 被阅读0次

    1、GENERATED_UCLASS_BODY和GENERATED_UCLASS的区别

    转载: UE4中的反射之一:编译阶段

    2、 C++风格的构造函数和带FObjectInitializer参数构造函数的区别

    使用上来说,如果子类不更改父类的Component或者SubObject,则使用C++风格更简洁。FObjectInitializer提供更高级的功能。

    摘自官网:https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Reference/Classes/index.html

    Constructor Format

    The most basic form of a UObject constructor is shown below:

    UMyObject::UMyObject()
    {
        // Initialize Class Default Object properties here.
    }
    

    This constructor initializes the Class Default Object (CDO), which is the master copy on which future instances of the class are based. There is also a secondary constructor that supports a special property-altering structure:

    UMyObject::UMyObject(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
    {
        // Initialize CDO properties here.
    }
    

    Although neither of the above constructors actually perform any initialization, the engine will have already initialized all fields to zero, NULL, or whatever value their default constructors implement. However, any initialization code written into the constructor will be applied to the CDO, and will therefore be copied to any new instances of the object created properly within the engine, as with CreateNewObject or SpawnActor.

    The FObjectInitializer parameter that is passed into the constructor, despite being marked as const, can be configured via built-in mutable functions to override properties and subobjects. The UObject being created will be affected by these changes, and this can be used to change the values of registered properties or components.

    AUDKEmitterPool::AUDKEmitterPool(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer.DoNotCreateDefaultSubobject(TEXT("SomeComponent")).DoNotCreateDefaultSubobject(TEXT("SomeOtherComponent")))
    {
        // Initialize CDO properties here.
    }
    

    In the above case, the superclass was going to create the subobjects named "SomeComponent" and "SomeOtherComponent" in its constructor, but it will not do so because of the FObjectInitializer. In the following case, SomeProperty will default to 26 in the CDO, and thus in every fresh instance of AUTDemoHUD.

    AUTDemoHUD::AUTDemoHUD()
    {
        // Initialize CDO properties here.
        SomeProperty = 26;
    }
    

    相关文章

      网友评论

          本文标题:UClass构造函数相关(GENERATED宏、构造函数Styl

          本文链接:https://www.haomeiwen.com/subject/rfijfctx.html