Create Widget For Everyone (solved)

Hi!

So I have 1 Host and 1 Client. Everyone has a widget with a button. If host presses the button, then everyone (host and client) should get the same widget.

I have a GameMode, GameState, PlayerState and PlayerContoller.

So what i tried is: when anyone clicks the button then he sends an interface event to GameMode that would execute an event that sends a message to all PlayerControllers (in foreach loop) to create a widget. But it doesnt work.

Button:
image

GameMode:

Controller:

I store players in an array of PlayerController. Whenever OnPostLogin event fires, I add received PlayerController to that array. I use this array in that foreach loop.

So I tried this on GameMode - widget appears only on host, not on both.

This widget creates only if the host clicks the button, but not if the client (which is what I want, but I want both to see the widget). I guess thats because I click the button on host (host == server, I use listen server), so that executes only on server. So I have to replicate that maybe… Or multicast, I tried multicast it didnt work.

Please, i need help

Or maybe I have to replicate the Players Array?

First thing to check:
Are you sure the “host” is the actual “server authority?”
Specifically, “Create Widget for All” should be sent to run on the server.

Also, your “create widget” node doesn’t actually have a widget blueprint selected, but I’m assuming that’s just for illustration purposes. But on the off chance that that’s the problem, fix that, too :slight_smile:

I almost 100% sure the “host” has server authority. Idk how to check it correctly.

Create Widget for All, I run now on server, no difference.

Hi, couple of things

when anyone clicks the button then he sends an interface event to GameMode

(-) GameMode only exists on the server, clients can never access it, it does not exist there. Therefore what you’ve shown in your image above will not execute if a client clicks the button, since GetGameMode will be None for the clients. Of course that also means that stuff like Multicast will only execute on the server.

(-) Widgets only exist locally, they never replicate. So the spawn logic needs to happen locally on the client where you want to spawn it, not on the server. Of course that then also means that you can’t (meaningfully) have any replicating variables / RPCs inside widgets.

(-) The only controller that exists on a client is the playercontroller of that client. All other playercontroller/AI controller do not exist on clients, only the server has them all. That then means that if even if the PlayerArray would replicate (which it can’t since you have that in the GameMode), it won’t be of any use since those other player controller will be nullptr on the other clients.

I guess thats because I click the button on host (host == server, I use listen server), so that executes only on server. So I have to replicate that maybe

Yes that is right, you need to replicate that to the clients and then spawn the widget there.

So in your logic above, from the CreateWidget event call a RunOnOwningClient event and from there construct the widget and add it to the viewport. And you need to specify a class for the widget, currently you don’t have specified any.

1 Like

Thank you, very helpful!
I did it btw