Announcement

Collapse
No announcement yet.

[BLUEPRINT] Skip Boolean AND if one pure input is Not true

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [FEATURE REQUEST] [BLUEPRINT] Skip Boolean AND if one pure input is Not true

    Hey there.
    Following Scenario:

    You have a boolean variable and a very very very heavy pure function that also returns a boolean.
    The Boolean is set to false.
    Plug the simple boolean into the first AND input and the heavy function into the second Input.

    Execute the Graph and you'll notice that the heavy heavy function gets executed.

    An Example:Click image for larger version

Name:	Unbenannt.JPG
Views:	1
Size:	38.5 KB
ID:	1208256

    in this case the Last digit of Pi (lel) will always be calculated, even though it does not have to.

    I'm no C++ expert, but I'm sure that && won't execute anymore functions if one boolean gets false:

    Code:
    if( lightFunction() && heavyFunction())
    in this example heavyFunction won't execute if lightFunction() returns false.

    I'd like to have this in blueprints.

    The same can be done with OR. Since it will always progress if at least one is true.

    #2
    So what you are basically asking for is hort circuit evaluation.
    This has been discussed before.

    https://forums.unrealengine.com/show...=short+circuit

    One point agaist it might be that the AND operator's behaviour wiuld then depend on the pure-ness of the operands.
    Imagine at some point in your development, a pure function needs to become impure..
    In your scenario above, you could also feed the first boolean through a second branch, comparing it to a static true/false. This way you could avoid evaluation of the second operand/function...

    Comment


      #3
      What's the problem with impure?
      Impure Functions get executed, no matter if it's needed or not.

      In your scenario above, you could also feed the first boolean through a second branch, comparing it to a static true/false. This way you could avoid evaluation of the second operand/function...
      What do you mean here?

      Comment


        #4
        What's the problem with impure?
        You need to change a lot of wiring around, if you change it as an afterthought....

        What do you mean here?
        Something like this.
        Here you evaluate the second (heavy) condition only if the first one evaluates to true.
        Kind of like splitting an "if (a && b)" into a nested if-then-else-if form.
        Much cleaner and without the need to look up to what an AND node is connected to (puer/impure?) to know how it will behave.
        Attached Files
        Last edited by KVogler; 01-25-2017, 05:56 PM.

        Comment


          #5
          ^This can be a solution for some cases, but I wouldn't say this is more readable. Imagine doing multiple heavy functions. Using a Branch for each function is a waste of space and instructions.

          Comment


            #6
            Using a Branch for each function is a waste of space and instructions
            While it is indeed an additional node in the graph, a short circuit evaluating operator would do the same instructions internally.
            So instruction wise its about the same...

            Comment


              #7
              I don't see how short circuiting has anything to do with evaluating pure vs impure nodes. Perhaps I am missing something.

              Impure nodes execute when the exec wire passes through them, and any outputs effectively persist during that frame (if not longer).
              Pure nodes execute when a wire they output is needed for an input on an impure node.

              Oversimplified, sure.

              Code:
              bool SomeResult = MyImpureFunction(Params in);
              
              if (SomeResult && MyPureFunction())
              {
                  // some action
              }
              
              if(MyPureFunction() && SomeResult)
              {
                  //some other action
              }
              Yeah, you can break your code if you change a pure node to an impure node, but that is a drawback to BP, not a drawback to short circuiting. You'd run into the same problem currently. In fact, an impure node that returns a bool should return false if never called before (if everything in UE4 is zero filled), so the effect of changing a pure node to be impure should not be different just because short circuiting exists.
              They broke the signatures so I removed mine thinking it'd be awhile. The signatures work again, but I haven't redone my signature yet.

              Comment


                #8
                More lke this:

                Code:
                if (A == true)
                  {
                     if (B() == true)
                       {
                          //  heavy stuff
                       }  
                  }
                By using a second branch, you are making basicaly the pure function impure.
                I somehow prefer that (sequential evaluation) over a context dependent AND operator...

                Comment


                  #9
                  Originally posted by Raildex_ View Post
                  waste of space and instructions.
                  Create a function.

                  Comment


                    #10
                    Blueprint does need short circuit evaluation though. I find it a bit baffling that Select nodes evaluate all branches even though the condition dictates that only one branch would ever need to be.

                    Comment


                      #11
                      Yeah I agree

                      Comment


                        #12
                        Originally posted by ambershee View Post
                        Blueprint does need short circuit evaluation though. I find it a bit baffling that Select nodes evaluate all branches even though the condition dictates that only one branch would ever need to be.
                        Wow, yeah that’s new to me. I was always taught that the select node was more efficient than a branch, but based on this I guess that would be wrong probably about half the time.

                        Here I’m thinking I’m being smart avoiding branch nodes and I’m actually just wasting my time haha
                        Last edited by Nerdsbeware; 03-01-2018, 10:15 AM.

                        Comment


                          #13
                          Yeah the lack of SCE is confusing at best, harmful at worst. However it's also been discussed for a while now... Blueprints just don't do it, they evaluate all branches on everything.

                          Comment


                            #14
                            Wait, does this make the BP "AND" a "&", not a "&&", or is it just the way BP treats function nodes?
                            I'm @londonisunreal, the organiser of the London Unreal Engine Meetup group.

                            Comment


                              #15
                              Exactly, it is a & and | respectively

                              Comment

                              Working...
                              X