Is there any way to fire an event on boolean value change?

I got a bool in my blueprint, I want to fire an event once the bool value changes. Is there anyway to create such an event? As I got several nodes in different place, all could change the bool value, so may be this kind of event could make BP looks pretty.

Hi porcelania,

You can use a Custom Event node and call it using a Remote Event. Take a look at the screenshot below, this is a simple example of a Custom Event that is only activated when the bool is true.

Also take a look at our documentation on Custom Events.

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Events/Custom/index.html

Thanks, TJ

Yes, if you put a call to the to randomize function in the constructor. Then if you change the public property in the editor, then the constructor will be called again, thus calling your function.

If it is only for ease of use in editor you can use C++ PostEditChangeProperty function on your class, define your event you would like to be called and let it trigger when your bool was changed. I’m not sure how to do it in BP but through C++ it is pretty straightforward process. Then you extend your event in BP to do what you need.

1 Like

By far the easiest and shortest way to achieve this is to add a XOR on the part of code where you evaluate your new boolean value. You don’t need any extra variables or functions…just check if the new value differs from the one already stored in your boolean variable.

http://i.imgur.com/gVRaQXA.jpg

The SET itself and any code following it will only be executed ONCE when there is a change.

I have basically the same question, is it possible to call an Event whenever a boolean property of an instance placed in the world is changed? Basically binding a boolean to an event that runs everytime it changes.

i know it would be possible with c++ code (getter setter of the property) but i’m wondering if you could achieve this using Blueprints too.

Because i would like to call one or more events when the a Boolean changes, that way i could place a instance into the world and change the values of aBP instance from the editor without having to change the defaults of every BP and recompile everytime only because i wanted to test or see something.

To fire an event when a value has changed, you have to know the old value, and check to see if it has changed.

To simplify doing this over and over I have a macro that I use to track if a value has changed.

This macro saves the setup value. Then every time you call the check, it will fire wither Value Not Changed or Value Changed, if Value has changed, you can look at the Old Value and New Value parameters.

To use this, I recommend calling the Setup on BeginPlay, and call Check Change on Tick. Here is an example I have setup. With this setup, no matter who changes the score, the next tick will detect the change and fire off the Print String. In my normal case, it would be calling an EventDispatcher with the value change parameters.

Here is what is seen in the console, when I update the score a couple times.

200669-ue_answerpic9c.png

2 Likes

Thanks for the anser but i meant more in the editor not while playing and the begin play event fires once the game started.
Wanted to know if its possible to fire an event or bind a event that can fire while in Editor, I’ve seen theres a experimental function of the editor where you could have a button in the default properties that can be pressed while in Editor (not while starting or playing the game).

201281-randomizeeditorbutton.png

(This isn’t taken from me, made a quick search for an example picture will link the original link of the thread below)

Haven’t looked too much into it yet (because haven’t much free time) but for my understanding this would fire an event from the blueprint while you are still in Editor and not playing, so with that you could easily change a boolean with a not node which inverts the boolean afterwards check the value of the boolean with a branch

(link of the picture [Create button for actor interface - Blueprint Visual Scripting - Unreal Engine Forums][2])

Thanks for that.

Thanks for this macro! Works wonderfully

Try using https://blueprintue.com/ to share it

Copy/Paste version added on blueprintue.com

1 Like

Done! Much better indeed.