Name of a player from Lobby to Game Level

Hello,

**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

Thank you a lot

these 3 picture explain what I try to do



here in lobby I try to save the name in the player states

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 ?

finally I try to get the variable name from the player states, and display it above the player

Thank you

up please

Okay just reading this off my mind but do let me know if this works for you.

  1. Create A Name Variable in your Player State. (For Replication)
  2. Create A variable for your Player Name in your Game Instance. (For Persistence)
  3. Once you set the Name value via UI store it in your game instance’s variable.
  4. 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.

Are you ensuring you’re using seamless travel? Do you have a transition level setup?

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”

and this image below is my result, the server got the name but not the client.
you can also see on the top left of this picture a player list…

this player list get the name and the ID from the “game state base”,
but from the “player state” it display the same name

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

Thank you

there are no transition between 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.

Here is everything you need:

  1. Game Instance with a variable of Player Name.
  2. 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).
  3. 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:

Notice the Player Name from Game Instance is not replicated, the one that exists in your Character class is Replicated with Rep Notify function.

this way I didn’t have to touch OnPostLogin or PlayerState, though you can store your names in Player state instead of Character BPs if you want.

it work thank you a lot !

No worries, mark the post as resolved so in future people can jump to the exact reply containing the solution.

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.

I Still get some issue here when Character spawn into Level Map the ‘Player Name’ of Server its not change but the Client changed. How I fix it?