Random Integer branch bug not working?

It’s working fine, but this is a common misunderstanding of how pure functions work in Blueprint.

There are two ways to execute functions in Blueprint

  • Pure functions (they do not have the white execution pins, in your example, RandomInteger)

  • “Normal”/Impure functions with execution pins.

When you execute a normal function, the return values will be cached and can be re-used and will stay the same value until the function is executed again via its execution pin.

Pure functions (GetActorLocation, RandomInteger, etc) are executed every time something “pulls” from its return value. You basically have to trace the execution backwards. In your example, the Branch node sees that it has to get a boolean value from the GreaterThan node its connected to. The GreaterThan node sees it needs an Integer value from the RandomInteger node its connected to, and so the RandomInteger node/function is executed.

What is happening in your example is that RandomInteger rolls the dice once because your Branch node is asking for a number from it, and then it rolls the dice again because your Print nodes are also pulling from it and so it gives your Print nodes a different value.

The solution is to save the RandomInteger as a variable, and then print that variable instead of connecting multiple things to the RandomInteger node.