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

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.

主站蜘蛛池模板: 石渠县| 巴楚县| 会昌县| 文昌市| 三门县| 苗栗市| 大悟县| 博野县| 宣恩县| 青河县| 沈丘县| 东丽区| 灵璧县| 原平市| 招远市| 西华县| 景德镇市| 甘孜县| 新兴县| 玉林市| 龙南县| 天台县| 五寨县| 连云港市| 平江县| 内江市| 长垣县| 沙坪坝区| 宁城县| 五大连池市| 蕲春县| 台前县| 巴彦淖尔市| 宁城县| 沈丘县| 阿合奇县| 咸宁市| 桦甸市| 岗巴县| 淮滨县| 饶阳县|