Hi, unity teams
I’m trying to use the following code to override CollisionFilter.GroupIndex at baking time. But I find that sometimes the GroupIndex is not what I expected.
It looks like that if two objects have same Collider shape / layer, they will share the same BlobAssetReference. So they can’t have different GroupIndex. Am I right? Is there any solution?
Thanks : D
[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
[UpdateInGroup(typeof(PostBakingSystemGroup))]
private partial struct BakeSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
using var buffer = new EntityCommandBuffer(Allocator.Temp);
foreach (var (@override, collider, e) in SystemAPI
.Query<PhysicsGroupIndexOverride, RefRW<PhysicsCollider>>()
.WithOptions(EntityQueryOptions.IncludePrefab).WithEntityAccess())
{
var newCollider = collider.ValueRW.Value.Value.Clone();
var filter = newCollider.Value.GetCollisionFilter();
filter.GroupIndex = @override.GroupIndex;
newCollider.Value.SetCollisionFilter(filter);
collider.ValueRW.Value = newCollider;
buffer.RemoveComponent<PhysicsGroupIndexOverride>(e);
}
buffer.Playback(state.EntityManager);
}