Handle large number of checks per frame

Hi everyone,

I am looking for suggestions on handling large number of checks/calculations every frame.

As of now, these are position checks (distance from one transform to another).
I am currently limiting the number of calculations to 10 every frame (I have 500+ moving objects in the scene) using a script. This works fine, but before looping through all moving objects 50 frames have to pass, which may take more than a second depending on the game framerate. However, if I increase the number of checks per frame (say 50), the FPS may drop a bit and as a consequence I end up in a similar situation as before.

I am wondering if there is a more efficient way to handle large number of objects. Is there an industry standard for solving such an issue (a bit like there is object pooling when trying to optimize object usage by removing instanciating and destroying them)?

Thanks in advance

Usually this is done by spatial partitioning like Quadtree or Octree. Unity has Culling Group built in which can be utilized to find nearby objects. Maybe that gives you some direction.

Best bet would be to use the new ECS (in preview) as this can easily handle collisions between 10 thousands of objects. But it’s quite a different paradigm.

Thanks a lot! Culling group seems to be I need based on a quick look. I’ll check it out properly.
We are also looking into ECS, but we were only planning to use it to a very limited extent due to the initial learning curve and the fact that there are still constant updates on it, which makes it kind of hard to work with.

This is the key to getting computer game performance: if you have to do a LOT of computations, figure out some way to NOT have to do them. If the computations by definitely only involve nearby objects, then spatial partitioning may be an excellent choice. Another term for it is “bucketizing” by position.

1 Like