- Home /
Assertion failed on expression: 'IsNormalized (ray.GetDirection ())'
So, I was programming a very simple mouse look script. The vertical rotation works fine (I only rotate the camera there), but if I try to rotate my player in horizontal direction, I get this error message:
Assertion failed on expression: 'IsNormalized (ray.GetDirection ())'
The mouse look itself works fine, but I get 60 of those error messages per second, which certainly isn't a good thing.
This is my code:
CharacterController playerMotor; Camera cam;
void Start () {
playerMotor = GameObject.Find("Player").GetComponent<CharacterController>();
cam = Camera.main;
}
void MouseLook ()
{
//this function is called in FixedUpdate ()
Vector3 horizontalRotation;
Vector3 verticalRotation;
horizontalRotation = new Vector3(0, Input.GetAxis("Mouse X"), 0);
verticalRotation = new Vector3(Input.GetAxis("Mouse Y"), 0, 0);
playerMotor.transform.Rotate(horizontalRotation);
cam.transform.Rotate(-verticalRotation);
}
I had more or less the same script in an older version of Unity. Since the last update I get that error message though. Does anyone know why this could happen?
I'm using Unity 5.5.0f3 btw.
I don't know what's going wrong. Your script is working fine for me, also on Unity 5.5.0f3
What is the whole error message? Which line numbers in which scripts? Are you sure it is from this function, and not somewhere else?
I tested it out, and without the line where I rotate the player (not just the camera) player$$anonymous$$otor.transform.Rotate(horizontalRotation);
, I don't get the error message.
The error message is exactly as mentioned in the title, but oddly there isn't any information about in which script/line the error occurs.
This is most likely related to some other component in your game. C# doesn't really have "assertions" by default. That's why the error has to come from a built-in component. Somewhere either a script or a built-in component builds a Ray (probably from your camera's orientation). For some reason the ray direction vector isn't normalized. That's what the assertion checks on the C++ side.
We can only guess what might be the reason for this, but possible causes are:
A deep object hierarchy or objects with non-uniform scaling and child object rotation. The last thing will cause shearing in the transformation matrix and might result in some strange transfomations.
A scale of 0 or at least a very extreme value (small or large) could theoretically cause this as well.
Do you use the new UI system? It also requires a ray for hit detection.
The problem isn't in the script you posted, even if that line of code causes it.
Ok thanks for the detailed information. I didn't have much in that project anyways, so I did a fresh restart (creating a new project) and rewrote the same piece of code, this time no errors. Could be that some file was corrupted because I imported the other project from an older version of Unity.
Thanks again for the quick reply of all you guys,
Happy program$$anonymous$$g and kind regards :)
Ditto error here...just started happening, is there a fix?
Okay, so I haven't had this issue now since I posted the last comment on this questions. But I solved it by starting anew.
Create a new Unity project.
Copy and paste all the assets you need
If it still doesn't work, try copying the script text ins$$anonymous$$d of the whole script file itself
Enjoy bug-free project
I believe this issue occurs when running an older-version-project in an updated version of Unity. Some metadata might be corrupted or wrong then.
Hope this works for you