Can't add elements to TArray

I’m creating a TArray and using it as a UPROPERTY. When I try to add any element it just doesn’t work.

Is it because of the UPROPERTY? How can I make it?

I’m using this structure:

UPROPERTY(BlueprintReadOnly, EditAnywhere)
TArray MyArray;
MyArray.Add (TEXT(“INSERT”));


First UPROPERTY should be contain BlueprintReadWrite because thats mark that property as writeable from blueprint… Long info about this: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums


TArray’s always should contain the type, for example

TArray<FString> YourArrayName;

Final Code should be look like this in your .h file:

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Array Stuff")
TArray<FString> YourArrayName;

After this you can use YourArrayName.Add(“TestString”); for example in your cpp file

Further info how you need to use TArrays: TArray: Arrays in Unreal Engine | Unreal Engine Documentation


To expand upon what AmphDev said, I would only make the property BlueprintReadWrite if you have a need to edit the array in blueprints. Otherwise I would recommend keeping it as BlueprintReadOnly and VisibleAnywhere. In this example the Uproperty shouldn’t have any effect on your code however, I’m almost certain it’s the missing type , like AmphDev pointed out.

Got it. Except for the “ReadWrite” part.

My blueprints code will only read the information, just C++ code will write it in the array.

I know I can just code it to not write in BP, but do I really need to ever have this “ReadWrite” property? Tought it was meant just for BP, and wouldn’t block the C++ add. I am wrong?

The documentation is not really clear about it.

Anyway, thank you so much! I’ll try this today. :smiley:

Lol. I’ve seen Cabewz comment just after posting. Now it’s clear.

Thanks guys! :smiley: