Are physic colliders shared between instances?

EDIT: Scroll to the second post in the thread to the new question

Hi,

i already searched the forum and found some lines of code, but i run into some issues. Here is the error:

The previously scheduled job Jobs:CheckStaticBodyChangesJob reads from the ComponentTypeHandle<Unity.Physics.PhysicsCollider> CheckStaticBodyChangesJob.JobData.PhysicsColliderType. You must call JobHandle.Complete() on the job Jobs:CheckStaticBodyChangesJob, before you can write to the ComponentTypeHandle<Unity.Physics.PhysicsCollider> safely.

I already “Run()” my code so i thought this would introduce a sync point and iam done with it, but apparently this is not enough

[UpdateInGroup(typeof(SimulationSystemGroup), OrderLast = true)]
public class Bla: SystemBase

private const uint CollideWithEverything = ~ 0u;
private const uint IgnoreAntiCollisionBlock = ~ 1u << 3;

protected override void OnStartRunning()
{
  Entities.ForEach((ref PhysicsCollider physicsCollider) =>
    {
      var collisionFilter = physicsCollider.GetCollisionFilter();
      collisionFilter.CollidesWith = IgnoreAntiCollisionBlock;
      EntityUtils.SetCollisionFilter(ref physicsCollider, collisionFilter);
    })
    .Run();
}

protected override void OnStopRunning()
{
  Entities.ForEach((ref PhysicsCollider physicsCollider) =>
    {
      var collisionFilter = physicsCollider.GetCollisionFilter();
      collisionFilter.CollidesWith = CollideWithEverything;
      EntityUtils.SetCollisionFilter(ref physicsCollider, collisionFilter);
    })
    .Run();
}

public static CollisionFilter GetCollisionFilter(this ref PhysicsCollider collider)
{
  var filter = CollisionFilter.Default;
  unsafe
  {
    var colliderPtr = (ConvexCollider*) collider.ColliderPtr;
    filter = colliderPtr->Filter;
  }

  return filter;
}

public static void SetCollisionFilter(ref PhysicsCollider collider, CollisionFilter newFilter)
{
  unsafe
  {
    var colliderPtr = (ConvexCollider*) collider.ColliderPtr;
    colliderPtr->Filter = newFilter;
  }
}

okay its not solved! :slight_smile:

My question is: are physicscollider shared somehow?

I iterate over each object, then i remember the current collideWith value, then override the physicscollider.collidewith value to something else. Later i want to switch back to the original one.

But apparently the values are shared between instances:

//I do this for every object once
var temp = physicsCollider.Value.Value.Filter;

storedData.TempCollidesWith = physicsCollider.Value.Value.Filter.CollidesWith;

//temp.CollidesWith = 0u;
physicsCollider.Value.Value.Filter = temp;

if i uncomment the value, then i store a single time the correct value, and then i store only 0s to the storedData entity…

I tried setting the entity to “force unique”, but this doesnt change anything.

Did i do something wrong?

force unique appears to be broken to me…

In general colliders can be shared if they have the same input yes

“Force unique” checkbox in “Physics Shape” component should control creation of separate colliders for bodies (leaving it OFF will make colliders be shared).
Could you please provide more details around when you’re trying to change the filter and what you want to achieve? Have you tried using UnityEngine.Debug.Log or asserts to print the values at the end and make sure you really performed the changes?