Hello Community 🙂
I try to develop a game in unity and it works great, but i am not happy with the performance.
The challenging part about my project is that i want to track many objects which collide (game is 2d).
First I just normal Circle Collider 2D and give every object a Monobehaviour to control movement. This worked great, but at around 2000 objects, the game started to lag.
So I thought I try ECS since it should be faster. However, I dont seem to get a performance increase out of it. Also there it starts to lag around 2000 objects, which was a very frustrating moment...
In ECS i used Unity.Physics.SphereCollider (since there is no 2d option) and lock angular and z-axis.
To give some context: I instantiate the creeps in code
Here the shared collider is made in the start:
var filter = new CollisionFilter
{
BelongsTo = 1u << 0, // Creep layer
CollidesWith = (1u << 0) | (1u << 1), // Creep | World (world is just 4 bounding boxes around the map)
GroupIndex = 0
};
var material = new Unity.Physics.Material { Friction = 0f, Restitution = 0f };
_creepSphere = Unity.Physics.SphereCollider.Create(
new SphereGeometry { Center = float3.zero, Radius = math.max(0.001f, colliderRadius) },
filter, material);
and i use this to spawn the object in the subscene: