Formula does not cache input values

Personuo 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 4

When I initialized the unit HP in batches, I found the problem and the Formula did not work correctly.
Like this.

Then I tried it for a long time, because I used Gaussian random, so the situation less than 1 rarely occurs, I always thought it was my Gaussian random problem, then I tried various methods and found the solution, like this

When I use negative numbers all at all, Formula looks like it works like this

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):




Working on Fix

Hi Personuo!

This is an interesting issue. Basically, what you see happening is that the formula will fetch a twice in your initial setup: once to evaluate the condition, and the second time to return the value. So it can happen that the first time, the value was negative, but not the second, or the other way around.

I can look into ways of caching this, hopefully without breaking existing behaviour. In the mean time, you found the right solution: by passing the flow into Random, it caches its output value after having been entered. Another approach would be to use the Cache node after Random to be very explicit about what it's doing.

Fixed in Next Version

Fixed for v1.4.0f11.