UE_Log crashing engine when trying to print a FString

Hi all again,
I’m trying, in vain, to print a FString from a specific struct contained in a TArray, like this:


 struct stuff { int32 first; FString second; };
 TArray<stuff *> stuffList;
 
 FString test = stuffList[x]->second; //x is a valid index
 UE_LOG(LogTemp, Warning, TEXT("%s"), *test);


No matter what I try it crashes.
Funnily enough, even AnswerHub crashed when I posted the question there, and had to rewrite the post…

Laughed so hard when I read your second sentence!


**Raw Struct Memory Management**

when you create regular structures or even UE4 C++ UStructs you absolutely must initialize your data members!

raw structs just get a section of memory that could contain anything, until you initialize the vars you have no idea what's there!

And so you dont have a clean FString in there, you have a tangled mess that UE4 is dereferencing, so you are dereferencing garbage.

Try this



```


struct stuff { 
	int32 first; 
	FString second; 
	
	stuff()
	{
		first = 0;
		second = "";
	}
};


```



or this:



```


struct stuff { 
	int32 first = 0; 
	FString second = ""; 
};


```



♥

Rama

Thanks for the tip Rama.