- Home /
On Trigger enters being called a frame late
I'm working with some functionality that requires a function to be called as soon as the player character enters a collider. We were originally using OnControllerColliderHit functions, but that only seemed to work with physical colliders, which is causing issues as collision is repositioning him. So I switched to using OnTriggerEnter functionality, however, the OnTriggerEnter function only seems to be called the frame after the player has entered the collider, as is demonstratable by the attached picture, the print functions are called within the OnTriggerFunction, is there any way around this, or anything I should be taking into account that I am not?
Answer by Bunny83 · Apr 11, 2013 at 03:18 PM
I guess the player is still a CharacterController? Have you an additional kinematic Rigidbody attached? Usually the CharacterController doesn't produce OnTriggerXXX messages.
In this case the problem is that collisions (and triggers) are handled by the physics system. The physics system runs before Update is called, so when you move your player in Update, the collision is detected the next frame when the physics system updates.
You could try to put your movement code in FixedUpdate, but i'm not sure if that really helps, especially because it could make your movement a bit "choppier".
Thanks, I did know about the order of calls, but I just hadn't thought about it in that way. I think I tried attaching a rigidbody to check if it works, but I'll try again to make sure.
I tried attaching a rigidbody to both colliders, making them both kinematic, and the player's update is already being called in FixedUpdate. The collision is still being detected a frame late, sometimes 2 frames, when the first frame is only a small collision.
What is "small"? :) maybe it's below the "$$anonymous$$in Penetration For Penalty" value? Is it that important to get the notification a frame earlier?
You could try using Rigidbody.SweepTest to test for an intersection manually.
Your answer
Follow this Question
Related Questions
How do I prevent multiple triggers using OnTriggerEnter? 1 Answer
OnTriggerEnter Multiple Collisions Activating. I tried many variations, Please help (Java) 3 Answers
Can't call GetKey inside OnTriggerEnter? 2 Answers
Hello, How would one make a particlesystem activate triggers? (hopefully I worded that right) 0 Answers
Trigger in child object calls OnTriggerEnter in parent object 3 Answers