(Multiplayer)How Can I display Player Names in my game hud?

I’ve been having issues with this seemingly simple task for sometime now. I have my game set up so when the game starts you setup a player profile (with a name and avatar) the information is saved into a struct. I’m able to populate and display the names in my lobby widget, but have been unable to get it to work in my gamehud (hud which displays other stuff like score and a timer). I’ve managed to get the host name displayed, or the clients named displayed for each player, but it won’t get the name of both players. I’ve tried using a custom playerstate to display the names, but with no success. How can I get the correct players information and display it on my game UI?

My project is based of this multiplayer tutorial:
https://docs.unrealengine.com/latest/INT/Videos/PLZlv_N0_O1gYqSlbGQVKsRg6fpxWndZqZ/_-yal2ufWP8/index.html

at 15:20 you can see how the player names are populated in the lobby menu, i would like to achieve the same but inside a horizontal box and in another level.

Any help would be appreciated

-SamuelB

anyone have experience with this?

I didn’t watch that tutorial but you can fix it this way:

  1. Foreach player find where the variables you need are.

  2. Find a way to pass them into an array into the Game Mode (that is server side only).

  3. Go in your hud class, use GetGameMode node, cast it to your current game mode class and get the array.

  4. Use the array to populate your list.

If you didn’t understand something or it’s not working reply this message

Hey thanks for the answer! For some reason I didn’t get a notify in my email for your answer, so I’m seeing it now after I’ve already fixed it :D. I managed to get the player names displayed correctly with a similar method. In the video I linked there are a couple of events that are created in the lobbyPC and lobbyGM, that I used as a basis to display the names. I’ll post an in depth answer soon, thanks again for taking the time to answer =).

  • SamuelB

So I’ve managed to get the names to display correctly. There were several issues that were preventing me from getting it to work correctly. Firstly I’m not 100% sure if this was an issue ,but I was trying to populate the names into a widget that was created in my player character blueprint (i’m dumb). It should be setup in the playercontroller and called there or in the game mode during initialization.

As I said in a comment to the other answer, I based the logic on the events implemented in the lobbypc and lobbygm, another key factor was how to populate the horizontal box in the widget correctly. Here are some screenshots of events i used.

events in my game hud for populating the horizontal box:

events in my gamemode bp, keeping track of the connected players and populating the info into arrays to pass to the gamplayPC blueprint event.

Adding the info and calling the events made in the widget.

Setting up the widget in the player controller blueprint and calling everyone update after respawn event.

The most annoying and time consuming part of the whole process was testing if it works. The only way you can test if its working is to build the project and copy it to another pc. If you try in editor or on the same computer the game will use the same player info, displaying the same name twice.

-Samuelb

1 Like