x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: Not Selected
Tags:
more ▼

asked Aug 11 '14 at 05:04 PM in Using UE4

avatar image

porcelania
16 3 5 9

avatar image Vertex Soup Jun 26 '17 at 10:37 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

5 answers: sort voted first

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.

Alert Value Change Tracker Macro

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.

Example setup

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

Console output

ue_answerpic9b.png (299.2 kB)
ue_answerpic9c.png (37.0 kB)
ue_answerpic9a.png (481.9 kB)
more ▼

answered Jun 15 '17 at 09:54 PM

avatar image

BenVlodgi
2.2k 39 17 52

avatar image sarchasm Sep 22 '17 at 05:08 AM

Thanks for that.

avatar image westomopresto Mar 30 '19 at 11:09 PM

Thanks for this macro! Works wonderfully

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

alt text

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

more ▼

answered Jul 31 '17 at 09:09 PM

avatar image

Katulobotomia
6 1 2 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

alt text

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

more ▼

answered Aug 11 '14 at 05:34 PM

avatar image

TJ V ♦♦ STAFF
41k 1009 183 494

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Jun 15 '17 at 08:35 PM

avatar image

TheDarkScience
11 1 2 2

avatar image BenVlodgi Jun 15 '17 at 10:02 PM

I've supplied an answer below, hopefully will help.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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).

alt text (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 https://forums.unrealengine.com/showthread.php?20934-Create-button-for-actor-interface)

more ▼

answered Jun 25 '17 at 08:54 PM

avatar image

TheDarkScience
11 1 2 2

avatar image BenVlodgi Jun 25 '17 at 10:29 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question