With Unreal Engine 4.7.5, I was trying to select two actors from an array and do different things with them including branch on conditions on them.
I selected the array indices with two nodes of “Random Integer In Range”… People used to this will probably already know the frustrating hours trying to find out what’s the problem with all sort of weird behaviour induced just by this sentence.
Here’s a testcase I created for this:
I was expecting, that the return value would be constant, and all prints should show the same value. I thought, OK, maybe when I kinda directly access the return value, the dice might be thrown each time… but if I already do something more complex, it will certainly keep the same at some point, I thought and built another testcase:
Even with this setup, my expectations were not met at all, as you can see by the X coordinate of “the” selected actor. But if you think about, what one would expect of a “Random Integer In Range”-node inside a loop, it makes a bit of sense. If the return value was constant, the loop would always use the same random value. But in my opinion, the random functions should get optional Exec sockets (or be duplicated with variants with Exec sockets), because these nodes have side-effects (change the random seed). Or at least the Blueprint API reference on the according functions should include a big hint about this topic.
Currently an easy solution for this is, promoting the return value to a variable and directly using it:
I hope, if anybody gets into the same frustrating situation, he will quickly find this post and be saved