pass lobby data to game map

I’m making a multiplayer game, in the lobby map I save the name of the player’s chosen team in the game instance and when I make the travel map for the game map, in game mode I call the onpost login event to check which team that player belongs , but the variable in the game instance where I recorded this information is always empty , and in the lobby it shows it being successfully recorded

are there other ways to record server variables without using gameinstance?

The reason for the behavior is that PostLogin fires on the server (GameMode is server-sided only), so when you talk to the GameIntance you are in fact talking to the server-sided GameInstance (GameInstance exists on both server and clients but has no means of replication, so they are separated). However, when you save the player’s chosen team beforehand, you are saving it in the client-sided GameInstance (that’s how you should be doing it, so it’s all good). One workaround to this is, to fire a client RPC on PlayerController from PostLogin, talk to the client-sided GameInstance, and then fire a server RPC back with the data, and ofc validating it before applying it.

You can take a look at this compendium if you want much more forbidden knowledge (other ways that is).

1 Like

in the first image is the initial logic in the game mode of the game after the fast travel map, it will pick up the spawn player on the map and then it will check which team the player selected

second image: on the controller of the player who entered the map it takes the information of which team the player chose in his gameinstance and returns the information to the server

third image: the player’s controller returns this function to the server to spawn the player in the right place

From the print strings it looks like the right team for the player, it spawns on the map but the player doesn’t have ownership of the character, don’t move or anything

Do you know what the problem is or a better way to do this?

That’s a different issue, so I would recommend you open a new thread, and that you check your logs (either in /Saved/Logs or in real-time inside the editor in the Output Log) beforehand and try to fix it yourself, or use that to provide further related info.

You have done what I suggested, and that looks fine to me (if you’ve done it in cpp, you would have saved yourself the client RPC), so no problem with the core system. The few notes I could give are:

  1. SpawnTeamClient doesn’t need to be a client RPC. Think about it, you fired a client RPC beforehand, you’re already on client, why would you fire another client RPC? Just to make sure you’re on the client again? No, that’s useless, and it would fire as a normal function anyways, so make it a regular event instead.

  2. From the looks of it, you are spawning all pawns at the same transform, by picking the first entry of the array (i.e. SpawnsTeamX[0]), and in return there’s a great chance that pawns spawn on top of each other, and not be able to get possessed correctly. In which case you could also be having the problem of characters not spawning (so you see a message in the Output Log like SpawnActor failed because of collision at the spawn location...).