I’m trying to figure out how to get spawning as a spectator and having it switch to player once the match state changes working over network. What I tried to do is override ready to start, and after 5 seconds have it transition from Waiting to Start to InProgress. What I can’t figure out is how to get the player to respond to that. I tried enabling bOnlySpectator in playerstate, but when the game transitioned to InProgress, it didn’t restart as a player. I also enabled bStartPlayerasSpectator. I’m very confused, and if anyone has done this successfully any help would be appreciated.
TLDR: I basically want to start as a spectator, and use the native match state to switch to my player pawn when the game starts even on multiplayer. I believe I’m overriding the wrong functions.
The default behavior of GameMode (not to be confused with GameModeBase) is actually what you want where it spawns in as a SpectatorPawn and spawn the DefaultPawn when switching to Match State InProgress. The “problem” is that the MatchState changes to InProgress as soon as the first player login by default.
You prevent this by setting DelayedStart to true. This will make ReadyToStart return false.
Now you can call StartMatch whenever you like which will give all existing players the DefaultPawn as well as any new players logging in.
If you set bStartPlayerAsSpectator players will remain as Spectator even if the match is InProgress and you have to call RestartPlayer to switch that player to a DefaultPawn.
bOnlySpectator will prevent the player from possessing anything besides a SpectatorPawn throughout the game.
Yes that’s how I currently have it the only issue is it doesn’t work and I can’t figure out why. I have delayed start enabled and I have bStartPlayerasSpectator enabled. The only way it works is if I enable bIsOnlySpectator in the player state, but then it’s stuck as spectator.
I can see the match change from WaitingToStart to InProgress, but it didn’t work, I checked the source code of GameMode.cpp and it said that it should automatically do this like you said.