- Home /
Any costs I should know about associated with InvokeRepeating?
Is there any real overhead associated with InvokeRepeating? I have something that runs in Update that I can easily get away with updating, say, 30 times per second instead of every single frame (which in most scenarios means it's being run about 150 times per second; which seems like I have a lot of excess frames to work with, but I'm making a physics game so I need to squeeze out as much performance as possible).
Keep in mind this is for simple "update counter text" type things, so the function itself that is being repeated isn't heavy, but I'm trying to maximize speed and wondering if InvokeRepeating has any inherent performance hits.
If there aren't any problems, I'm going to happily start migrating a bunch of things out of Update, where it seems wasteful to do them every single frame when there's no need.
Also, is there any difference between using coroutines and InvokeRepeating in terms of performance?
Answer by Eric5h5 · Nov 28, 2011 at 07:48 PM
In terms of overhead, the order (from most to least) is Update, coroutines, then InvokeRepeating.
Specifically, InvokeRepeating is about twice as efficient as a coroutine when it repeats, but the "wait" part for both has no appreciable overhead (as opposed to Update, which always has overhead).
Really useful to know. I've been using coroutines a lot but end up yielding a new WaitForSeconds() each time and I think InvokeRepeating() feels like a better fit in these cases.
Your answer
Follow this Question
Related Questions
convert timer from update() to coroutine or invokerepeating 0 Answers
Update with bool flag or script enabled/disabled? 2 Answers
How do I get my game to run faster? 4 Answers
InvokeRepeating VS Coroutines [Performance] 1 Answer
Is Instantiating bullets/many objects always bad for performance? 1 Answer