limit number of same type of object within a certain distance

Hi guys, im having some trouble with instantiate bullet shells causing lag. I want them to last for a long time, at least an hour(I know im an idiot). They work great, instantiate great, make a sound on collision and they stay there. Im using a capsule collider on them and everything is fine.

The only problem is if I stand in one spot and unload a few mags on full auto, I would say after about 90 shells are on the ground in that area I start getting some lag. Then it just gets worse. If I move from that spot, no lag.

I thought it was due to the bullet shells impacting each other, so i made a new physics layer called bulletshell, and set it to not interect with itself. Lag is still there.

Now im thinking a possiable solution could be to just limit the number of shells withen a certain range of each other. So if the newly instantiated shell on collision is 3 inches from another bullet shell it will destroy itself.

Anyone know how to delete an object based on its distance to another object of the same type?

I figured this out, I just made it so that if a bullet shell collides with another bullet shell it deletes it. Heres the code.

Destroy(that.gameObject, 10.0f); // 10.0f - 10 as Time in seconds or 3600 - 1 hr

problem got me too thinking , disable-rigidbody that would increase performance and while we are at it collision-off

I like to see the bullet casing’s bounce on the ground then timeout shortly say in 10’s then disable-rigidybody and destroy() abit later. :slight_smile: