Trouble setting UMG elements 'Visible' for all players in Multiplayer game

*Game is currently being developed solely through Blueprints.

In my multiplayer game, once all players are connected to the server, the game travels to a new map where the game will be played. At the start, one random player is chosen as the Leader. The Leader is given access to a button on the Game HUD(UMG Widget) to start the game.

What I want to happen is that when that button is clicked, a menu in the Game HUD is set to visible for every player.

The problem is that it only works if the Server is chosen as the Leader and they press that button. Then each player’s Game HUD shows the new menu. If a Client is the Leader and they press the button, the new menu on the Game HUD only shows for them and not anyone else.

Here are some images to show how everything is currently set up at the moment:

From the Game HUD:

From the Game State:

From the Player State (The Rep Notify):

What am I doing wrong?

Thanks

It’s been a while since I did replication stuff, but the problem is probably in your widget. I don’t think calling server functions directly in widgets (even though it’s “through” the gamestate) will work.

Try creating a non-replicated custom event next to your DisplayVoteOnTeamHUDToClients event (let’s call it “DisplayVoteClicked” for this example), and have that new event call DisplayVoteOnTeamHUDtoClients.

Then have your widget button call DisplayVoteClicked.

Hey there,

the Problem is that you can’t call ServerRPCs on the GameState. The Class, which you want to call the ServerRPC on, needs to be owned by the Client. The GameState is owned by the Server.

So you need to create this ServerRPC in your PlayerController or PlayerState (although i’m not 100% sure if the PlayerState is owned by the Client).

Otherwise the ServerRPC will be dropped and never reaches the Server. Once you did this, you can then Get the GameState and iterate through the PlayerArray.

You should also consider creating the Widget in a class where you can access it. Place it, for example, directly in the PlayerState. Then you don’t need to use “GetAllWidgetsOfClass”. Always try to avoid the “GetAllXXXXOfClass” nodes (: They are performance hungry if used wrong.

That was exactly it! I moved the ServerRPC I had to the PlayerController and it worked perfectly! And yea, I’ll definitely stay away from overusing the ‘GetAllWidgetsOfClass’, good point.

Thanks a lot, much appreciated! :slight_smile:

I have a follow up question if you don’t mind. I’m sorry if this should be in it’s own post, but I feel it is a very similar issue to my original problem.

So thanks to your help, if a Client or the Server presses the button, the GameHUD Widget properly displays the new menu for all players. Great. So my new issue is what takes place on that new menu. What I want to do is create a certain number of widgets and add them to the scroll box that is on that newly visible menu.

I created the logic for that and it works just as expected. So here:

This is in my Player Controller in the event that sets the menu visible for all players. At the end of the loop through all connected players, I call PopulateChosenTeamList. I set it to Multicast and I have it loop through the players again, and depending on if a boolean is true inside each player’s PlayerState, it will create the widget I want and add it to a ScrollBox in the menu.

I want each player to see the widgets added to the menu, but the problem is that if the button is pressed from a Client, only that Client will see the added widgets. Everyone else just sees an empty ScrollBox. But if the Server presses the button, all players properly see the created widgets.

Here are two screenshots inside my game to show what I mean, if my description isn’t making sense:

When the Server player presses the button:

When a Client player presses the button:

How can I achieve the result of the Server pressing the button when the Client is the one pressing it?

Thanks