How would i transfer a few ints as an index of a character that has been chosen, alongside some other data.
According to this post: What should I do in GameMode, GameState, and PlayerState? - #3 by Yun-Kun, you would store them in the GameInstance:
You have to set the game instance in the project settings.
You could also use a savegame and reload it on the next level, but that would be more work.
Re-read the title.
So are you trying to transfer a variable from the map itself and not the player? Are the ints different for each player, or are they the same for all players? It would be helpful to know more details.
Any variable put into your Game Instance will be saved between maps. So before you change maps set the variables in your Game Instance then retrieve them when the new map is loaded.
You can also use level streaming and have an actor that is in the persistent map hold the variables. Then use a get all actors of class node to retrieve them.
How would one go about getting who is who, to assign the right class to the right player
I think this would work. The persistent level is empty and only contains the persistent variables, then use level streaming to load in new levels.
When a player joins, you handle the logic either in the player state, player controller, or player character; there’s many ways to go about it. Remember, there is communication going on between the client & server, so you shouldn’t be for-looping through each player.
Also, more details would help.
Am making an fps game, All i want is to store what class someone is across maps.
Well, I tested the game instance and it worked:
The class variable (an enum) is in the game instance. When the widget is created (pre-construct), it adds all the options to the combo box and sets the selected option to the variable in the game instance. When the player selects a new class, the widget updates the variable in the game instance. When the level switches, the widget is recreated and reloads the variable from the game instance. Since the game instance is persistent throughout the game session, the selection stays the same.
This is all that’s happening; this goes in the widget:
The game instance only contains the variable; it doesn’t have any code for it. However, I did put this:
This is just debug to show that “Event Init” only fires once for the entire game session. You can see this in the video.
I didn’t test this in multiplayer since switching levels needs more than just “open level”, but it should work the same.
You can alternatively use level streaming to load & unload levels, that way you don’t have to worry about server travel. Basically, the persistent level will be the lobby, and the streaming levels will be the maps.