OnTriggerExit2D not working, but OnTriggerEnter2D does???

Just as the title states. I have an enemy and when he collides with a boxCollider2D the OnTriggerEnter2D works, but I cant even get a Debug.Log(“test”); to show up on an OnTriggerExit2D.

What gives???

5 Answers

5

Check your spelling and capitalisation

If that doesnt help you might need to paste some code for anyone to be able to help

I added my code.

well then you cant call onkeydown, them you have to set a bool to true and inside the update part, call onkeydown

public void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == “Edge”)
{
enemy.ChangeDirection();

        }
        if (other.tag == "JumpTrigger")
        {
            enemy.EnemyJump();
            Debug.Log("Jump Test - On Enter");

        }
        if (other.tag == "LandTrigger")
        {
            enemy.EnemyLand();
            Debug.Log("Land test - On Enter");


        }
    }

    public void OnTriggerExit2D(Collider2D other)
    {
        if (other.tag == "JumpTrigger")
        {
            Debug.Log("Jump Test - On Exit");
        }
    }

On Enter works, On Exit does not.

???

Paste what change direction does?

What does enemy.EnemyJump(); do? Without seeing any code i would guess that it is because you are moving the collider out in the same frame (I dont think you can have an enter and an exit happen in the same frame so the exit gets missed) You could try making the jump function set a member variable and in update in the next frame react to that

That's exactly what I ment, I wasn't clear maybe.

It is soo hard to answer with such little information… :frowning:
There are soo many things to check.
1:Check which colliders are really used.
2:See if any colliders are getting Disabled/Becoming Non Trigger/Sizes/Changing Layers/ etc…
3:Check if one of at least one rigid body stays active all along.
4:Check if script is enabled all along. etc…

Sooo soo many things could have gone wrong.

If all the OnTriggerEnter2D's are working then why does it matter what is inside them? The script is enabled because the OnTriggerEnter2D's are working. Its the same collider, I don't understand why It works on the onEnter and not onExit. It's all the same colliders.

Is your enemy actually leaving the the trigger area? if not, on trigger exit wont be called.

e.g. Enemy enters area, enemy is destroyed. Trigger exit wont be called.

e.g Enemy enters area, Trigger is destroy. Trigger exit wont be called.

e.g Enemy enters area, Passes through and out of area. Trigger exit will be called.

Try to change the place of " Debug.Log(“Jump Test - On Exit”);" to outside of your if condition [if (other.tag == “JumpTrigger”)] to see if the problem is really if the OnTriggerExit2D call or it is up to your IF statement

So once you have an attached follower, you don't want anymore to follow?