Checking area via code or detection collider

What do you think is better for performance?

  • Thousands of objects checking for enemies around via code?
  • Or thousands of objects checking for nearby enemies with its attached, say Circle collider?

So lets say you have turret and it checks for enemies around it if they are close.

Both have advantages and disadvantages. Getting vector and sqrMagnitude and then comparing it to nearest object, can have have lag spikes if doing it for thousands of objects lets say every 1 second.
But having additional thousands of moving colliders on scene can have impact too.

I think having thousands of anything is bad for performance.
With your information given I’d say test both approaches and see each impact in the profiler since numbers count and guessing is quite hard if one don’t know what’s actually going on.

More important questions would be to get the numbers down like:

  • Do off screen enemies need to be updated?
  • Are they forming army like formations and therefore a check to the army is sufficient?

Now that I think about it, depending on a first distance check with all there could be a coroutine running only on the closest ones and sometimes on enemies further away.

Handling large numbers will be tricky anyways.