Making game events update the UI
I have my score calculations in the GameMode. And I want to update the UI of all the players with the current score. But I can't figure out how to get a list of all the player controllers, to call a function/event on them, which would be passed to their UI widget with the updated score. The score calculation is behind HasAuthority() so that clients can't cheat, so even if I had all the PlayerControllers would a function call end up being an RPC?
What is the correct way to do an event based update from the GameMode/GameState/Level down to the UI attached to a PlayerController?
I'm trying to avoid polling the GameMode in the UI's Tick() to fetch the score, and instead only updating the text when the score changes. Because lots of things using Tick() will slow your game down, and I've noticed that setting text is rather expensive because it calculates the width of all the characters etc...
My understanding of the intended workflow with UI/UMG is that you bind attributes such as the score/text to functions that are responsible for fetching the updated value, and those functions are called whenever the underlying UI framework decides that they should be polled. Then you simply replicate the scores over the network whenever they are changed, and your bound function retrieves that value for the UI.
Having said that, if you want to do things in a more event-driven way I'd investigate a replicated variable with a ReplicatedUsing function which gets executed when an updated value is replicated over the network - that OnRep function can then 'push' the updated variable into your widget class. There's an example with a helpful comment from an Epic Dev on this forum thread.
answered Nov 17 '14 at 07:46 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here