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"

Add string to TArray in other actor

I have two actor classes MyActor and MyActor2, I want to pass a TArray from MyActor to MyActor 2. In MyActor2 I have TArray< FString> Parsed which is a global variable. The editor is crashing when doing this.


AMyActor2* actor2;
TArray< FString> Parsed;




TArray< FString> Parsed;

void set(const TArray< FString>& str);


void AMyActor2::set(const TArray< FString>& str){

for(int32 nr=0; nr!= str.Num();){
++nr; }

Product Version: UE 4.15
more ▼

asked Dec 28 '17 at 12:04 AM in C++ Programming

avatar image

34 3 3 8

avatar image Firefly74 Dec 28 '17 at 12:05 PM

i see actor2 is in default only, how do you set it ? could you wrap your call too it with a check ? like :


even if you are pretty sure the value isn't null, add it so you can discard this possibility

anyway, i suggest you to attach visual studio to you game/ editor so you can intercept the crash and see what's wrong ! :)

avatar image BestWarrior Dec 28 '17 at 12:18 PM

I could do that, but I am telling you its working.

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

2 answers: sort voted first

I had not correctly created an instance of MyActor2 causing the reference from my .h file to be null so I added this and its working:
actor2 = GetWorld()->SpawnActor< AMyActor2>((AMyActor2::StaticClass());

more ▼

answered Dec 28 '17 at 04:03 PM

avatar image

34 3 3 8

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


First, you shouldn't make the input argument of your "set" function const because you are modifying your input argument by adding to it. Next, try to change your "set" implementation to the following and it should work fine:

 void AMyActor2::set(TArray<FString>& str)
     for (auto s : str)

Hope this helps.

more ▼

answered Dec 28 '17 at 12:43 AM

avatar image

1.5k 10 10 18

avatar image BestWarrior Dec 28 '17 at 11:42 AM

Thankyou for your time, but it's still not working. I think its something about initializing the TArray or something

avatar image Vizgin Dec 28 '17 at 11:45 AM

Do you get any error messages when the Editor crashes? If so then please post them here so that we can help you resolve them.

avatar image BestWarrior Dec 28 '17 at 11:50 AM

I dont get any errors

avatar image BestWarrior Dec 28 '17 at 11:54 AM

I found this:

for (int i = 0; i < 6; i++) { UStaffUnit* Newunit = NewObject(); RegularUnits.Add(Newunit); }


I think I need to do something like this, with strings.

avatar image Vizgin Dec 28 '17 at 12:00 PM

If the editor crashes I doubt it has to do anything with your string copying. You're probably trying to dereference a nullptr somewhere in your code. Check in an if-else statement whether your actor2 is valid before calling its member function "set". Let me know how it goes :-)

avatar image BestWarrior Dec 28 '17 at 12:01 PM

The actor its fine, I can call other stuff, so If I use a local variable TArray< FString> in set() its working, but I want to set the global variable.

avatar image Vizgin Dec 28 '17 at 12:11 PM

Well, I don't know what that global variable is, how you defined it and what you're trying to do with it. Unfortunately, your issue is somewhat vague and given the information you've provided, if a null checking isn't helping either, then I have no more comment to give. Maybe others can help but I think you need to provide more details for us to be able to help you. Good luck debugging your code :-)

avatar image BestWarrior Dec 28 '17 at 12:16 PM

MyActor2.h TArray< FString> Parsed;

Parsed is the global variable here that I want to set, but if I do this its working, though I dont want that.

void AMyActor2::set(TArray< FString>& str){
TArray< FString> ParsedLocal;
for (auto s : str)

I will try to find a way. Anyway, thankyou for your help.

(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