AttachRootComponentToActor crashes multiplayer game

Hey everyone,

I’m getting the same problem.

, here is a simple say to reproduce the problem using the sample project (miniYag) i sent you for the network issue about file sharing between server and clients.

In the YagPlayerController.cpp, add the following lines around line 1430 (in the ServerSpawnObject function):

// TEST
// ATTACH TO PREVIOUS OBJECT
if (MyGameState && MyGameState->ObjectArray.Num() > 1)
{
	//SpawnedObject->AttachRootComponentTo(MyGameState->ObjectArray[FMath::Min(0, MyGameState->ObjectArray.Num() - 2)]->GetRootComponent());
	SpawnedObject->AttachRootComponentToActor(MyGameState->ObjectArray[FMath::Min(0, MyGameState->ObjectArray.Num() - 2)]);
}

They attach each newly spawned object to its predecessor in the object array maintained by the game state.

You then just have to add two objects to reproduce the problem.

When playing with only a server the attachment works well, but when using 2 players, you’ll get the crash.

Here is a video showing you everything:

I hope this helps.

Cheers