美文网首页
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

    1、GENERATED_UCLASS_BODY和GENERATED_UCLASS的区别 转载: UE4中的反射之一...

  • Flutter 6种构造函数详解

    Flutter有生成构造函数、默认构造函数、命名构造函数、重定向构造函数、常量构造函数、工厂构造函数 一.生成构造...

  • C# 构造函数总结

    构造函数 构造函数分为:实例构造函数,静态构造函数,私有构造函数。 实例构造函数 1、构造函数的名字与类名相同。 ...

  • 原型链

    原型以及原型链等相关概念总是离不开构造函数。下面我们先从一个构造函数来看。 一、构造函数创建对象 通过new 构造...

  • Javascript 基础之原型链

    构造函数、构造函数实例、构造函数原型 function Student (name) { } - 这是构造函数va...

  • Swift基础语法-类的构造函数

    本节知识点 构造函数的介绍 构造函数的基本使用 自定义构造函数 属性与构造函数 1. 构造函数的介绍 构造函数类似...

  • C++:面向对象基础

    构造函数 C++中有三种构造函数:默认构造函数,有参构造函数,拷贝构造函数 类对象的初始化 括号法//默认构造函数...

  • 构造函数

    构造函数分为: 1.实例构造函数 2.私有构造函数 3.静态构造函数 私有构造函数 私有构造函数是一种特殊的实例构...

  • Dart整理

    Dart构造函数 普通构造函数和命名构造函数 默认构造函数一个类没有声明构造函数,默认会有一个无参构造函数,声明了...

  • Kotlin面向对象 (3)✔️构造函数

    主构造函数次构造函数默认构造函数 kotlin中的构造函数有主次之分,主构造函数只能有一个,此构造函数可以有多个。...

网友评论

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

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