x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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"));

Product Version: UE 4.18
Tags:
more ▼

asked Mar 08 '18 at 01:08 PM in C++ Programming

avatar image

Tabacudo
62 3 5 13

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hello!

First UPROPERTY should be contain BlueprintReadWrite because thats mark that property as writeable from blueprint.. Long info about this: https://wiki.unrealengine.com/UPROPERTY

Second:

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: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/TArrays/

Cheers

more ▼

answered Mar 08 '18 at 01:27 PM

avatar image

AmphDev
1.5k 15 9 34

avatar image Cabewz Mar 08 '18 at 07:30 PM

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.

avatar image Tabacudo Mar 08 '18 at 07:46 PM

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. :D

avatar image Tabacudo Mar 08 '18 at 07:48 PM

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

Thanks guys! :D

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question