UnityEvents for UI updating, generic way of removing repeated calls in same frame.
I'm currently using UnityEvents to update UI elements in my cRPG.
In this example I'm using them to update the players inventory window. So whenever the data within the data structure of the inventory changes, I fire a UI event. This all works fine, but when you loot a mob and several items are placed from the mob's inventory into the players inventory, the event gets triggered several times. This is where the issue arises.
I could have quite specific code for logic checking to see if it's the last item added to the inventory and only invoke the event on the last one. This can be done my moving the invoke 'one level up' or by specific checking. But the thing is there's dozens of places in the game that can access the inventory and in quite different ways, so there would have to be special logic checking all over the place. This problem is multiplied by an order of magnitude when you consider there's many UI elements, from the character window, the quest window, the loot window, the dialog window. All of which will need quite a lot of special logic checking to reduce repeated UI update calls. This just isn't scalable.
A better solution would be that when you invoke event "ABC" 10 times within the same frame to update the toolbar, Unity only actually triggers the last one at the end of the frame. This would be a good general solution for all of my problems and would avoid writing a huge amount of logic testing code as mentioned above. Thing is AFAIK, Unity has no provision for this and I really don't want to write my own event system or use a 3rd party event system if possible.
What solutions are others using for this?
(The value of using UnityEvents over C# events over another solution is not what this post is about)
Your answer
Follow this Question
Related Questions
Unity UI create and drag with one click 0 Answers
When I duplicate my UI, navigation stops working 2 Answers
Why can't spam click on UI Image ? 0 Answers
EventSystem.current is returning null 0 Answers
Unity Event that returns mouse over 0 Answers