Setting Timeline Length Problem

Hello,

I am using a Timeline to create a period of delay before performing another action. In this specific case its a launch delay before an enemy ship is spawned.

I’ve run into something that doesn’t make any sense and I’m hoping someone can shed some light on it for me.

I have two variables which I use as the min and max delay.
I then use RandomFloatInRange to return a value between the min/max.
I then set the length of the Timeline using SetTimelineLength, hooking up a reference to the Timeline variable and also the returned value from the RandomFloatInRange.

I then call PlayAtStart.

Whilst I was getting some randomness, it didn’t feel right. I added a series of Print nodes, one in the function I have which returns the random delay, and another after I have set the timeline length, it gets the timeline length after its been set.

I’m getting very weird results. For example, I may have created a random value of 2.888883 but then the get length might output at 8.94444 - there’s nothing obvious about what’s going on here at all.

The behaviour I expected was, passing in a value of say 5, and then when I get the length of the timeline, I would expect to see that value of 5.

Have I missed something here?

Happy to share a screenshot of my nodes, but its fairly straight forward, pretty simple, I’m not doing anything clever (clearly!) with this…

Stuck :frowning:

I moved the print statement out of the function that was creating the random delay, and placed it directly outside of that function. Now both the generated value, and the set value of the timeline report to be the same thing.

Very confused… but it seems to be working… I can’t think of a reason why a print statement within a function, as the last step before the return node, would produce a different value than that being generated?!

Judging by the description, it’s this:

Store the result in a variable, top example. The bottom one will generate 2 different results.

Thanks for the reply @everynone and WOAH!

Is that because RandomFloatInRange is executed once for each of those print statements?

I assumed more of a linear effect, e.g. “return value” of RandomFloatInRange happens once, and then both of those print statements would return to the same value.

Is that because RandomFloatInRange is
executed once for each of those print
statements?

Precisely! It evaluates every time it’s accessed.


There are more gotchas like this in the engine, unfortunately. The way Select node works and the whole short-circuit evaluation shebang.

And it’s not going to change - Won’t Fix:

Oooof!

Well thanks for the heads up and the links, will check them now… at least now if I come up against any weirdness like this again I have some form of reference to think back too.

Much appreciated :slight_smile: