Continious OnCollisionEnter2D and OnCollisionExit2D

Hi,

I try to detect if a RB is (still) on a tile, but while it’s on there, it keeps triggering OnCollisionEnter2D and OnCollisionExit2D continiously.

I’ve tried a few combinations, just BoxCollider2D, a TileCollider2d in combination with a CompositeCollider, but all show the same effect.

Since i want to set a state to my Player if it enters it and leaves it, that doesn’t work if both get keeping triggered…

Any ideas?

It won’t do that unless you’re doing something that’s causing it.

TileCollider2D, CompositeCollider2D are not special and the physics system doesn’t know anything about them. In the end, it’ll only exit if it has no contacts with that collider or if you’re doing something to cause it to cycle like disabling/enabling colliders etc.

NOTE: There’s a physics forum for this stuff.

Let’s say i have a square sprite with a box collider (that’s easier for this discussion)
I have a player (RB) that’s moving over the collider. I would expect it to only exit if it’s not longer touching the sprite?

Further i don’t to anything with disable / enable

The square sprite has this code;
The RB has continious colliding tracking…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Safezone : MonoBehaviour
{
    // Start is called before the first frame update
   private bool hasEntered;

    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        Debug.Log("Your in the Safezone!!!");
    }

    void OnTriggerExit2D(Collider2D hitInfo)
    {
        Debug.Log("Your left the Safezone!!!");
    }


}

p.s. sorry will next time post it in the other forum…

If you are getting Enter/Exit continuously with nothing changing and the player collider (whatever that is) still overlapping this other box then basically 2D physics is broken and there’d be pitchforks out.

TBH, showing a script with enter/exit on it doesn’t really show anything. What collider is on the player (not that this would really matter) and how is the Rigidbody2D being moved?

Put together a simple example in a new project with two boxes and see if you can duplicate it there. If you get can send me a simple reprouction project and I’ll take a look for you.