- Home /
I copied my project from Unity 4 to Unity 5. OnTriggerStay is no longer working -- what changed?
As the title says, I switched from Unity 4 to Unity 5. Everything works except for one thing: I have an OnTriggerStay function that is no longer called when my capsule collider enters a sphere collider. I have the project open in two windows: one is Unity 4, and it works, and one is Unity 5 and it doesn't work. So I'm assuming the way you would handle that type of stuff has changed. Can someone fill me in? Let me know if you need more info.
Update: changing the function from OnTriggerStay to OnTriggerEnter makes it get called. Unfortunately, I need OnTriggerStay, which seems to have been messed with. Can't find anything about it in the release notes. I'm on 5.1
$$anonymous$$y guess would be it is being called, but some code inside is working differently. You've got Debug.Log("got here");
as the first thing in OTS?
Or, maybe a setting got knocked loose on the conversion, like collision-layers.
@Owen Reynolds I have tried debugging with Debug.Log and it shows that OnTriggerStay definitely isn't being called. It also looks like my collision layers have not changed -- even the layer collision matrix carried over correctly. It really seems like nothing about my project changed between Unity 4 and Unity 5. I'm gonna have to dig through the Unity 5 update notes or something I think.
Weird update: I changed the function from OnTriggerStay to OnTriggerEnter and it did call the function. I changed it back to OnTriggerStay and it didn't call it. Unity 5 must have done something to OnTriggerStay!
I'm pretty sure the answer is yes if you're getting OnTriggerEnter, but do you have a Rigidbody attached to the object and/or the trigger? Also, what type of collider is on each?
The trigger is a sphere collider, and it is on an object that has a parent with a rigidbody. The collider is a capsule collider, which is the player. No rigidbody there.
Answer by sabish-m · Jun 12, 2015 at 06:05 PM
now i am working in Unity 5.. i am using OnTriggerStay function its working fine...
maybe it will be help you...
#pragma strict
function OnTriggerStay(other : Collider){
if(other.tag == "MovingBridge"){
transform.parent = other.transform;
}
}
function OnTriggerExit(other : Collider){
if(other.tag == "MovingBridge"){
transform.parent = null;
}
}
Answer by Madhotdog · Oct 20, 2015 at 12:03 PM
Just in case anyone else gets stuck on this issue the problem is related to the following bug: http://issuetracker.unity3d.com/issues/triggercollider-ontriggerstay-is-not-called-for-child-objects
To further note, it appears that adding a rigidbody to the OnTrigger scripted object allows OnTriggerStay events to be called even when its parent object has a rigidbody.
This does not work: -> Parent (has rigidbody) ---> Child (has OnTrigger script)
This works: -> Parent (has rigidbody) ---> Child (has rigidbody, OnTrigger script)
Adding a blank OnTriggerStay method to the parent also will surfice
public void OnTriggerStay(Collider other)
{
// Unity needs this method here
}