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)

Yes, I need such kind of node as well. I want an event fire once a boolean value change. Because I put this bool in a class BP and referenced it in many other class BP, I got several “place” which would change this bool vaule. If I need to fire an event when this bool value change I need to put an event node on each “place”. If I have a node called “fire on value change”, then I only need to put one node on on BP. Or I have to use per tick event to detect bool change.

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.

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.

Exact answer I was lookin for, with enough detail to make it useful this time!!! This gets asked a lot but no other answer I could find explained wtf “RepNotify” was or how to setup/use it to us noobs. much thanks man

While I appreciate the answer, this doesn’t work for “local only” variables. If I can send the variable from the server, then RepNotify is great!

Asynchronous is not the same as parallel execution. NodeJS is entirely single threaded yet asynchronous programming is the go-to on there for precisely that reason.