- Home /
Are there any performance differences between a timer and using Invoke?
Quite straight forward; I often find it easier to use Invoke whenever I need something to happen based on a specific delay. I find this easier then setting up a traditional timer using floats, bools and Time.time.
Is there any performance differences between the two approaches? I haven't found any slow down from using Invoke but I would appreciate some more knowledgeable advice about these two approaches, so I don't have to rewrite my code later down the track.
I believe invoke is slower, but in any case, for delaying execution, have you considered using coroutines and yield return new WaitForSeconds
? - in my games I have many things that require delayed execution, and never used invoke or cumbersome timer logic.
By "slower" is it significant, because I use Invoke quite often in my scripts so should I be concerned for optimization reasons?
In Js WaitForSeconds is definitely straight forward to set up, but in C# (which is what I use predo$$anonymous$$antly) it takes a few extra lines of code, I think about as many as setting up a manual timer which is why I just use Invoke because it's just one line.
Well, if you are using it a lot, then yes, it may be significant. Whether it is significant enough to justify a change will depend on your specific uses and frequency of execution.
Your answer
Follow this Question
Related Questions
How Can I Reduce Build Time for Script-Heavy Projects? 2 Answers
Should i bake the skinned mesh? 1 Answer
Why did my render time increase after lowering the vertex count? 2 Answers
Whats an efficient method for drawing hundreds of Health Bars etc. over units for an RTS? 2 Answers
Performance of game depends on computer's power option? 0 Answers