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

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.

主站蜘蛛池模板: 岱山县| 贺兰县| 富宁县| 沭阳县| 石屏县| 仙桃市| 淳化县| 连州市| 舞钢市| 和林格尔县| 澎湖县| 治县。| 西吉县| 广平县| 大田县| 西青区| 芮城县| 卢龙县| 酉阳| 金门县| 青铜峡市| 常德市| 岳阳市| 察雅县| 阳江市| 甘孜县| 偃师市| 濮阳市| 宜春市| 潼南县| 固安县| 老河口市| 崇文区| 望都县| 蓬溪县| 宝山区| 谷城县| 小金县| 乌苏市| 韩城市| 双峰县|