Problem when loading games in multiplayer

I did a similar thing in my multiplayer game where each player had a preferred color that was saved on their local computer.

  1. Basically, each local PlayerController reads its color preference from a local save file, and then tells the server what that color is.
  2. The server gets the color the player wants, and then sets a RepNotify variable.
  3. Inside the RepNotify function (not shown in image) you find your Pawn material and change it to the new color.

Notes:

  • The reason I did this with the PlayerController BeingPlay is that the GameMode class only exists on the server, so sadly, the handy OnPostLogin function is not available to remote players who join the game. However, if you don’t want to use BeingPlay you could create a custom Multicast event called MyPostLogin in the PlayerController, and have the server call that every time a Player logs in.
  • One thing to be aware of is that Players joining a game is like this: PlayerController Spawns → a little bit of time passes - > Pawn Spawns → a little bit of time passes → PlayerController Possess Pawn. This means you have to be careful because during the BeginPlay for the Pawn and PlayerController, the PlayerController and Pawn are not connected yet (i.e. the Pawn possession has not occurred yet). A quick hack is to use a delay node to wait a little bit for this to happen.
  • The OnPossess event is super handy, and seems like it would avoid the need for that delay node, but is sadly only called on the server. Again, you could always create a custom Multicast “MyOnPawnPossess” and do it that way to avoid the delay node.