What is the error "infinity or nan float numbers appear when calculating matrices for collider"?

Hi, guys. I’ve been getting an odd error. “infinity or nan floating point numbers appear when calculating matrices for collider” I’ve seen others on the forum getting the error too. When I was getting it in the build out, all I had to do was let the game sit and it’ll eventually come up and everything will be invisible.

Does anyone know what generally causes the error and what the error means?

NaN means not a number. It usually appears when a calculation results in infinity, which cannot be represented by a float. It usually results from dividing a number by zero.

Would that mean some collision calculation is trying to divide by zero? The happens at random when I play the buildout. Sometimes not at all, other times within the first few minutes. It can show up from playing the game or by leaving it idle. I’ve seen other people getting it randomly too. Is it a bug from Unity?

NaN is not the same as Infinity. Likewise, division by zero does not result in Infinity.

Both are special values, though.

NaN is not the same as infinity, but I have found a divide by zero calculation to be the cause NaN errors in most cases. That is why I said “usually” in response to a question that asked “what generally causes”.

Division by zero does result in infinity by the IEEE 754 floating point standard.

Oh okay. I see what you’re saying. I guess I should have asked for a more specific answer. It comes up when trying to “calculate collider matrices”. Do you think that’s something wrong with an engine bug or is it possible my code may cause such an error? I’m not dividing by zero anywhere that I can tell. I have an error console addon from the asset store and it tells me the errors end up being on lines that deal with the player character’s position or its rotation. Do you have any idea why it would say it’s caused by calculating collider matrices?

Posting some lines of code would make it easier to help.

Okay. I’ll post code in a few hours.

Okay, when the error showed, this was the line it said was the issue:

transform.position = new Vector3(transform.position.x, transform.position.y, 0);

However, I no longer need that line since I’m using a rigidbody constrained on the Z axis. But I DID comment that line out and then got the error on this line:

transform.rotation = Quaternion.LookRotation(Vector3.right * faceDir);

The former line was being called from Update and the latter is being called from FixedUpdate. All I’m doing with that line is turning the collider to instantly face left or right when the player inputs to change faceDir from 1 to -1 and vice versa. But like I said, no input is even needed. The game can just sit and idle itself until the bug randomly comes or doesn’t come at all.

I’d also like to mention that these lines are shared between two scripts. For example:
PlayerPhysics script holds the method GetMotion (which is where the rotation line is located) and is called from a script named PlayerMotor inside a method called FixedUpdateMotor which is called from FixedUpdate in PlayerPhysics. I don’t know if that configuration has anything to do with it though.

Bump

I get same error sometimes when trying to rotate car in 5.6.0f3.
I receive Vector3 via network, then check if it is NaN:

if(float.IsNaN(rot.x) || float.IsNaN(rot.y) || float.IsNaN(rot.z))
{
return;
}
if(float.IsInfinity(rot.x) || float.IsInfinity(rot.y) || float.IsInfinity(rot.z))
{
return;
}
Quaternion newrot = Quaternion.Euler(rot);
transform.localRotation = newrot;
1 Like

Error appears only when I respawn my car and it gets inside another car. I don’t see any solution. It was good in Unity 5.3.6 but I cannot revert back to it from Unity 5.6.4.

1 Like