In my game, players log and then customise their characters. Once they finished they go in another map. But it happens that some players ends up with other players characters. (It’s like in Mario kart you would pick Luigi and end up with Daisy, the character that your friend picked).
My problem is that to save the customisation made in the first place, I use the game instance with a list of the customisation for each player sorted in their log in order. I didn’t found a better way to do this since i need to save this data between levels.
Now when I load a new level for every players, On Post Login on the game mode, I give the customisation to the newly logged player. The first player to load the new level gets the first customisation of the level, and so on…
The problem with this (I suppose, I’m not sure) is that this assume that everytime that the players will travel to a new level, everyone will load the level in the same order and you guessed it, this isn’t happening.
My goal is to link a PC to an index, the first time the player would log in the lobby, that would be saved throughout levels to corrreclty assign the customisation and spawn points, etc…
I was looking to do this a while back and was surprised to find no consistent ID I could get at across PCs.
Easiest option (if the the game is simple enough) is to do as Rev suggested. If your game is too complicated, or just demands server travel, or you have gone too far now anyway then as best I can tell you will need to do all the book-keeping yourself.
An outline for one such system:
Add some kind of Multiplayer ID var in the game instance, default to 0
Add a Connected Clients Counter var in there too, and maybe default to 2 (reserve 0 for invalid, and 1 for a server player) (never decrement this! It counts the number (+2) of clients who have connected in this session, not the number currently connected).
After a client connects, enter a ‘handshake’ type protocol exchange: client sends server a HELLO with its MultiplayerID (0 if it connecting to this server in an initial join), then If MutliplayerID == 0 the Server assigns a new id for the player (ConnectedClientsCounter++) and sends a HELLO back with the new ID, which the Client puts in its game instance to use for future handshakes (on server travels), Else (ID>0) the server (validates and) maps the ID received to the PC (and/or vice-versa), and can now use this ID<->PC mapping to correctly identify players between levels.
Whatever you were storing in login order (in an array?) you now store by ID (in a Map not an Array, there can be holes).
I’m doing the customisation in the “lobby” level because it won’t change once the game has started so I need to separate it from the actual gameplay.
The workaround I found is to use the player name variable that comes with the steam advanced sessions because this variable meets all the requierements I wanted but I was pretty sure that was not the common way to do what I wanted.
And thanks for your solution, I thought that the game instance was only on the server since when I tested getting it on the client before it failed, but I tested it out now and it seems that it failed for another reason because now I can get it.
Would you suggest me to try your solution or keeping my workaround is fine ?
I imagine most games of any complexity will want to move players to new levels from time to time, so I doubt this is a rare problem.
The name you have found and are using sounds good (if it can’t be changed on the fly) and I would not bother adding your own code if that is working! You surely have a list of other things to do, if this is working now, I would move on to the next thing