Possible platformer effector bug

I’m developing a 2D platform game that uses the platform effector. I use the function OnCollisionEnter2D to set variables like isGrounded and to change the animation state in Mechanim.Since platform effectors trigger that function even when the collision is ignored, I check the variable Collision2D.enabled to make sure that the collider is enabled and the character is actually on top of the platform. This works fine most of the time. However, I realised that sometimes the collision is resolved and the player stays on top of the platform, but OnCollisionEnter2D doesn’t get called. After some debugging I think I found the problem: most times, when the player jumps it triggers OnCollisionEnter2D when it touches the platform from below and I ignore that collision because Collision2D.enabled is false. The player continues to move up until it goes over the platform and then falls on the platform and triggers OnCollisionEnter2D again and this time I set isGrounded to true because this is a valid collision. This is the most common behaviour. However, there is a special case that happens when the platform is at a height equal to the height of the jump. In this case, the collision is resolved but the player hasn’t exited the collision, so the player stays on top of the platform but OnCollisionEnter2D doesn’t get called because it was called when the character hit the platform from below. As a result, I had to also implement the OnCollisionStay2D function to check for Collision2D.enabled until it becomes true to set isGrounded to true. This is obviously not an ideal solution. I don’t know about other games, but in my case, triggering OnCollisionEnter when the collision is ignored is clearly not the desired behaviour, or, at least, it should get called again when the collision is enabled. Or maybe I’m missing something. Any ideas?

Sorry for necroing, but I just discovered the same problem.

Due to a platform effector, the collision is disabled (enabled=false) when CollisionEnter2D is called when the player jumps up from below. The same collision gets enabled once the player reaches the top of the platform, but there’s no callback for that state change. So you either have to poll for the collider contacts or try to use OnCollisionStay2D, which seems potentially expensive. It also doesn’t seem to have a well-defined relation with OnCollisionExit2D, so it seems hard to track when the collision stops.

Any suggestions for workarounds or better solutions here?