Bug - NAND with 3+ inputs gives incorrect result

Summary

Boolean NAND node appears broken in blueprints in all versions of Unreal Engine 4, UE5, and UEFN (presumably even predating 2017)

  1. :point_right: 2017 FORUM POST: Bug: NAND gate inaccurate if more than 2 inputs
  2. :point_right: 2024 FORUM POST: Is NAND gate bugged?

Steps to Reproduce

  1. In any blueprint, create a node for a boolean NAND operation.
  2. Click ‘add pin’ to add a third input to the node.
  3. Checkmark two of the three inputs and leave one of three inputs UNCHECKED.
  4. Observe how the NAND node will output FALSE (which is erroneous)

Expected Result

In the field of digital logic, a NAND gate is, quite simply:
an AND gate with a trailing NOT gate hooked to its output.
Therefore, the only instance in which a NAND operation should output ‘false’ is when ALL of its inputs are set to true:
NAND (F, F, F) = true
NAND (F, F, T) = true
NAND (F, T, F) = true
NAND (F, T, T) = true
NAND (T, F, F) = true
NAND (T, F, T) = true
NAND (T, T, F) = true
NAND (T, T, T) = FALSE
(You can see the above behavior by hooking up a boolean ‘NOT’ node to the output of a 3-input boolean ‘AND’ node.)

Observed Result

NAND (F, F, F) = true
NAND (F, F, T) = FALSE (erroneous)
NAND (F, T, F) = true
NAND (F, T, T) = FALSE (erroneous)
NAND (T, F, F) = true
NAND (T, F, T) = FALSE (erroneous)
NAND (T, T, F) = true
NAND (T, T, T) = TRUE (erroneous)

Platform(s)

Reproduced in Unreal Engine 5.3.2,
but presumed to affect all versions of Unreal Engine 5, Unreal Engine 4, and UEFN.

C:\Program Files\Epic Games\UE_5.5\Engine\Source\Runtime\Engine\Classes\Kismet\KismetMathLibrary.inl

lines 39-43

KISMET_MATH_FORCEINLINE
bool UKismetMathLibrary::BooleanNAND(bool A, bool B)
{
	return !(A && B);
}

maybe change the BooleanNAND on source to something like this? to allow more than 2 inputs?

KISMET_MATH_FORCEINLINE
bool UKismetMathLibrary::BooleanNAND(const TArray<bool>& Inputs)
{
    for (bool Input : Inputs)
    {
        if (!Input)
        {
            return true; // If any input is false, return true (NAND logic).
        }
    }
    return false; // If all inputs are true, return false.
}

EDIT:
the blueprint comment does say “returns the logical NAND of two values”


so is the real bug that there is a “add pin” + on the node?

EDIT2:
i did not test, but: all the kismet library boolean functions have only 2 inputs, so it is very possible that when there is more than 2 inputs on other boolean blueprint nodes, they might be bugged aswell.

1 Like