Best way to move lots of game objects in an optimal way

I have made a top-down shooter game with lots of enemies moving towards to the player. I have been thinking what would be a good solution to handle all those enemies without much performance issues.

  • Each enemy has a movement script with Update function to handle all the movements.
  • An enemy manager script with Update function to iterate the enemies to make them all move.

Thanks in advance :slight_smile:

If you’re experiencing performance issues try identifying the code that’s causing said issues using the profiler. Otherwise, if everything is running smoothly and working then I don’t see what the problem is. Now I did google this because I am curious, say you have thousands of objects moving, here’s an answer from a forum post I found interesting:

  • Don’t put a script on each thing. Instead, have one script that moves all of them. That’ll save you some overhead when you’re moving this many things.
  • Move all of those objects to the top of the hierarchy. Moving things that have parents are slightly more expensive.
  • Reduce the number of if-statements
  • Instead of the moving-bool, have things that are not moving in their own list, which you don’t do anything with.
  • Instead of having a reverse bool, change the value of your destination when you get to the current destination.

https://forum.unity.com/threads/optimizing-the-movement-of-many-gameobjects.488081/