Where is the loop?

I have an event timer that starts on begin play and I need to update the “falling speed” variable over a long period of time. Just changing it on tick with a delay wont work. I have to clear it and invalidate then call it again. The “falling speed” variable is set by default to 0.5 and i want it to get to 0.1 (might change it to 0.01), so i’m substracting 0.1 every 3 seconds. When reaching 0.1 the timer should still work but it should stop substracting.

In theory what I did here works… except that if i want the value to get to 0.2 then it loops and crashes (it says there is a loop when incrementing the int variable)
If I set it to 0.1 it says there is a loop in the falling object event(sometimes it says there is a loop in the input which I don’t know how that makes sense…)

UPDATE: Setting the limit to 0.15 instead of 0.1 in the branch and substracting 0.05 every 3 seconds makes it so it keeps substracting 0.05 forever and ignores the branch check to see if the falling speed is 0.15. However it’s not crashing anymore.

You might a victim of the floating point inaccuracy.

Try checking for “equal or less” on your branch, instead of “equal”.

2 Likes

I took your advice and it did something, but it’s still crashing.
It is set to substract 0.1 until it reaches 0.1 so now it got to 0.1, and then to 0.0 and then it crashed. (without <= it would crash at 0.1)
234233422

Is there another way to update the timer?

Hm, not sure if that’s the problem, but as far I see it, once your branch condition of reaching the “0.1” is met, you’re never canceling the timer again and it keep running forever (as it’s set to loop).

Not sure if that’s causing the issue - or you maybe even want it to keep running - but that’d be the next thing I’d check.

1 Like

I went ahead and pluged only a printstring node in the “fallingobject” custom event, and it still crashed. I suspect it might be something wrong with updating the timer. Does the “clear and invalidate” node not stop the timer? I connected a pause timer and it does the same. Reaches 0.1, substracts 0.1, crashes…

When the timer reaches 0.1 I still want it to work for 0.1. It’s that it should stop substracting and updating the timer after reaching 0.1.

It doesn’t (stop) and keeps running forever.
Since the Invalidate() is never called again (and even if, it’s re set-up right after) and the timer is set to loop (keep running).

1 Like

I don’t really get what you’re trying to say. The timer MUST be looping.
Let’s say the float variable gets to 0.2. It is not <= 0.1 so false on the branch, it’s set to 0.1, it clears and invalidates the 0.2 timer then calls the 0.1 timer. Next it should stop at the branch since 0.1=0.1 except it doesn’t.
I don’t see what’s wrong…

Try it like this, see whether it delivers. edited it slightly to simplify the graph

2 timers & no tick, no need to invalidate or risk memory leaks. Debugging delayed tick while comparing floats is asking for trouble, imho.


You can also do this for a slightly different behaviour, depending on whether you want to see the update immediately in this very frame:

3 Likes

Ok I think I got it now. So I’m “creating” new timers for each value of the variable and the old ones are still working. Okay.
How do I stop the “old” timers?
I tried using pause timer by handle and move the clear and invalidate before substracting and it’s the same:

Yeah… your graph works really well. I did not think of using a timer to update another timer.
Thanks a lot!

1 Like