I’m absolutely stumped with this problem: I have a GameObject with a Sphere collider, and a script with an OntriggerStay (Monobehaviour script). I made a test script to eliminate my own script which looks like this:
public class TestOnStay : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnTriggerStay(Collider other)
{
var test = "Test";
}
}
And I have a breakpoint at the “var test” to check if triggered.
The GameObject which has it attached looks like this: Image
The structure of where the GameObject resides looks like this: Image
If I drag the same GameObject (FovElement), and make no modifications, out of the parent GameObject (under enemies, or root), it will work as expected and trigger. I have no explanation for this, what so ever.
Things I checked:
- Layer compat: Can’t be a problem, because then it wouldn’t work when dragged out
- Parent GameObject disabled: Checked, not a problem. If it was the cube wouldn’t be blue in the Inspector (and it is)
- Rigidbody problems: The thing I try to trigger has a rigidbody, and wouldn’t explain the difference between in and out of the object
Any help or tips would be greatly appreciated.
UPDATE: I found the solution, it’s a bug within Unity: Solution is to attach above testscript to the Parent GameObject which has a rigidbody. It will then apparently send the trigger events down to the children. It’s a Unity bug which should be fixed in an upcoming release Check the bug here