Let’s start with the code:
for(const UStaticMeshComponent* comp : meshes)
{
if(IsValid(comp))
{
TArray<FName> sockets = comp->GetAllSocketNames(); <- This line crashes
...
This code is located inside the OnConstruction method of an actor, it goes through mesh components in a TArray uproperty called “meshes”, and if they are valid does a few operations on their sockets.
The crash doesn’t happen always, for example simply editing the level, or starting the simulation of that level from the editor is fine. But opening a level that contains instances of this actor from a running game (for example: from a menu button) will cause a crash.
The crash also happened a few times by simply opening the level in the unreal editor, but this is rare.
Now, to make things even weirder, if i change the if statement to this:
if(IsValid(comp) && IsValid(this))
the crash never happened while opening the level in-game;
But to make it even even weirder, now it did happen a few times by opening the level in-editor.
What is happening here? Why would a simple getter method, executed on a non-null pointer, to a presumably valid component crash the entire editor? Is this a bug?