OnTriggerEnter/Exit only happening once

I have a scene which involves several characters walking around. Currently when they pass a certain threshold distance to the camera, they switch from one character object to another. I want to continue doing this, but use a box collider and the OnTriggerEnter and OnTriggerExit events instead.

I created my empty game object, added my box collider, checked “Is Trigger”, added a RigidBody component and unchecked “Is Kinematic” and “Use Gravity”, and moved it into place. I added the following basic script to it to just print out a message when one of my characters encounters it:

using UnityEngine;
using System.Collections;

public class AvatarSwitcher : MonoBehaviour {

	/*
	* AvatarSwitcher.cs
	* by Aaron Siegel, 9-1-10
	*
	* Attached to a large invisible box collider used to detect onTriggerEnter and Exit events
	* in order to switch 
	*/
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter (Collider other) {
		print(other +" has entered"); 
	}
	
	void OnTriggerExit (Collider other) {
		print(other +" has exited");
	}
}

The thing that baffles me at this point is that I only get the print messages once. The first character that interacts with the box triggers the enter/exit events, but after that none of them seem to have any effect.

disable “collapse” in the console window :wink:

Not to sure what your problem is, but you do not need a rigidbody of Trigger detection. A rigidbody is mainly for the use of physics. What i do when i want to make trigger i create a cube, and simply set the box collider to ‘is Trigger’. That way i can clearly see when i enter and exit the trigger, then delete the mesh filter and renderer.

If you have done that, and attached your script to it, then it will detect it whenever something with a rigidbody enters it. Here is the code that works perfectly well for what you want in Javascript, as i am not that good a C#.

function OnTriggerEnter (other : Collider) {
	Debug.Log("Something is in side me!!!!");
}

function OnTriggerExit (other : Collider) {
	Debug.Log("Its out! Thank the Heavens! ");
}

Thanks. That was ridiculous. :sweat_smile:
Why does that button even exist?

to prevent the console from going nuts.
you will likely find good use for it later when you use outputs for “program flow debugging” when a state change goes nuts somewhere … without collapse such a thing can cost the last nerve as you easily have hundreds of outputs in a dozen seconds and alike.

The idea is that the console only adds new entries for stuff that changed, not for stuff thats “still the same”

Thank YOU!