2D collision matrix does not work in unity 2020

I am trying to make a system where when the player pushes on button he changes layer from “Player layer” to an “invicible layer” where the player can’t collide with enemy or other objects. so i created the “enemy” and “the invicible” layers and disabled the collision between the two from the 2d collision matrix but the collision still happens. i tried to set the player to the invicible layerfrom the start to make sure there wasn’t a problem with changing layers with the script but the collision probblem still persisted.
I tried using various functions like Physics2D.IgnoreLayerCollision(10,11, true) and Physics2D.IgnoreCollision(enemy.GetComponent(), player.GetComponent()); but nothing changed. To better understand the problem i tried disabling (i tried with all the methods above) the collision between player and an object in the scene (because i have more control on the player movement) and i saw that the collision still happens when i move horizontally but if jump on the object the player ignores the collision for a split second but then gets glitched “inside” the object. All of this problems exist only in unity 2020, not in 2019 but i can’t use the 2019 version because i need to import some packages that are available only in the 2020 version.

At this point i just don’t know what to do and i am quite desperate, any help would be much appriciated

  1. How do you detect a collision? Do you use Physics.Raycast(), collider.Cast() or anything like that, or do you detect it using OnCollisionEnter2D or OnTriggerEnter2D method call?
  2. Do the player and button have both rigidbody2d attached?
  3. Are any of the colliders have isTrigger flag enabled on it?
  4. Do you have in code any calls to IgnoreLayerCollision(10, 11, false) or anything that can potentially enable collision between those two?

@testinapuzz I don’t see the same problem in 2020.1. I created an obstacle in my game and set the layer to “test”. I don’t get a collision. Here is my collision matrix. Turning off collisions between test and Player. I didn’t do the invincible layer but you said even if you change the layer to invincible it doesn’t work.

Are you sure you disabled the collision in Physics2D collision matrix and not in the Physics Collision matrix??? (I am assuming you are working on a 2D game here)… Was just having this issue and seems like I was disabling the collision in Physics collision… Disabling the same collision in Physics2D worked for me…

I thought I had ran into this bug, but it turned out that I had enabled the “Use Collider Mask” option in a “Platform Effector 2D”, which effectively overrode which layers this platform would collide with. That meant that it could create collisions between layers which weren’t colliding according to the matrix. Bit of a facepalm, but yeah…