How do you accurately sync the position of colliders on an animated character in the physics engine?

I’ve been trying to figure this problem out for a week now and haven’t found any solutions.

I have a NPC with colliders attached to different bones using Unity ragdoll wizard. They’re supposed to be targets for a Physics.raycast projectile. Except, the raycast will go through some colliders depending on the animation the NPC is performing. The NPC is using a Mecanim Animator Controller.

From my research, the problem appears to be that despite the colliders appearing that they’re moving with the animation in the game window, they’re not really synced in the physics engine.

I’ve tried everything I can think of to fix this. I tried changing the fixed timestep, tried all sorts of sizes and shapes for the colliders, the colliders all have rigidbodies set to kinematic, the Animator Controller has Animate Physics checked, etc. The closest I have gotten to accurate raycast hits is changing the colliders rigidbody to interpolate but this obviously completely messes up the animations and can cause tons of deformations.

Does anyone have any thing to share or any experience dealing with this? I’ve seen multiple topics and questions dealing with the exact same issue but no responses. The only thing I can conclude now is that it’s not possible in Unity to accurately fire raycasts at colliders attached to a Mecanim character.

I believe the issue is that Animation changes are only applied after the Update phase (full Execution Order can be found here), thus if you are performing the raycast in FixedUpdate or Update, technically the raycast is being performed on the animation state from the previous frame (since the current frames animation change hasn’t occurred yet).

To correct this, put your raycast or other physics code in LateUpdate. This will allow you to still destroy objects based upon the results of your raycast, since the Scene Rendering phase only occurs after Late Update.

Hope this helps!