[Networking] Spawning players on specific player starts

Okay so I am currently working on a small game to play for me and my friends.

Assigning teams is the same logic as in the ShooterGame template.

Now I found out that the way it is programmed in the shootergame template it does not work. This is because the moment a playerstart is chosen the playercontroller doesn’t know yet on what team it is.

I also found a really old bug pointing to this.

If somebody would be so nice to point me into the right direction. Preferable someone with networking experience.

I already found the GameMode call logic which is: PreLogin → ChoosePlayerStart → Login → PostLogin

So the moment my playercontroller is assigned a team at the moment is in the PostLogin method which I think is the correct method to put such logic in.

I don’t understand why ChoosePlayerStart is called before the Login method because that one creates the PlayerController.

When a PlayerController is initialized it calls FindPlayerStart that calls ChoosePlayerStart and moves the PlayerController and Camera to this spot.

On PostLogin RestartPlayer is called and FindPlayerStart and ChoosePlayerStart is called again to get a spawn location for the Pawn. You may just want to override RestartPlayer and perhaps get the team from there?

That’s the cleanest way. Another dirtier way is to make the decault pawn class a spectator pawn, and when the player Spawns, do your own GetAllActorsWithTag and use whatever tag you added to the playerstarts you want it to be able to use, and then Spawn at that playerstart’s location and possess the pawn.

But I recommend the clean way

Got it working. Thanks for pointing me in the right direction.