Our team is currently developing a multi-player game using Visual Studio 2013 and engine version 10.04. We are using the ShooterGame sample from Epic Games as a template. Below is a virtual demonstration how problems could arise in clients when we call AGameMode::RestartGame() on the server:
Preparation:
Let us attach some break points to the code before we test:
Step 1: Attach break-point to UWorld::CreateWorld(…)
Step 2: Attach break-point to AWorldSettings::NotifyBeginPlay()
Step 3: Attach break-point to APlayerController::Tick(…) and DISABLE it
Round 1 test:
Step 1: Run game as server without debugging
Step 2: Run game as client with debugging, client will be connected to server and play normally
Step 3: Call AGameMode::RestartGame() on server
Step 4: Client will trigger break-point at UWorld::CreateWorld(…). This is called by FSeamlessTravelHandler::StartTravel(…) with comment
“// If a default transition map doesn’t exist, create a dummy World to use as the transition”
Step 5: Immediately press Continue on visual studio debugger. Must be fast!
Step 6: Client will trigger break-point at AWorldSettings::NotifyBeginPlay() called by AGameState::HandleMatchIsWaitingToStart(). The value returned by GetWorld() is DIFFERENT from the AWorld from Step 4.
Step 7: Everything works. Everyone is happy.
Round 2 test:
Repeat Step 1-4 from Round 1
Step 5: Wait ~5 seconds and then press Continue on visual studio debugger.
Step 6: Client will trigger break-point at AWorldSettings::NotifyBeginPlay() called by AGameState::HandleMatchIsWaitingToStart(). The value returned by GetWorld() is THE SAME from the AWorld from Step 4.
Step 7: Activate the breakpoint at APlayerController::Tick(…).Immediately we trigger a break. If we watch the value of GetWorld(), we will find this is DIFFERENT from the AWorld from Step 6. Moreover, its member field bBegunPlay is false.
Step 8 A lot of things breaks, because the world they live in is not initialized.
Conclusion
We are worried that perhaps there is a replication timing bug in the UE4 version 10.4. When the server is restarting, the initialization signal sent to the client through AGameState may be received by the intermediate map created in seamless travel instead of the destination map.
Thank you for reading this report. We are looking forward to hearing from you.