Unity Tips : InvokeRepeating()

In this video I discuss the InvokeRepeating() method that is available in Unity3D. Historically I used to write my own timers to repeatadly call a method from the Update() method of a GameObject, however, I recently discovered this gem of a method built in to Unity! Check out the video tutorial below.

Note, the video discusses the InvokeRepeating() method but I negelected to mention that InvokeRepeating() would typically only be called from the Start() method of a GameObject or similar. If you placed this within the Update() method you would cause a race condition and build up multiple calls to the same method.

Another top tip for this specific method is to also have it’s initial start time randomised if making multiple InvokeRepeating() calls within the same GameObject otherwise you could cause contention on the available CPU cycles!

Finally, don’t forget that InvokeRepeating() continues to be invoked even if a GameObject is deactivated! To stop the Invocation, use CancelInvoke(“NameOfMethod”) to cancel a specific invocation or just CancelInvoke() to stop all!

Hope you found this Unity Tip useful! Any questions, please leave in the comments below, on YouTube or via contacting me on Twitter and I’ll endeavor to assist!