How to spawn the player characters in Multiplayer

How do i spawn the whole player characters with the controller in Multiplayer when i switch between levels. It worked on starting the game in the beginning. But i let the characters spawn after hosting/joining a lobby and start the game then. Thats how the code looked like:


this works just for games that starts in the level to play instead of joining a new level

and this picture…

At a quick glance, I can tell this is not how you should spawn pawns (player characters in your case). The first point in code where it’s safe to fire RPCs on PlayerController is AGameModeBase::PostLogin which happens after APlayerController::BeginPlay is called.

What should you do instead then? GameMode is the answer. Unreal already has an out of the box pawn spawning & possessing code in GameMode class. HandleStartingNewPlayer is what spawns and possesses pawns.

But what if you don’t like the process itself? For example, where the pawns are spawned. For that reason, you can override functions, in this case FindPlayerStart, or make functions of your own and override the function calling the previously mentioned. The options are endless, but it’s so important to do things right. Also don’t feel too afraid to look at how pawns are spawned in source (C++ knowledge required of course).

1 Like