Colliders/Rigidbodies on multiple objects - performance issues

Hi

I’m instantiating one stone prefab periodically. Each stone falls down and collides with bottom or other stones.
Each prefab has BoxCollider2D, RigidBody2D and a script assigned.
All works smoothly, however, the performance is decreased significantly when there is a lot of the stones in scene spawned.
Is there any way how to optimise the prefabs or scene to increase performance?
I tried to put the stone to sleep if it’s velocity is 0 but no change.

Thanks

Inf-

How many is a lot?

Have you tried pooling the stone objects, so that you’re pulling from an existing set of objects rather than Instantiating?

FPS is starting to decrease with about 50 stones on scene and drops to 3 FPS with about 80 stones.
I haven’t tried to pooling the object, cause I’m not aware about this option, I will try to find something about it.
Thank You :slight_smile:

Just 80? Are they piling up in heaps? Does each stone have a collision function? You might squeeze a lot more performance out by forcing settled stones into kinematic and disabling any collision reactions.

…Actually, are you using OnCollisionStay2D for each stone? That might be your primary problem right there.

Actually… I was using OnCollisionStay2D :slight_smile:
Silly mistake but I didn’t realise it has such impact on performance, so problem solved.

Thanks a lot :slight_smile: