Multiple updates or an update for multiple objects? (Performance-wise)
So, I was wondering, if I need a lot of objects to do something, like for example; multiple tiles moving (it's a 2d game), would it be better to have them each have their own update code, or should I group all of them into a parent and then add an update only to the parent with a foreach child loop inside?
My point here is; is it better to have 100 objects with updates doing small tasks, or is it better to have a single update looping through 100 objects and do a small task for each one.
Also, I have quite a bunch of gameobject constantly checking for player position (each object has an update) so that if the player is above them it changes the display layer of the sprite. Is there a better way to achieve the same without having a lot of objects with updates just checking for that?
Answer by brunocoimbra · Dec 06, 2017 at 06:36 PM
For the first question, it could be considered micro-optimization, but it is a little faster to just call one Update and use a for-loop to go trough each one (like an TileManager that updates all tiles).
For the second one, if the position comparison should be done to each object, like "if player position is above my position", them there is no way to eliminate it, but if it is something like "if player position is above certain object that is the same for the everyone", then you could just check once in that "ObjectManager" and call the method with a for-loop for those objects.
Your answer
![](https://koobas.hobune.stream/wayback/20220612144047im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Proper way to update enemies in a large 2d level. 1 Answer
Jerks and friezes at moving after upgrading to Units 5.6 (2D game) 0 Answers
should I use Invoke or Update? 0 Answers
Really High CPU usage On empty scenes/new projects (ApplicationTickTimer problem) profiler pics 0 Answers
Full screen image impacting the performance severely 0 Answers