InvokeRepeating does not work as expected on iOS with low targetFramerate

Unity 2108.4.27, iOS 14

Set Application.targetFramerate = 1, then call InvokeRepeating(“Foo”, 60, 60). The Foo function won’t be called with 1 minute interval. In fact, I’ve never seen a call until I reset the targetFramerate to 60.

This only occurs on iOS device. It works fine in editor.

I tried to use coroutine. It does not work on iOS device either.

I recommend staying away from black boxes like Invoke and InvokeRepeating that really provide zero actual value. When they fail, there’s absolutely NOTHING you can do about them, as you can see here.

Just do it yourself: keep your own timer, count it up with Time.deltaTime each frame, when it crosses the threshold you want, do the action, reset the timer, continue.

That way the instant there is a problem, you can start printing out timer values, reason about the problem, and have a fighting chance of fixing it, none of which you can do with InvokeRepeating.

Thanks for your reply. Indeed, I workaround this with Update and a counter/timer.

There is one more problem with Time.deltaTime. When targetFramerate is set to 1.0, Time.deltaTime is capped to 0.1. I have to use Time.unscaledDeltaTime as a workaround. This even happens in editor.

1 Like

I think this might be tripping you up perhaps?

On my Unity that comes set to 0.333 by default.

6464806--725149--Screen Shot 2020-10-27 at 7.30.45 PM.png

Either way, if doing it with unscaled time works, that’s probably future-safest!

1 Like

I don’t know this option before. That makes sense now. The InvokeRepeating problem is much likely caused by this too.

Thanks a lot