Need Some Help With Reading A Variable On MyPlayerController From MyGameMode


I made my own player controller (MyPlayerController) and game mode (MyGameMode).

In my settings menu I allow the players to change their character, when they select a character it changes an integer then it RepNotify’s and sets the value in MyPlayerController. - Works
I Load and Save my settings from MyPlayerController - Works
The problem I have is in MyGameMode on PostLogin I want to grab the int value from MyPlayerController but it only works if I’m the host. I have been at this for about a week trying so many different ways and still can’t figure it out. Is it possible for MyGameMode to access MyPlayerController and grab a variable?

All advice is welcome,
Thanks for taking the time to look at this.

GameModes only exist on the server, so I am confused what you mean by your setup only working on the host? What is your exact issue?

Yes I know the game mode only exists on the server :slight_smile: My character is stored as an integer in my player controller, (I have multiple character BP’s so I reference them by a number in the player controller) but my game mode won’t get the value unless it’s the host/Server PC. I thought the game mode has access to every connected controller? I have another question, when exactly is the game mode spawned? Is it right after the level is loaded? See the 2nd picture when I casted to my player controller, why don’t I get a value. Thanks

Try something like this:

  • Remove delay in your OnPostLogin event because some players may be skipped if they join in a short period of time.
  • In your Game Mode spawn dummy character/actor and possess it with the current player controller.
  • On your dummy / spectator character use Event Possessed (or check if the current player is the owner) and from there Spawn your desired character and destroy dummy character.
  • Save your player data like Character Selected etc in your Game Instance. When Spawning a new character use Run on Owning Client, get character/variables from the Game Instance, call Spawn Event on the server.

You can spawn also character from Game Mode but maybe it’s more flexible to spawn spectator/dummy character first. Also, I think you have too many unnecessary variable replications…like RandomSpawnLocation (transform). Server will spawn on that location without replication anyway and if that actor/character is already replicated it will replicate his location and spawn. The same applies to other variables.

Thanks I will try that. I figured that I was replicating to much but after nothing was working I replicated everything lol By spawning a dummy character do you think this is a dirty way of doing it or is this how many people do it and is an accepted practice?

Well it depends on your gameplay flow and application design. The point is that you need to understand what variables used only on the server, what variables are replicated to the client and what is used on the client only.
I almost always use this method to spawn dummy character and i never had any problem. Of course, you can also spawn a character directly from GM, but you need to think which one is better for you.


I have it working Thank You Mr. Wood!