In my game, I have different classes of characters, and I want to let the player chosse wich class he will play.
Then, the client will connect to the server, and the instantiation of the selected class will proceed.
But for now, I’m stuck, cause the scene between the choice of character class and the playable level are differents, and so the scene switch makes me lose datas.
I’ve tried to store it in a GameInstance, but it doesn’t seems to work, because of connection to server.
I have different GameMode and PlayerController between those scenes.
What kind of object can I use to pass data trough scenes, and keep it on the client ?
So your want class selection to be like game configuration isn’t? So you need to setup like configuration and then make client inform it’s confiuration to server. Problem is currently it seems you can’t do that via Blueprint, you need C++ to do so. My guess you need to make a class with varables with Config specifier:
more specifically GlobalConfig so subclass won’t override it. You can expose those varables to blueprint but considering it implys ReadOnly you will need to put setting code in C++ too
In my game, i save the character class to game instance upon change to gameplay map, i call Client-Server function in PlayerController and set the that variable to PlayerState then replicated that to everyone, any changes in gameplay run time will apply directly to PlayerState.
That’s what I’m trying to do now, but I have issues, sometimes it is not the right class that spawns, I don’t get why
Is the GameInstance still in each client when they connect to a server ? Because the documentation says that it can be just one in the whole game.
GameInstance is different for each Game Instance that mean client and server have their own GameInstance and is independent, there’s no connection with client or server.
The point it in gamemode you must control when you spawn the character and what will be spawn, like when game mode start it will call GameMode.StartMatch() and in that it will check PlayerController.CanRestartPlayer() and call GameMode.RestartPlayer() and will get spawn class by GameMode.GetDefaultPawnClassForController()
So u can put some checking in CanRestartPlayer() to stop auto spawn from gamemode, next call Client-Server to set the class, upon class set finish, get GameMode and call RestartPlayer(), and in GetDefaultPawnClassForController() just check the class and return the correct spawn for that class.
NOTE: i put the Class.Function for you to easily find it, some function have parameter but i don’t put there.
Fixed it, there was an issue when passing a TSubclassOf in parameter (a “Class” parameter in BP) to a server function : it was reseting it. So know I pass an index of an array, and it’s ok