I make a multiplayer game with lobby and game level. In lobby, each player can select a team. In lobby PlayerController i create an event for selecting a player team, that will called from widget button. Then i make a server travel to game level from lobby. I need to transfer data about selected team for each player. I found that can be done using a GameInstance. In lobby controller event, after player select a team, it will save in GameInstance. But i dont know how to properly get this variable in game level for owning client. It always only gets a server team value.
Here is my lobby controller event for changing a team.
Maybe i made something wrong here, but looks like all right.
Please, help me ASAP.
If you are using seamless travel then you can use player state and override the copy properties function to pass values in-between levels.
On the other hand yes this can also be done in game instance, but I see that you have made Player team replicated, there isn’t a need for this what you should have done is simply without any run of server event or owning client event, the things in your game state don’t need to be replicated but if you want to propagate the changes to other clients you need to have same variables in a (for sake of example : Character class) replicated actor which are replicated or use rep notify. (Essentially making the same copy of all the variables in your game state but now in character class and marking them replicated/RepNotify)
you will manually need to get game instance in your character class and set things on server. Here is an example, In my character class I get saved variable from game instance and send it to server via event’s input and since it is marked rep notify it will call a function when ever it is changed and in that rep notify function I show the value on widgets:
I would recommend you should try to move the data to player state and use its copy properties function to move data from one level to another during seamless travel. (NOTE: this will only work in standalone)
1 Like