I have some variables set up on my player controller that get wiped out as soon as I connect to a server. I can’t seem to find a place where I can put these so that I can send them to the server after connecting. Any suggestions?
Store them in the game instance. It persists through open level.
Hmm, I thought the game instance only exists on the server? My impression was as soon as the client connects, the client’s game instance no longer exists - there is only the server’s game instance that doesn’t exist for the clients.
I ended up doing a really weird process.
- When the client is ready to connect to the server, I save off data from the player controller to the game instance.
- Then, the client connects to the server (Calling “open level” form the player controller)
- The Game Mode event “OnPostLogin” executes for the server. I get the connecting player controller and execute an event on it
- This event is run only on the owning client. It goes back to the client’s version of the game instance and re-obtains the values stored there. Then it calls another event on the player controller, passing the data.
- This second event is run only on the server. It takes the obtained data then gets the game instance. Since it’s run on the server, it obtains the server’s version of the game instance. It calls an event on the game instance, passing the data.
- The game instance then uses the passed data to spawn a pawn for that player.
I can’t help but feel like this is a huge roundabout way to accomplishing this but I couldn’t find any other way. I didn’t want to have to rely on executing client code to finalize the client’s connection to the server - the server should be in charge of everything. But if connecting to the server wipes out player controller data and effectively replaces the client’s game instance and game mode, I don’t see what other choice I have.