Download

Connected player Widget

How can i do to add this widget to all “ingamehuds” ? i have the widget, i set “the player name” but i cant add to all “ingamehuds”, i try in the player controller, maybe isent the correct place to do?

pd : this widget showed in all games when a new player is connected in the sesion “player name has connected to the game”

You need a list of all your connected players. Create a custom event on your **pawn **or player controller (wherever your **HUD **is) and set the custom event’s **Replicates **property to “Run on Owning Client”. Create an input on the custom event to expect a Name, Text or String. When a player connects, iterate through all of your connected players and call this new custom event and pass the name of the connected player.

Your custom event should call a function on the HUD that adds a “[player] has connected” message.

Example:

My Player Pawn has an event called CL_NewPlayerConnected that expects a Name value (my combat HUD is on my Pawn in this case).

The game should be building a list of all of your connected players. GM_Game is my main Game Mode. The **Event OnPostLogin **triggers anytime a new player connects to the **Level **that is using this Game Mode. This event gives you a controller - you can cast it to whatever your player controller is. Mine is called PC_Game. My player controller has a Name variable that stores the name of the player and I pass it to a function called New Player Connected.

IMPORTANT: Make sure you use a function that way anytime a new player logs in, it calls a new “instance” of this function so-to-speak and passes it it’s own **Name **value. If you don’t create a function here and do a ForEachLoop right off of the event, you’ll run into issues when 2 players connect at the same time and the loop hasn’t finished running the code on all HUD’s for the previous player. By separating it into a function, this event runs, gets the name, passes it to a that function and moves on. If another player connects at the same exact time, it calls the function again with a new value, but now you’ll have 2 functions potentially running at the same time to update all HUD’s but each of them has a different Name value so everything will work as expected :smiley:

The function iterates through all your Players and calls that **CL_NewPlayerConnected **custom event. Remember, this Players array that I have is a list of all of my Pawns.

Hope this helps :slight_smile:

Thank you for taking the time to answer me and explain in detail, try to reproduce the idea you gave me in my project but it does not show any warning in the huds, how can I set the variable “players”? at what time?

Sorry @mehack, just saw your question now.

So Players can be set a number of ways. You can either wait X amount of time in your game mode and then Get All Actors of Class (whatever your pawn is) - **this is not recommended **but it’s a quick and dirty way to test things

OR

  1. Create an event in your Game Mode called RegisterPawn that has a **Pawn **as an input.

  2. In your pawn class, whenever you are done initializing (Event Begin Play), on the server side (Switch has Authority > Authority) you can get the Game Mode and call the RegisterPawn event and pass “Self” as the input.

  3. On your Game Mode, the **RegisterPawn **simply takes that input and adds it to an array called Players.

So you’re basically creating like a “sign up” sheet when Pawns are born. Instead of your **Game Mode **going and getting all the Pawns, as the Pawn is initialized…

Pawn says: “Hey Game Mode, I’m here now!”

Game Mode says: “Ok, I’ve got you in my list now.”

Does that make sense?