It lags when there are 150 game objects nearby

Help please.
I have 300 game objects on the stage - simple cubes with a collider and a trigger and a rigidbody. A separate layer has been created for these cubes. The physics setting states that the objects in this layer do not interact with each other.
When the game objects are distributed evenly across the scene with dimensions of 250 * 250, everything works, nothing slows down. But when I bring these objects together (even 150 out of 300) approximately in volume 101010 it starts to lag terribly. If I distribute them back, the lags disappear.
Why can this happen and how to fix it?

It depends on the GameObjects Polycount. How many polygons is the model of each GameObject and what are your pc/laptop specs?

Show us your collision matrix and the gameobject’s layer.

I tried different models for the final object: cubes, spheres, and even just a square. Almost no difference. When they come together, it starts to lag. I’m creating a project for smartphones. Now I’m testing on Honor 50 lite


Have you used the profiler?

1 Like

What’s going on in your “Ship” script and will it be doing anything differently based on proximity of other objects?

Wouldn’t happen to be an O(n^2) algo hanging out in there somewhere, would there?

You need to run the game through profiler. Like @angrypenguin noticed, you have a custom script on your ship, and given that your script has a list of enemies to attack, it might be doing something computationally epxensive when objects get too close to each other.