Code Optimization Question

Hi, all! this is just a quick code optimization question. If you don’t know the answer, then I understand :wink:

I have a script that randomly picks 1 of 3 asteroid prefabs to spawn, picks a random position within a certain radius, gives it a random speed, random size, etc., then instantiates it.

Well I have 4 empties all with this script in different places.

Would it be more processor heavy to have 4 different empties with this script, all doing independent calculations,
Or would it be more heavy to have ONE object simply choose from an array of those empties’ transforms, and spawn them x many times as quickly?

Thanks!- YA

You generally want to do as much repetitive work as possible within a loop in a single script. Each MonoBehaviour in the scene incurs a small amount of overhead, and this can become quite expensive if you have a large number of behaviours in the scene.