- Home /
What are the benefits of using Invoke over Coroutine or vice versa?
Is there any performance difference between the two? I really don't understand the difference of using the two except that a coroutine has more flexibility for changing out yield return types and such. While a invoke maybe simpler for just a simple time delay before execution.
InvokeRepeating() continues to run when a game object is disabled (may be a positive or a negative). Also awhile back I saw a post that indicated that InvokeRepeating() was slightly faster.
Answer by Statement · Dec 23, 2013 at 07:23 PM
The benefit as I see it: Readability.
Use what makes most sense for your problem. You want to invoke something after x seconds?
Use Invoke.
You want to design sequential or wait-timed code flow?
Use Coroutines.
You can use Coroutines where you could use Invoke. I can't really say one is much better than the other. Use your judgement and try to decide which method makes sense.
Using chained Invokes to do sequential code flow would be very ugly, so I would recommend against that.
Also a little nugget of hidden info I learned from trial and error (if it still is applicable, it may have changed since the past major version of Unity):
In UnityScript, the method that is Invoked can be a coroutine.
In C#, the method that is Invoked can't be a coroutine.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
WorldToScreenPoint in Update/OnGUI: Bad Performance 1 Answer
Best Practice For Shader Complexity + IOS 1 Answer
Total memory allocated increases indefinately from .80GB untill crash 3 Answers
Performance when having Update functions in many gameObjects ? 1 Answer