[Unity 5.4] OnTriggerStay/Exit/Enter doesn't work properly

I created a simple scene to test this:

  • Two cubes
  • Two materials for giving each one different colors
  • Each one have a box collider attached
  • The one i move have also a rigidbody attached (with Use gravity unchecked)
  • The other one doesn’t have any rigidbody, and its collider is configured as a trigger

I created this simple script:

using UnityEngine;
using System.Collections;

public class OverlapTest : MonoBehaviour {

    // Use this for initialization
    void Start ()
    {
    
    }
    
    
    // Update is called once per frame
    void Update ()
    {
        
    }


    void OnTriggerStay(Collider collider)
    {
        Debug.Log("Overlapping '" + collider.gameObject.name + ".");
    }


    void OnTriggerEnter (Collider collider)
    {
        Debug.Log("Overlap enter.");
    }


    void OnTriggerExit (Collider collider)
    {
        Debug.Log("Overlap exit.");
    }
}

and attached it to the one that have the rigidbody.

When i click Play, i move the cube with the rigidbody and the script directly by modifying the X value in its transform component until i touch the other cube.

The OnTriggerEnter and OnTriggerExit methods are called succesfully, but ONLY THE FIRST TIME i enter and exit the other cube.
If i try another time, i get no more “Overlap enter” and “Overlap exit” messages.

And the OnTriggerStay method… only fires one time while i’m inside the other cube.

See ya!

Well… it seems all was my mistake …

I didn’t realize the Console panel has a Collapse checkbutton.
When this is active, if you write 2 or more identical messages, only one will be shown (with a number meaning how many times that message appears in the console).

The problem here is because, that button is checked by default, so, may lead to misunderstandings if you don’t know of this feature (like my case).

All resolved then :slight_smile: .

See ya!