GameMode::ChoosePlayerStart_Implementation called multiple times

Hello,
I am overriding the function ChoosePlayerStart_Implementation(). I am running into weird behavior (UE 4.13.2)

The function is being called double the amount of players. For example, if I have 2 players, then it gets called 4 times. If I have 4 players, then it gets called 8 times. For 1 player, it gets called twice.

I am attempting to spawn my players there, so I end up with double the meshes.

Any ideas why this is happening?

Thank you

Still no luck.

Here is some Log

MyLog:Warning: ChosingPlayer, 0
MyLog:Warning: SpawnLocation found for ITR: 58140.000000 -3803.000000 3450.000000 for team 1
MyLog:Warning: SpawnLocation found for ITR: 19069.000000 23036.000000 5361.000000 for team 2
MyLog:Warning: Chose1 58140.000000 -3803.000000 3450.000000 for team 1
MyLog:Warning: Post Login, so far 1 playres
*
MyLog:Warning: Found player 1
MyLog:Warning: Overlap ON
MyLog:Warning: ServerFunction ON
MyLog:Warning: SpawnLocation: 58140.000000 -3803.000000 3450.000000 for controller team 1
LogGameMode:Display: Match State Changed from EnteringMap to WaitingToStart
LogGameState: Match State Changed from EnteringMap to WaitingToStart
LogGameMode:Display: Match State Changed from WaitingToStart to InProgress
MyLog:Warning: ShouldSpawn set to false
MyLog:Warning: ****ChosingPlayer, 1
MyLog:Warning: SpawnLocation found for ITR: 58140.000000 -3803.000000 3450.000000 for team 1
MyLog:Warning: SpawnLocation found for ITR: 19069.000000 23036.000000 5361.000000 for team 2
MyLog:Warning: Chose3 19069.000000 23036.000000 5361.000000 for team 2
MyLog:Warning: Init StartSpot was called 1
MyLog:Warning: SpawnLocation for team 2.
LogGameState: Match State Changed from WaitingToStart to InProgress
LogLoad: Took 0.203813 seconds to LoadMap(/Game/Maps/PlayLevel002)
LogHandshake: SendConnectChallenge. Timestamp: 0.225515, Cookie: 072000133016094214139148120082194036121244214005054027074165
LogHandshake: SendChallengeResponse. Timestamp: 0.225515, Cookie: 072000133016094214139148120082194036121244214005054027074165
LogNet: Server accepting post-challenge connection from: 127.0.0.1:49725
PacketHandlerLog: Loaded PacketHandler component: Engine.EngineHandlerComponentFactory (StatelessConnectHandlerComponent)
LogNet: NotifyAcceptedConnection: Name: PlayLevel002, TimeStamp: 11/30/16 05:11:25, [UNetConnection] RemoteAddr: 127.0.0.1:49725, Name: IpConnection_55, Driver: GameNetDriver IpNetDriver_62, IsServer: YES, PC: NULL, Owner: NULL
LogNet: AddClientConnection: Added client connection: [UNetConnection] RemoteAddr: 127.0.0.1:49725, Name: IpConnection_55, Driver: GameNetDriver IpNetDriver_62, IsServer: YES, PC: NULL, Owner: NULL
LogNet: NotifyAcceptingChannel Control 0 server World /Game/Maps/UEDPIE_1_PlayLevel002.PlayLevel002: Accepted
LogNet: Remote platform little endian=1
LogNet: This platform little endian=1
LogNet: Login request: /Game/Maps/PlayLevel002?game=/Game/GameBP/BPLobbyGameMode.BPLobbyGameMode_C?Name=Colossus-PC-6576D678400D64A148F5E58530485C49 userId: Colossus-PC-6576D678400D64A148F5E58530485C49
LogNet: Welcomed by server (Level: /Game/Maps/UEDPIE_1_PlayLevel002, Game: /Game/Game/BPGameMode.BPGameMode_C)
LogLoad: LoadMap: 127.0.0.1//Game/Maps/UEDPIE_1_PlayLevel002?game=/Game/Game/BPGameMode.BPGameMode_C
Cmd: MEM
LogMemory: Platform Memory Stats for Windows
LogMemory: Process Physical Memory: 2302.75 MB used, 2330.30 MB peak
LogMemory: Process Virtual Memory: 2994.56 MB used, 3216.00 MB peak
LogMemory: Physical Memory: 8920.34 MB used, 23773.09 MB free, 32693.43 MB total
LogMemory: Virtual Memory: 3703.64 MB used, 23773.09 MB free, 8388608.00 MB total
Allocator Stats for TBB: (not implemented)
LogAIModule: Creating AISystem for world PlayLevel002
LogWorld: Bringing World /Game/Maps/UEDPIE_2_PlayLevel002.PlayLevel002 up for play (max tick rate 0) at 2016.11.30-05.11.25
LogWorld: Bringing up level for play took: 0.006647
LogLoad: Took 0.167398 seconds to LoadMap(/Game/Maps/UEDPIE_1_PlayLevel002)
LogNet: Client netspeed is 10000
LogNet: Join request: /Game/Maps/PlayLevel002?game=/Game/GameBP/BPLobbyGameMode.BPLobbyGameMode_C?Name=Colossus-PC-6576D678400D64A148F5E58530485C49?SplitscreenCount=1
MyLog:Warning: ShouldSpawn set to false
MyLog:Warning: ***ChosingPlayer, 1
MyLog:Warning: SpawnLocation found for ITR: 58140.000000 -3803.000000 3450.000000 for team 1
MyLog:Warning: SpawnLocation found for ITR: 19069.000000 23036.000000 5361.000000 for team 2
MyLog:Warning: Chose1 58140.000000 -3803.000000 3450.000000 for team 1
MyLog:Warning: ShouldSpawn set to false
MyLog:Warning: ChosingPlayer, 2
MyLog:Warning: SpawnLocation found for ITR: 58140.000000 -3803.000000 3450.000000 for team 1
MyLog:Warning: SpawnLocation found for ITR: 19069.000000 23036.000000 5361.000000 for team 2
MyLog:Warning: Chose3 19069.000000 23036.000000 5361.000000 for team 2
MyLog:Warning: Init StartSpot was called 2
MyLog:Warning: SpawnLocation for team 2.
MyLog:Warning: Post Login, so far 2 playres

MyLog:Warning: Found player 2
MyLog:Warning: Overlap ON
MyLog:Warning: ServerFunction ON
MyLog:Warning: Overlap ON
MyLog:Warning: ServerFunction ON
MyLog:Warning: Overlap ON
MyLog:Warning: ServerFunction ON
MyLog:Warning: SpawnLocation: 58140.000000 -3803.000000 3450.000000 for controller team 2

I’m guessing you are checking ‘ShouldSpawn’ before spawning the player?

Share the code where you check shouldSpawn. Maybe your if statement (or whatever you are using) is a bit off.

Thank you for your reply.

I am not concerned about that. I am curious to why the ChoosePlayerStart_Implementation() is called multiple times. I traced it through source code and it gets called from RestartPlayer(), which may be called form several places. I wonder if this behavior is intentional.

Basically all I have is a listen server, when client joins, jump to a different level.

Is it possible it’s called once in the server and once in the client? In that case you might want to add a check and only fire it on the server?

Hmmm. Interesting thought. I thought that GameMode functions are only fired on the server, but if it is true, it can explain the behavior. I will check.

Ok, here is what I found so far. In “MyGameMode” class, I have two members: TeamA and TeamB. When a player connects, I choose starting point and increment either TeamA or TeamB.

However, when the client connects, TeamA and TeamB are 0, as if it is checking its own game mode. I printed the unique ID in PostLogin(), and indeed I see two different IDs based on the player ID.

As example:
MyLog:Warning: Post Login, so far 1 playres*****
MyLog:Warning: Gamemode ID 38587
MyLog:Warning: Controller ID 38563

MyLog:Warning: Post Login, so far 1 playres*****
MyLog:Warning: Gamemode ID 38494
MyLog:Warning: Controller ID 38295

Same is true for InitStartSpot_Implementation() and ChoosePlayerStart_Implementation()

Moreover, if I set game for 4 players, upon each player login, I find that there is a different GameMode unique ID and variables are set to 0.

I don’t think I can replicate GameMode variables. I am not understanding how I am supposed to track what players I spawned. It seems that clients do have their own GameMode!

Yeahhh I noticed the same thing regarding the amount of times ChoosePlayerStart was getting called. This is how I ended up getting around it, I basically just did some checks on the PlayerController and added an increment counter on the GameMode. PS: Got the player starts on the constructor.

AActor* AMultiplayerFPSGameModeBase::ChoosePlayerStart_Implementation(AController* Player)
{
	AFPSPlayerController* LoggedInPlayer = Cast<AFPSPlayerController>(Player);

	if (!LoggedInPlayer->GetHasSpawnBeenSet())
	{
		LoggedInPlayer->SetPlayerNumber(SpawnCounter);
		LoggedInPlayer->SetHasSpawnBeenSet(true);
		SpawnCounter++;
	}


	UE_LOG(LogTemp, Warning, TEXT("Player: %s"),
		*LoggedInPlayer->GetName());
	UE_LOG(LogTemp, Warning, TEXT("Spawn Point Used: %i"), LoggedInPlayer->GetPlayerNumber());

	if (PlayerStarts.IsValidIndex(LoggedInPlayer->GetPlayerNumber()))
	{
		return PlayerStarts[LoggedInPlayer->GetPlayerNumber()];
	}
	else
	{
		return PlayerStarts[PlayerStarts.Num() - 1];
	}
}```