Widget not Adding to Viewport if Multiplayer

Hello,

I am trying to set up viewports for multiplayer. I have a fully functioning UI that works perfectly on Singleplayer. However, if I switch to multiplayer (either LAN or Dedicated), the UI is never added to the actual viewport. I have the Authority and Remote Role checks and the events do successfully fire only on machines where there is proper control. The Widgets are successfully created, they return true, have the correctly assigned controllers. However, they never add to viewport on multiplayer nor does the construct/tick event run (I understand that this is because widgets that are not viewable are not allowed to execute anything).

How can I fix this?

Hi!

Two possible reasons:

Widgets / UI are owned by the player controller.
In multiplayer the server takes the clients and “travels” with them to a new level. After a new player joined, the server creates a new player controller for each client. In this process the player controllers get reset.
Previously added widgets are not in the viewport anymore.
So make sure you create widgets and add them to the viewport AFTER all clients connected to the server and traveled to the multiplayer map.

Or:
The assigned controller should be 0 in networked multiplayer. If you assigned 0,1,2… that is only for local couch multiplayer on the same machine with several input devices.

Hope this helps.
Cheers!

I spawn them from the player controller class itself. I just found out that the widgets are getting added server-side. If I play on Lan, only the Server gets the UIs added to viewport even though the events trigger only on client-based elements.

They do show up okay for me in pie with 2 windows.

This is my setup, and these are the results.

the Camera adds and sets view successfully. On clients. What am I doing wrong?

284589-ue4spawnwidget2.png

Is that branch getting true?
I think it could be the sequence that messes it up, try swapping them over or remove it all together.

It only prints those values if it returns true, and the print includes the context where it’s printing. As in image 2, only the clients are generating prints.

Removing that altogether doesn’t change anything; only more UIs spawn on the Server.

This function is executed from BeginPlay within the player controller. I event tested to execute the event from an input-based event and nothing happens either (by that I mean that controller doesn’t set new view target nor UI gets added to the viewport).

For the actual answer, using IsLocalController() will do the trick.

In my case, the problem was that I was initiating the Widget’s functionality based on an interface. However, I forgot that the object of that interface only truly existed on server and thus client widgets were never initialized.

1 Like

You, sir, really helped me out today!