官术网_书友最值得收藏!

Unreal's garbage collection system and UPROPERTY( )

When you have an object (such as TArray< >) as a UPROPERTY() member of UCLASS(), you need to declare that member as UPROPERTY() (even if you won't edit it in blueprints), otherwise TArray will not stay allocated properly.

How to do it...

Say we have a UCLASS() macro as follows:

UCLASS()
class MYPROJECT_API AWarrior : public AActor
{
  //TArray< FSoundEffect > Greets; // Incorrect
  UPROPERTY() TArray< FSoundEffect > Greets; // Correct
};

You'd have to list the TArray member as UPROPERTY() for it to be properly reference counted. If you don't do so, you'll get an unexpected memory error type bug sitting about in the code.

How it works…

The UPROPERTY() declaration tells UE4 that TArray must be properly memory managed. Without the UPROPERTY() declaration, your TArray won't work properly.

主站蜘蛛池模板: 芜湖市| 栾川县| 临湘市| 昌都县| 眉山市| 北安市| 江华| 平舆县| 敖汉旗| 中卫市| 金华市| 黑龙江省| 共和县| 武冈市| 桃园市| 泗水县| 青河县| 淮滨县| 曲松县| 延川县| 家居| 广安市| 祥云县| 道孚县| 湖南省| 万盛区| 临桂县| 蒙山县| 元谋县| 梁河县| 怀化市| 浦城县| 陇川县| 博爱县| 沙田区| 靖西县| 油尖旺区| 枝江市| 农安县| 金塔县| 资阳市|