In short: while in an online session, how do I load a saved game from a client’s computer and not the server.
There’s pictures involved, but for whatever reason they won’t upload. Here’s a link to the google doc containing this post with pictures.
Main Menu level loads, using GameMode_MainMenu
GM_MainMenu has the following defaults
GM_MainMenu is an empty class otherwise, no login in it’s event graphs/construction script
PC_MainMenu creates the main menu widget
PS_Gameplay loads the save game. Since we haven’t created or joined a session at this time, it loads the save game from the local computer. From this save, it pulls the character class and saves that to a variable in PS_Gameplay.
The game instance only ever has two jobs: creating a session, and joining a session.
The main menu widget does the following
Have a Join Game, when clicked calls the Find Session function in the game instance
Have a Host Game button, which requires a server name text box to contain input to be enabled, when clicked calls the Create Session function in the game instance passing in the server name
Allows the player to choose their character through a combo box
This sets a character class var in the main menu widget, then calls SavePlayerInfo in the current player state. That function does the following
When a player clicks Host Game, the game creates a new session and opens the gameplay map. This map uses a new game mode, GM_Gameplay, with the following defaults
And this game mode only has two functions (AddPlayer is called from PC_Gameplay, which I’ll get to next)
When an instance of PC_Gameplay is created, it does the following
In the EventOnPostLogin in the game mode, it calls SpawnPlayer on the New Player, which does the following
InitializeAfterPossess sets a health variable in BP_GameplayCharacter, which is outside the scope of this issue. Once the player has spawned its character and possess it, it adds itself to the list of connected players in the game mode.
The issues that arises is currently within the player state. The first thing I have noted is when the game initially launches to the main menu, the player state is created and putting a Print String in its BeginPlay will fire. When that player hosts or joins a session, both the server and the client will call that BeginPlay on that player state, causing the aforementioned Print String to fire twice. In addition, this Print String is called by the server before it is called by the client, so all logic happens server side first, then client side. This normally wouldn’t be much of an issue, except during the BeginPlay of the player state, it’s loading the saved game to retrieve the selected character class, which is then passed to the player controller to determine which pawn is spawns and possess. Because the the server is calling this event first, it always loads the saved game which exists on the server computer, and thus the selected character class of the server, before it loads the client saved game, causing all clients to use whichever character the server had selected.
As stated above, here is ultimately my question: While I am in an online session, how can I load a save game from the client’s computer?