Iterating over a compound colliders children gives bad values e.g. saying collider is terrain and showing seemingly “random” values for filter. I’ve tried with both using foreach and for looping.
var physicsColliderPtr = intCollider.ColliderPtr;
var newFilter = new CollisionFilter()
{
BelongsTo = filterInterior.belongsTo.Value << spaceShipData.crewGameID,
CollidesWith = filterInterior.collidesWith.Value << spaceShipData.crewGameID,
GroupIndex = 0
};
if (physicsColliderPtr->Type == ColliderType.Compound)
{
var compoundCollider = (CompoundCollider*)physicsColliderPtr;
compoundCollider->Filter = newFilter;
SetChildFilter(ref newFilter, ref compoundCollider);
}
...
unsafe void SetChildFilter(ref CollisionFilter collisionFilter, ref CompoundCollider* collider)
{
var numChildren = collider->NumChildren;
for (int i = 0; i < numChildren; i++)
{
ref var child = ref collider->Children[i];
...
}
}
2 Likes
Same problem, please fix asap.
I solved my case by creating an GameObjectConversionSystem in GameObjectAfterConversionGroup update group that clones and store the colliders in a IBufferElementData that is later used to set the correct collider when needed. Hope it helps : )
Some code
[UpdateInGroup(typeof(GameObjectAfterConversionGroup ))]
public class MultiLayerPhysicsCollidersConversionSystem : GameObjectConversionSystem
{
protected override void OnUpdate()
{
Entities.ForEach((MultiLayerColliderAuthoring multiLayerColliderAuthoring) =>
{
var entity = GetPrimaryEntity(multiLayerColliderAuthoring.gameObject);
if (DstEntityManager.HasComponent<PhysicsCollider>(entity))
{
var collider = DstEntityManager.GetComponentData<PhysicsCollider>(entity);
var multiLayerPhysicsColliderBuffer = DstEntityManager.GetBuffer<MultiLayerColliderElementData>(entity);
// 0 is world default
multiLayerPhysicsColliderBuffer.Add(new MultiLayerColliderElementData() {Value = collider.Value});
var colSettings = CollisionSettings.GetOrCreate();
// TODO should probably be checked vs the blobassetstore for similar blobassets
// Create clone for each layer
for (int i = 0; i < MultiLayerColliderAuthoring.numShips; i++)
{
var colliderBlobPtr = collider.Value.Value.Clone();
multiLayerPhysicsColliderBuffer.Add(new MultiLayerColliderElementData() { Value = colliderBlobPtr});
colliderBlobPtr.Value.Filter = new CollisionFilter()
{
BelongsTo = colSettings.interiorStartCollisionTag.Value << (i),
CollidesWith = colSettings.interiorStartCollisionTag.Value << (i),
GroupIndex = 0,
};
}
}
});
}
}
1 Like