- Home /
How efficient is Update() vs Update via a Manager vs Coroutines for iOS Deployment?
HI All
I am trying to decide whether I should update multiple entities (such as enemies) in game each in their own Update() method, or whether it is worth having a master update against which each entity is registered and for the master update to update each entity in its update, or whether each entity should run its own Coroutine to do updating, perhaps only for certain things such as moving from one point to another - presumably running a Coroutine for every frame would be no less efficient than running Update()? Perhaps easier to yield and continue however?
I'm developing for iOS so trying to use the best approach now rather than have to retrofit later. Currently I have a mix of Update(), FixedUpdate() and Coroutines.
Interested to hear what other people are doing and whether they've seen or know about particular performance considerations between these options or if anyone who knows the deeper workings can enlighten me?
Thanks a lot!
Answer by Eric5h5 · Sep 26, 2011 at 05:31 PM
Update is for things that happen every single frame. FixedUpdate is for physics. Coroutines are for everything else (InvokeRepeating can also be useful). Whether you should have a "master Update" depends on the number of objects; if it's just a few, it's not worth the extra development time.
$$anonymous$$y current approach is to use a Coroutine WaitForFixedUpdate() to move my tile-based controllers around the game ins$$anonymous$$d of always trying to do work in FixedUpdate() - it feels like it ought to be moe efficient as nothing happens unless it should.
I've recently started using AngryAnts behave library so the typical pattern there is to Start as a Coroutine, and yield for several frames using WaitForSeconds(), so in many respects the updating process for enemies at least is out of my hands while ever I stick with that pattern.
Sounds like Update() is fine for a few things as you say but as the number increases something else has the potential to be more efficient. Sounds like the gain in efficiency will be directly related to the quantity of the thing involved or the amount of work saved?
Answer by IndieForger · Feb 17, 2013 at 04:24 AM
I don't have experience with IOS but I run few tests regarding particle system and coroutines vs updates and it always depends on the case. You can find my observations here
I don't see any benchmarks or observations - it looks like conjecture, did you compare each method and capture metrics on efficiency?