I have a DynamicBuffer of positions on which I want to create sphere colliders. I am using following system to create colliders in runtime:
partial struct CreateCollidersSystem : ISystem
{
private BlobAssetReference<Unity.Physics.Collider> CreatedColliderBlob;
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
// Do it only once
state.Enabled = false;
// Define sphere geometry
SphereGeometry sphereGeometry = new SphereGeometry
{
Center = float3.zero,
Radius = 1f
};
// Create collider blob
CreatedColliderBlob = Unity.Physics.SphereCollider.Create(sphereGeometry, new CollisionFilter
{
BelongsTo = (uint)CollisionLayers.Ground,
CollidesWith = (uint)CollisionLayers.Players
});
EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp);
DynamicBuffer<WaypointElement> waypointsBuffer = SystemAPI.GetSingletonBuffer<WaypointElement>();
// Add collider to each point in buffer
foreach (WaypointElement waypoint in waypointsBuffer)
{
ecb.AddComponent(waypoint.Entity, new PhysicsCollider { Value = CreatedColliderBlob });
ecb.AddSharedComponent(waypoint.Entity, new PhysicsWorldIndex { Value = 0 });
}
ecb.Playback(state.EntityManager);
ecb.Dispose();
}
[BurstCompile]
public void OnDestroy(ref SystemState state)
{
if (CreatedColliderBlob.IsCreated)
CreatedColliderBlob.Dispose();
}
}
Although colliders are created correctly, after inspection in editor I can see that each one is marked as unique:
Why it should be unique when I am using single blob to define all the colliders? I believe correct behaviour should be non-unique state by default.
Am I missing something here? Or is it a bug? I am using latest versions of the Physics and Entities (1.3.8).