I ran into this bug just now and found a good workaround for it. Try disabling then re-enabling the collider after setting the new layer.
this.gameObject.layer = LayerMask.NameToLayer("IgnoreAll");
this.collider2D.enabled = false;
this.collider2D.enabled = true;
↧