I’m very new to UE4, and I’ve been having a bit of trouble setting up a Blueprint that sets a name for players that are visible to other players connected to the server. Any help would be much appreciated! If you need me to be more specific please ask.
playerController has a PlayerState which has a PlayerName. you can get the name in blueprint, but you cant set the name, because SetPlayerName() isn’t exposed to blueprints.
you could make your own string variable called PlayerDisplayName, in a PlayerState blueprint, and set it to replicated or rep_notify. then the server version of your player controller can change it, using switch on authority. then other players can read it, but not change it.
Hey Omni, hopefully you’re still around. Anyways, I did what you said, but it seems if I try to grab the playername var I made in the playercontroller from a game mode (by casting to playercontroller) or if I try to bind it in a widget to some text, it returns the default value. However, if I have the playercontroller print the var, it comes out with the changes made to it elsewhere. Any idea why the game mode/widgets can’t get the new values?
This document helped me out a lot with understanding the basics of Blueprint networking.
Multiplayer in Blueprints
It sounds like you may not replicating in the right direction. Replication only flows from the server to the client(s). So to change a player name you need to set the player name on the playercontroller from the server. Basically, if you want a client to do anything that other players should see then it needs to go through the server.
You can have a playerController send its player name to the server and then replicate from there with events. The link above should explain in more detail. I hope this helps, happy coding!
Any reason SetPlayerName isn’t exposed? Seems kinda odd. Or is it just something they haven’t gotten around to yet?
You must create a profile for your player actor
- Name display
- Rare name for searching
Then save to slot
At the beginning of game or you can use a widget to load it again then show by whatever way you want.
Everyday I ask myself about other similar stuff. I guess someone in the team still thinks that blueprints is for noobs.
I have my player info saved in a struct , and i can see the names updating in my game ui when playing in editor. But when i play with standalone, with 2 computers it won’t update the name of the other player. (it will display player 1’s name twice). Any idea what im doing wrong?
I’m aware that using “get player controller” is not reccommended in a multiplayer game, but it won’t work any other way, not even by casting from the gamemode, where the controller references are…
Any help would be appreciated!
-SamuelB
Hi !
First of all, the Switch Has Authority statement literally doesn’t do anything in this that image since both cases are identical. The Authority branch should be what only the server should do, and the Remote side being what the individual client (the player) does. Takes a bit of understanding and fiddling around to actually get quite how to use authority switches. Right here you might as well just not have it be there though. ^^
Second, if this is a widget, try using Get Owning Player to fetch the player controller. Index 0 is actually the first player, which is why it shows the first player’s name for both of them.
You might also want to move some of the Player Settings variables into PlayerState because that’s tidier, but that’s not mission critical
Hey Zebezd, thanks for the reply.
Yeah i posted this pic after a long day and yes in doesn’t make much sense, more like a desperate attempt to get something working. I have experience with switch has authority, but it still manages to get my brain in a knot sometimes.
Apparently i failed to mention that the code in the pic IS in the player state blueprint, in the widget i’m trying to cast from to the player state to get the info out. Its a real pain to test this out, because it will require me to build the project and use another computer to see the results. i’ll try using the “Get owning player” when casting to myplayer state and report back.
-SamuelB
I haven’t managed to get it working yet, I Think I should be populating a horizontal box to my Scoreboard UI, i’ve only managed to display the same players name on either the client or servers UI.
I know this is really old, but it came up on my Google search so Imma update it.
There is a BP Exposed function AGameModeBase::ChangeName that does the trick!
It’s in the Game Mode Base, not in the PlayerState, very unintuitive. (Maybe to prevent people from screwing up replication for names??)
Anyway, try this: