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.
Ah, that's surprising. Thank you.
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.
Can I ask where you have this information from?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
4 People are following this question.
convert timer from update() to coroutine or invokerepeating
Few versus many Update() routines?
What is better: Set a animator variable each frame or use a if to check if need?
How do I get my game to run faster?
Mobile physics optimizations and Mesh Colliders