onTriggerEnter works but not onTriggerExit???

Okay, have a simple bit of code. Player (rigidbody with collider, no charcontroller) moves, hits a cube set up as a trigger (box collider, no rigidbody). Cube has an onTriggerEnterscript attached that parents the player to another cube (parentCube, collider, no RB). There’s also an onTriggerExit code attached to the cube but this is never triggered (no message in the console).
So I figured maybe it’s because the player is now a child and doesn’t register as a collider BUT it does. onTriggerEnter is still reported in the debug console but never onTriggerExit. If I create another cube with onTriggerEnter script on it the cild-player will happily trigger it - no problem. So my questions is why do the triggers register onTriggerEnter but not onTriggerExit. Bug or am I missing something? Here’s the code. Any help much appreciated.

private var steps : GameObject;

function Start () {
steps = GameObject.Find("parentCube");
}

function OnTriggerEnter (other : Collider) {
	Debug.Log("Entered");
	// find the script attached to the player
	var otherScript = other.GetComponent(newController);
	// turn off controller
	otherScript.canControl = false;
	// Get the transform of the player
	var playerTransform = other.transform; 
	// Get transform of the steps object
	var stepsTransform = steps.transform;
	// make player a child of the steps object
	playerTransform.parent = stepsTransform; 
	// turn off gravity
if (other.attachedRigidbody) {
other.attachedRigidbody.useGravity = false;
}
	// Get script attached to steps
	var stepscript = steps.GetComponent(CubeController);
	// enable control of the steps object
	stepscript.canControl = true;
}

function OnTriggerExit (other : Collider) {
	Debug.Log("Exit");
	var stepscript = steps.GetComponent(CubeController);
	stepscript.canControl = false;
	var playerTransform = other.transform;
	// un-child 
	playerTransform.parent = null;
 	// find the script attached to the player
	var otherScript = other.GetComponent(newController);
	// turn on controller
	otherScript.canControl = true;
	// turn on gravity
if (other.attachedRigidbody) {
other.attachedRigidbody.useGravity = true;
}
}

Oh and I should add that when not parented to the cube the onExit trigger does work so I’m doing something wrong here but I just dont get why it’s only on Exit and not on Enter…and a way to make it work would also be nice :). tia.

A bit confusing on what you want to do. But have your player leave the trigger if not trigger exit would not even run at all.

Just add a rigid body to the cube trigger as kinematic, or a joint. For some reason it’s buggy with compounds.

@ hippocoder: Tried adding a kinematic RB but doesn’t help. It’s the strangest thing: if my compound collider leaves the trigger onExit isn’t called but if the exact same compound enters another trigger onEnter is called!? Go figure. So is this a known unity bug then? OnExit Triggers dont work with compounds but onEntry triggers do? Seems a bit odd. Any Unity employee or mod commented on this before? Or do I need to file a bug report?

Hmm, I just considered that maybe because i’m creating the parent-child compound in the trigger area after onEnter is called that the initial collider is no longer recognized because it’s a child now and as such never leaves the trigger, hence no onExit?

Yes it is a bug but you need to loop through collider.contactpoints, instead of just getting the collider.

The reason I consider it a bug is because with compounds, you get the parent events for exit but child events for enter. The exit part is which is bugged, solved by attaching a joint from child to parent.

I hope unity fixes it but I haven’t heard back from them about that bug.

@hippocoder: Thanx for the info.