Any reason why OnControllerColliderHit has a NaN normal?

I have a small MonoBehaviour script I attach to a game object in the editor, and the game object also has a CharacterController component attached to it. My question is, in my game, I (rarely) get into a situation where the ControllerColliderHit object passed to my OnControllerColliderHit function has a normal with NaN values. Can anybody think of a reason why this would happen? The rest of my source is pretty lengthy so I won’t ask anybody to dig through it, but I use both Move() and transform.position to move the object around.

Here’s the small component I use:

using UnityEngine;
public delegate void CollisionEventHandler(ControllerColliderHit hit);
public class CollisionDetector : MonoBehaviour {
  public CollisionEventHandler OnCollision;
  public void OnControllerColliderHit(ControllerColliderHit hit)
  {
    if (float.IsNaN(hit.normal.x))
      Debug.Log("Collision detector NaN normal");
    if (OnCollision != null)
      OnCollision(hit);
  }
}

I have used OnControllerColliderHit a lot, and never observed this issue. Maybe the transform.position changes are fooling the collision system and producing this error - a Character Controller is supposed to be moved only with Move and SimpleMove.

You could try to replace any transform.position assignment like this:

  transform.position = newPosition;

by a Move equivalent:

  character.Move(newPosition-transform.position);

You could also try to do all Move or transform changes in FixedUpdate (the CharacterController belongs to the physics engine like the rigidbodies).

I’m in an extremely similar situation and started getting this in Unity 4.3, leading to hard crashes / lockups. It took me literally days to diagnose, all I knew was that my state data was getting corrupted, and I poured through and logged every piece of physics related floating point math in my codebase, thinking I must have played a bit fast and loose somewhere and forgot that floats aren’t reals, or that maybe there was a corner case networking bug, but lo and behold, I find the occasional though incredibly rare NaN filled normal in ControllerColliderHitS.

Why having NaN values in a CC Move would cause a hard crash is beyond me (it should certainly fail more gracefully than that), but a hit normal should quite obviously NEVER NEVER NEVER NEVER NEVER come back NaN. That’s simply not valid and breaks the contract of the API.

For now I guess the solution is to assume Unity physics are even more broken than usual and manually guard against NaN normals.