[Solved] OnTriggerExit never gets called (in a most basic example)

[Solved]: dumb typo…

Hi

In a most basic example I’ve made below, to troubleshoot this-
OnTriggerExit and OnTriggerStay never gets called, but OnTiggerEnter always works fine. What is wrong here?

Setup:
You have two cubes.
You move one (through transform.position) towards the other, and you want to know when they touch (OnTiggerEnter) and exit (OnTriggerExit).

Both cubes have a Box Collider, set to trigger.
Both cubes have a Rigid Body, set to kinematic, and no gravity (since we’re moving them ourselves - no physics).


You add this script to the moving cube (to make it move towards the static cube):

using UnityEngine;
using System.Collections;

public class CubeMover : MonoBehaviour {

    void Start () {
    }

    // Move this cube to collide with CubeStatic
    void Update () {
        transform.position = transform.position + Vector3.right * Time.deltaTime * 1.5f;
        if (gameObject.rigidbody.IsSleeping())
        {
            Debug.Log("rigidbody is sleeping!"); //this prints only on first frame, then rigidbody is awake for the rest of the way...
        }
    }
}

and you also add this script to the moving cube (to detect collision entry and exit):

using UnityEngine;
using System.Collections;

public class CollisionDetector : MonoBehaviour {

    void OnTriggerEnter(Collider other) {
        Debug.Log("OnTriggerEnter"); //this prints once when the two cubes touch
    }

    void OnTiggerStay(Collider other) {
        Debug.Log("OnTiggerStay"); //this never prints?!
    }

    void OnTiggerExit(Collider other) {
        Debug.Log("OnTiggerExit"); //this never prints?!
    }

}

Result:
CubeMoving moves towards, and through, CubeStatic.
OnTriggerEnter gets called when the collision starts, but OnTiggerStay never gets called, and OnTiggerExit never gets called.

None of the cubes are tagged, or set as player, or contain a player controller… or are on any special layer.
There are no other scripts.
The cubes aren’t parented to anything.
The ridgid body of the moving cube wakes up long before the collision happens.
You can attach the CollisionDetector to the static cube also, and you’ll get two debug printouts of “OnTriggerEnter” proving that both rigid bodies are awake.

Sample .unitypackage attached: http://forum.unity3d.com/attachments/testcollision-unitypackage.103370/?temp_hash=188050cda0ee13a92d31f21ab28194fa (5.6KB)

This is on Unity 4.5.0f6.

This issue manifests in a more complicated scenario in my game, but this is the most basic way of testing it and replicating the issue - OnTiggerExit (and OnTiggerStay) never gets called!

Please help - I’m stuck!

What is wrong with this setup?

Maybe if you have a working sample of a collision where OnTiggerExit gets called - could you share the project?

1655444–103370–TestCollision.unitypackage (5.62 KB)

void OnTriggerStay(Collider other)
 {

 }
 void OnTriggerExit(Collider other)
 {

 }

It is “Trigger” not Tigger…

Hahahaaa! yep, just noticed that myself. Thanks!!

Anytime. :slight_smile: