Cannot create widget on client

Hi All. I’m creating a health card and menu for a multiplayer test game I’m making, but every time I create the widget it returns null on the client side only, somehow. Please ask any questions you need, I’ll get back to you soon.
EDIT: In fact, nothing set in beginplay is valid for the client. Why is this?



Hi, widgets only exist locally, they never replicate. You need to create your widgets on the client where you want them shown, not on the server.

Mostly correct logic, just called from the wrong events and probably the wrong place. You shouldn’t create widgets from a server event. It just doesn’t work really like that directly…

The best place for widgets to occur reliably and locally for multiplayer and be added to local viewports is from the game instance.

So create custom events in the game instance and create your widgets in those events’ logic, much like you have already. Call those events by casting to the game instance from the player character or player controller blueprint off begin play or a triggered event from the player’s controls. Especially if it’s not anything specific or complicated.

This works on multiplayer also, but won’t yield any kind of replicated variables like scores and such from other players. It can, but it’s not that simple as a widget appearing and allowing local control. You can also call your game instance functions from the player state for more specific local control but through the player controller or player character. So that would look like from the character as a cast to your player state to an event that casts to the game instance which calls the widget creation function.

Is beginplay a server event? Even when i get the pawn’s controller it’s always null on the client’s side. Any variable set in beginplay seems to be null.

Taking another look, you’re using “GetController” in the cast. Perhaps use “GetPlayerController” instead for the object reference. So that’s likely causing your cast to fail.

Begin play isn’t a server event, but I find that in some instances the server does have some authority over it’s execution and interaction with widgets.

Are you spawning the player in the gamemode PostLogin event?

That is where once you posses the character with the passed contoller you can call a custom event on the controller (called only on client) to setup the player (do local ui widget spawning if needed etc).

1 Like

No, using Player Start objects.

So using GetPlayerController with index 0 will always return the local playercontroller?

Do not use begin play for widget construction unless you are making a single player game.

It runs begin play on client and server (separately)

On start:

  • Client → begin play → create widget from class = success

  • Server → begin play → create widget from class = always fail resulting in null return

Widgets will only work on clients so it will fail when running on rhe server.

1 Like

Yes, the GetPlayerController would be the correct node to use in this case. If you used “Create Widget” on begin play you could use “SwitchHasAuthority” and run remote into the widget and bypass the create widget node with the server pin and continue execution on the other side of the add to view port it if you couldn’t find any other way to implement it. But I wouldn’t personally run any of this on a server event.

Also you can use “GetPlayerController” on the Set Input Mode UI Only node in lieu of the player controller reference you created on your player controller cast.

Make sure that the player controller cast node is the player controller specified in the game mode as well.

If I were to personally do this widget in the player character I would set all this up in the game instance and on begin play cast to the game instance and call that function but use SwitchHasAuthority to only execute on the client with the remote and go around with the server pin to avoid the errors…

So basically, have a GameInstance event that creates the menu widget when on the client? Seems to make sense howeverr what can I do to create a widget on a listen server (non-dedicated)?

You can call those game instance functions from places like the character blueprint or the player state and others without having to run anything on the server and have them occur locally but also be happening on everyone.

If you need it to occur at specific times within gameplay like a team scoring against another team and a widget appears on everyone saying the other team scored, you can call if from the game state as a server event that multicasts to an event on the player states to the game instance in that particular situation.

If it just needs to show up when the game starts you can pretty well just cast to the game instance and run those events off begin play, but just need to make sure it’s not running on the server and throwing errors by using switch has authority and bypassing anything that’s trying to add widgets to the viewport on the server.

widget is not server, only for local player , widget is not replicated, change on server in custom event (to standart custom event).
same that 3drevan message on top reply
good luck

Thank you all for your help, however now I’m trying to figure out a “Health Card” that shows the player’s name and health above the players head. This has to be replicated, but what do I replicate? The WidgetComponent’s Widget (set using createwidget and set in a variable) or just the WidgetComponent?

just the WidgetComponent