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.
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)
Parsed.Add(s);
}
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
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
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());