Quaternion.normalized

Hey there !
I have a dumb question. This line gives me “Input Quaternion was not normalized” error sometimes.

targetAngle = Mathf.Atan2(characterDirection.x, characterDirection.z) * Mathf.Rad2Deg + cameraRotation.normalized.eulerAngles.y;

Is there a known issue with the Quaternion.normalized property or am I using it the wrong way ?

Thanks for helping !

Well, if you transferred the quaternion over a network and reconstructed it on the other side, don’t you think that including that piece of code would make more sense ? ^^. Quaternions in Unity are always normalized when you assign them to properties like localRotation or rotation since Unity only works with unit quaternions.

Have you actually pinned down the piece of code that is generating that error? Have you tried disecting that long line of code into seperate lines? That way it will tell you exactly on which line the error occurs. As CodesCove said there’s usually no reason to normalize a Quaternion manually, at least not in the code you posted.

So try seperating your code into individual lines and tell us exactly on which line you get the error:

float angle = Mathf.Atan2(characterDirection.x, characterDirection.z) * Mathf.Rad2Deg;
Quaternion rot = cameraRotation.normalized;
targetAngle = angle + rot.eulerAngles.y;

Though as I said it would be more interesting where the original values come from instead of seeing where you use it.