Support reactive variable events?
Adding "event tick" in a lot of places just to pick up the fact that a variable of some sort occasionally changes value is not very efficient.
It is possible to insulate a variable and only allow updates through function calls, and then I can do "other things" in response to the variable changing value. However, this generally happens synchronously, unless I define my own event type, and post it to myself (or other listeners) within the "change variable" function. This is a lot of boilerplate, which for Blueprints is annoying both in the amount of clicking needed, and in the screen space it takes.
It would be swell if I could tag a variable with an event, such that if this variable changes value, that event is fired, for example at the conclusion of the tick during which the variable changed. (This will also coalesce multiple changes that happen in the same tick.) This would let me write more efficient code, that was purely reactive, without adding a mess of wiring and nodes and functions for each little variable I may want to pay attention to.
I have a feeling that adding this feature, while not zero work, shouldn't be TOO much work, and I think it would significantly move the needle on how efficient, easy, and slick development with Blueprints can be. (Something like it is already supported for network events, too, with OnRep)
Change your variable's replication to RepNotify. This creates a function automatically called OnRep_Variable that is called every time your variable is changed. I would say just make your own named function for it, but if you use it already at too many places than I'd suggest this solution.
answered Jul 23 '16 at 03:08 PM
Events only give you illusion of asynchronous, in reality they still execute by main thread. General practice in C++ is to make a varbales private or protected and strictly use Get and Set functions, if you look on API this is convention that UE4 follows.
answered Jul 23 '16 at 06:58 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here