# AND and OR Blueprint nodes' connections are always evaluated (no short-circuit evaluation)

**URL:** <https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079>\
**Category:** Blueprint\
**Tags:** unreal-engine, bug-report, question, Blueprint\
**Created:** [October 12, 2015, 6:13pm UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079 "2015-10-12T18:13:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![RattleSN4K3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RattleSN4K3](https://forums.unrealengine.com/u/RattleSN4K3)\
**Post date:** [October 12, 2015, 6:13pm UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/1 "2015-10-12T18:13:48Z")

</div>

**Note:** This bug was original posted in the UT forum. I was asked to report it in the engine forum (forwarding me here). I mostly kept the structure from that post and added _repro steps_.

AND and OR nodes in Blueprint behave differently to how C++ (or other common [script] language) works.

**Example code:**  
C++

```
AController* Controller = NULL;
// if (Controller && Controller->PlayerState)
if (Controller != NULL && Controller->PlayerState != NULL)
{
    // DO SOMETHING
}

```

This is a valid _if_-condition (PlayerState won’t be accessed; no crash).

UnrealScript

```
local Controller C;

C = none;
if (Controller != none && Controller.PlayerState != none)
{
    // DO SOMETHING
}

```

Similar to C++. No “accessed none” log (no crash).

Blueprint equivalent

 ![62362-bug_and_node_always_evaluated.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/a/a6ab69bd0d0fccb7fea98523561f48f51fb04c73.png)

This casues an error like this:

```
The log will contain an entry like this:
LogScript:Warning: Accessed None 'NewVar_0'
    Untitled_C /Temp/UEDPIE_0_Untitled_3.Untitled_3:PersistentLevel.Untitled_C_0
    Function /Temp/Untitled_3.Untitled_C:ExecuteUbergraph_Untitled:0074
PIE:Error: Error Accessed None 'NewVar_0' from node Branch in graph 'EventGraph' in blueprint Untitled
```

The Blueprint is trying to access the class field _PlayerState_ of “NewVar\_0” because it would process something like this (in C++):

```
AController* Controller = NULL;
bool b1 = Controller != NULL;
bool b2 = Controller->PlayerState != NULL;
if (b1 && b2)
{
    // DO SOMETHING
}

```

`Controller->PlayerState` would result into a crash (null pointer) which is catched by the Blueprint VM and reported as an error. The _and boolean node_ is using `UKismetMathLibrary::BooleanAND(bool, bool)` which takes two evaluated boolean values. This is likely the source of the _problem_.

The OR node behaves the same.

```
if (Controller != NULL || GetController(Controller)) // GetController(ByRef)
{
    // DO SOMETHING
}

```

_GetController_ would only be called if the _Controller_ variable is not already set.

For Blueprint test, I created two pure functions which both calling a unique message and return true.

![62363-bug_or_node_function.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/f/a/1fa9e14e34080ac27064140b75528fb9f4b15406.png)

![62364-bug_or_node_always_evaluated.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/1/5/615cfa2eea810c4e0dd22a4a1343644baad7afad.png)

Log:

```
LogBlueprintUserMessages: Func1 called.
LogBlueprintUserMessages: Func2 called.
```

_Func2_ is also processed even if there is no need for it. In C++ it would only process _Func1_ as it already returns true (true || ? == true).

A workaround for the AND node would be using separate Branch nodes sequentially. This is not ideal for more than 2 expressions (and you have to process/link each _false_ case).

 ![62366-bug_and_node_workaround.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/0/e30dde96e6d8bf3f90fa1483889028a2808b0955.png)

Original post in the UT forum:  
[AND and OR nodes’ connections are always evaluated (no associativity)][5]

Additional reference:  
[MSDN: Logical AND Operator: &&][6]  
[MSDN: Logical OR Operator: ||][7]

* * *

**Editor version:**  
4.8.0-2710036+++depot+UE4-UT-Releases  
UT Editor Build 2710036 (10/01/2015)

**Detailed description of the issue:**  
The associativity of the Blueprint nodes AND, OR, … are not the same like these from C++ (and other common languages). Each connected statement/node will be evaluated.

**Repro Steps:**

1. Create a new level (_File_ \> _New level_)
2. Open the level blueprint editor (Toolbar _Blueprints_ \> _Open Level Blueprint_)
3. **Create a variable** of type _Controller_ (_My Blueprint_ \> _Add New_ \> _Variable_)
4. Add an _ **Event Begin Play** _ node to the EventGraph (or use the existing greyed-out one)
5. **Connect** the above to a _ **Branch** _ node
6. **Drag** from the _Condition_ and create a _ **AND boolean** _ node.
7. Drag and **drop the new variable** (_NewVar\_0_) from the _My Blueprint_ tab into the EventGraph
8. **Drag** from that variable and create a _ **Is Valid** _ node
9. **Connect** this node to the _ **A** _ pin of the branch node.
10. **Drag** another time from the variable and create a _ **Get Player State** _ node
11. **Drag** from that _player state node_ and create another _ **IsValid** _ node
12. **Connect** that 2nd _Is Valid_ node to the _ **B** _ pin of the branch node
13. Choose to **play that level**
14. **Exit** the _Play In Editor_ session (Escape) and open the **output log** (_Window_ \> _Developer Tools_ \> _Output log_

The Level Blueprint should looks like this:

 ![62367-bug_and_node_levelblueprint.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/5/f/d5f4b5128b1313441a8e798fb9a1289f5ff3ec08.png)

The log will contain an entry like this:

```
LogScript:Warning: Accessed None 'NewVar_0'
    Untitled_C /Temp/UEDPIE_0_Untitled_3.Untitled_3:PersistentLevel.Untitled_C_0
    Function /Temp/Untitled_3.Untitled_C:ExecuteUbergraph_Untitled:0074
PIE:Error: Error Accessed None 'NewVar_0' from node Branch in graph 'EventGraph' in blueprint Untitled
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [October 13, 2015, 1:09pm UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/2 "2015-10-13T13:09:33Z")

</div>

Hey RattleSN4K3-

I was able to reproduce the behavior you mentioned and have entered a bug report (UE-22021) for investigation.

Cheers

---

<div class="post-metadata">

**Author:** ![zEh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zEh](https://forums.unrealengine.com/u/zEh)\
**Post date:** [September 17, 2017, 8:06pm UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/3 "2017-09-17T20:06:01Z")

</div>

Getting modulo by zero log spam even when checking for a positive number due to this. Will this be addressed in the near future? Branches aren’t a reasonable solution to this.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [September 18, 2017, 12:50pm UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/4 "2017-09-18T12:50:17Z")

</div>

Currently our resources are dedicated elsewhere and UE-22021 is not a priority item for us to work on. We don’t have a timeframe for when this may be addressed. Please keep in mind that with source code access, a programmer on your project can implement your own solution, and you are welcome to share that result with Epic for possible integration.

---

<div class="post-metadata">

**Author:** ![Gareth.Sumo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gareth.Sumo](https://forums.unrealengine.com/u/Gareth.Sumo)\
**Post date:** [October 6, 2017, 2:51pm UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/5 "2017-10-06T14:51:49Z")

</div>

I haven’t had the opportunity to test the generation of C++ from blueprint, and I’ll probably never have time. Do you know if the C++ generated from the blueprint takes into account that all AND paths must be run?

(What I’m trying to say is…I hope it doesn’t generate something along the lines of:  
if( FuncA() && FuncB() && FuncC() ) { DoThing(); }  
… does it?)

---

<div class="post-metadata">

**Author:** ![Dune](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dune](https://forums.unrealengine.com/u/Dune)\
**Post date:** [October 6, 2017, 3:19pm UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/6 "2017-10-06T15:19:46Z")

</div>

Just thought I’d add here that you might want to look at using validated get functions as well (Right click variable), as they can sometimes be much cleaner. Obviously doesn’t help with the actual bug issue at hand.

![215866-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/9/349731ee271c6b980228d93e2aa5837b05477de3.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [October 6, 2017, 5:17pm UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/7 "2017-10-06T17:17:59Z")

</div>

Hey Gareth-

Are you referring to nativizing the blueprint? As RattleSN4K3 mentioned, the blueprint node uses `UKismetMathLibrary::BooleanAND()` and this is how it appears in the nativized asset as well; so this behavior would also exist with nativized blueprints.

---

<div class="post-metadata">

**Author:** ![Gareth.Sumo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gareth.Sumo](https://forums.unrealengine.com/u/Gareth.Sumo)\
**Post date:** [October 9, 2017, 7:59am UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/8 "2017-10-09T07:59:12Z")

</div>

Thanks for clearing that up . I just didn’t know enough about the conversion process. Now I do. 🙂

---

<div class="post-metadata">

**Author:** ![Blindopoly](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Blindopoly](https://forums.unrealengine.com/u/Blindopoly)\
**Post date:** [September 22, 2019, 1:12am UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/9 "2019-09-22T01:12:28Z")

</div>

Any update on when UE-22021 will be fixed?

---

<div class="post-metadata">

**Author:** ![FunGames55](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fungames55/32/710746_2.png) [@FunGames55](https://forums.unrealengine.com/u/FunGames55)\
**Post date:** [July 18, 2023, 12:33am UTC](https://forums.unrealengine.com/t/and-and-or-blueprint-nodes-connections-are-always-evaluated-no-short-circuit-evaluation/335079/10 "2023-07-18T00:33:47Z")

</div>

Looking at the issue as of now, it was closed as “Won’t Fix” in August 2021 so unfortunately this remains an issue today and need to use the branch node trick to force the equivalent “short-circuited” behavior. These nodes continue to function like their “bitwise operator” equivalents.

> **[The Unreal Engine Issues and Bug Tracker](https://issues.unrealengine.com/issue/UE-22021)**
>
> Welcome to the Unreal Engine Issue and Bug Tracker. You can check the status of an issue and search for existing bugs. See latest bug fixes too.
