So I’ve been wracking my brain on this one for some time but can’t find a solution.
In my setup I have various environment actors. When interacted with, they trigger the display of a HUD(UMG Widget). I’d like to be able to fire events on the server when clicking the buttons/sliders/textboxes on the widget however I don’t want to have to embed every possible UI interaction into my PlayerController or Pawn. I’d rather have all of this domain-specific logic reside in the respective environment Actor.
- I have an Actor placed in my level: BP_Terminal
- When a character walks up to a terminal and presses “Use” button the UI element is shown for that client.
- When they click the “Create Vehicle” button on the menu, a vehicle is spawned into the level
As there are many other interactions(besides “Create Vehicle”) and BP_Terminal variations, I’d rather not define all of them in 1 place.
Any help or guidance would be greatly appreciated.
I was also thinking about that, but didn’t find a good solution yet.
generally it is possible to send client->server RPCs if the local PlayerController is the owner of the actor, and it is also possible to change this owner on runtime, with the caveat that it has to be changed on the server (Owner is replicated then)
so if you would have one reliable RPC event on the playercontroller/pawn that sets its controller as the owner of the actor (via a reference) you can change the owner and afterwards the RPCs work, but the problem is the asynchronicity, since the roundtrip of setting the owner takes more time than actually executing the RPC.
I guess to solve that a possibilty would be to manage a queue on the actor clientside that executes the command as soon as it has the Owner set, or manage a callback reference and call it when the owner is set, or maybe change the owner if a player is in the immediate proximity (e.g. an overlap event that fires on the server that sets the last player that fired the event as its owner of the actor)
but yeah, those are not really good solutions but rather dirty workaround ideas, but oh well
please let me know if you came up with something else
Ye, for now I’m just going with approach of bundling all the in-game console interactions into the PlayerController and doing my best to keep them tidy… as there will be a LOT of them.
I’ll update this post if I come across a solution.