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 ...
Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.