**I want do a simple multiplayer local game, ** but I don’t understand how manage the variables of the players
the game will look like this:
a lobby level
to set name, (skin color and more)
to choose if you host / join the game
then the game level
play, (interact with environement)
with the player list somewhere in the HUD
quit when finish
but I can’t pass the variable “name” from the lobby level to the game level ?
at my best try the players have the sames names
can you please show me some very simple blueprint to pass the variable to the next level,
I tried already the “game instance” blueprint, but the names still look the sames
is the CopyProperties and the OverrideWith are set correctly ? with this nodes I should be able to transfer variable to next level ? do I need to call these nodes ?
Okay just reading this off my mind but do let me know if this works for you.
Create A Name Variable in your Player State. (For Replication)
Create A variable for your Player Name in your Game Instance. (For Persistence)
Once you set the Name value via UI store it in your game instance’s variable.
when you start the Game level Override OnPostLogin method and fire a server RPC from there which will get the value from your game Instance and store it in your PlayerState.
Finally Read the name from PlayerState when you want to show them in your Game level.
I have no idea if this is right way or not, but its worth checking.
Thank you for your reply, I tried,
I understand the part 1,2,3 but I am not sure about the part 4
so I took a screenshot to show you
this is “my game mode BP”
this is not clear for me,
I understand the “game instance” is for keeping the variable through level
but how to force an update on all client “player state” ?
if you have some screenshot of simple good practice, It will be wellcome,
I need to be able to show a player list,
I need to set/show the player name/character and keep it through levels
Okay so I tried this on a dummy project and we can forego player state for this if our PlayerName is a replicated variable with OnRep Notify function inside the Character blueprint.
Character Blueprint with a OnRep Notify Variable called Name. (When ever this will change it will call a function where we get our 3D Text Component and set the Text to Player name).
When you Join or Create a Session first thing you would do is to save the name from UI text field to your Game Instance’s Player Name variable.
Once the New Level Opens and your Character spawns in you run this code on your Characters begin play:
This is not the answer to the initial post, just a different way to achieve what he wanted.
Copying player states and their variables is pretty useful especially if you do not want to clog your game instance with things that should be contained only in playerstates. While the playername could definitely be saved and loaded from this… if its not something that ends up in a savegame you’re just taking up space in the game instance for something that changes at runtime and is not saved locally. Imagine you have a “current score”. Through the level transition using copying playerstates you can keep this. In the scope of the game instance it really has no point being there because everytime you join the game current score is 0 but carries through level changes. This is exactly why you are able to copy playerstates because it makes much more sense.