Hey I’m trying to figure out how I would create a character selection screen, where each player picks a character while in the lobby before the game starts and then the game spawns their pick when the game starts on a different map.
Im trying to save the picked character class in the player state, but when its time to read it in the player controller and actually spawn the character it turns out empty.
I tried using the game instance to store the character class, but if I understand correctly it is not replicated, so when I try to spawn the character on the server only the character the server picked is spawned for all of the players.
I’m not sure if there’s a different way to handle it in modern Unreal, but in UE2 and UE3, the server would be sitting in the map, and the player controllers wouldn’t be ready to start until after they had selected their characters. So, you don’t tell it what you want to spawn in a separate level, you just have it selected locally in the level you’re going to play, and then you start with that one.
In the lobby, store the selected character in each player’s local game instance. Then, when the new map is opened, have each player controller get their selected character from their game instance, then send it to the server before spawning.
4 In game, while in the lobby, I pick Blue Character on the client and Red Character on the server, but both characters spawn as red on the In-game map. Log comes out like this:
Where does it go wrong? The server reads the PC Selected Character variable as Red character when I call it on the OnServer event, yet it shows as the correct character when i print the string after in the player controller. I cant understand why or what to do about it.
Looks like the Server is spawning a character for the client. Since server’s game instance has red character, both will be red. Try a branch with a “Is Local Player Controller” node before the cast on BeginPlay, and only set/spawn the selected character if true.