Physics2D Collision Matrix not working correctly, possible bug?

I’m using the Layer Collision Matrix with Physics2D to allow certain objects to pass through each other and have certain objects collide. The player can switch between layers to choose which objects to pass through and which to collide with.

Layer 8 and Layer 9 are set to not collide with each other. If my player is on Layer 8 and jumps on an object in Layer 8, he will stand on that object. When changing the layer of the player to Layer 9, he should fall through immediately, but he doesn’t. He can walk left and right on the Layer 8 object while he is in layer 9. If I leave the Layer 8 object by jumping, the Player on Layer 9 will then fall through like it should instead of landing.

For example:

Object: Layer 8
Player: Layer 8

Player stands on object → Good, since both are on layer 8.

Player changes to layer 9 → Player stays in collision with layer 8 object, even though he shouldn’t.

Player (still in Layer 9) manually leaves the object he’s colliding in by jumping → Player falls through object, which is ideal.

My Debug.log shows that he’s staying in collision with the layer 8 object even when he’s moved to layer 9. Calling IgnoreLayerCollision does nothing (it’s already set to ignore in the matrix anyway). Calling OnCollisionExit2D in OnCollisionStay2D does nothing either. Adding small nudges via a Vector2 does nothing. Is there a workaround, or am I missing something?

There are two other users that have experienced the same thing with no answers for them:

http://answers.unity3d.com/questions/612288/when-changing-a-gameobjects-layer-the-physics-coll.html
and (Second to last post by NioFox)-
http://forum.unity3d.com/threads/211215-Bug-on-physic2D-layers

Any help on the matter would be awesome. Thanks.

I found a possible workaround. By putting transform.Translate(0,0,0) in the update function of the object I need to pass through, the collision (or lack of) works as the matrix intends. The only problem is that I’d need to put transform.Translate(0,0,0) in the update of every object in my scene, which is probably a huge waste of resources depending on how many objects end up in there.

Better solutions are welcome. I’ll submit a bug report soon.

I had similar problem and had it after i installed the the free asset starter pack (cant remember how they call it). It reset all my gamepad inputs, layers and collision matrix (wasn’t really happy about that). I’m working on a 2d project so when i edited the matrix in Edit->Project Settings->Physics it didn’t work. When i chosen Physics2D everything worked as before. :slight_smile: Hope that helps