Look rotation viewing vector is zero

ConsoleRuntime exception · Math

Look rotation viewing vector is zero

Quaternion.LookRotation was asked to face a direction of zero length. A direction of nothing has no way to point, so Unity logs this and returns no rotation. It usually happens the frame a character stops moving.

Read the Console line first

This is logged rather than thrown, so the game keeps running. The stack trace points to the LookRotation call or a method that uses it, such as Transform.LookAt.

Common causes

  1. Rotating towards the movement direction while standing still

    With no input, the move direction is Vector3.zero, and LookRotation(Vector3.zero) has nothing to face.

  2. Looking at your own position

    target.position - transform.position is zero when the target is the object itself, or sits exactly where it is.

  3. Flattening a vertical direction

    Setting y to 0 on a direction that pointed straight up or down leaves zero.

The fix

Fix
C#
Vector3 direction = new Vector3(input.x, 0f, input.y);

if (direction.sqrMagnitude > 0.0001f)
{
    transform.rotation = Quaternion.LookRotation(direction);
}

Stop it coming back

Guard every LookRotation on a computed direction with a small sqrMagnitude check, and keep the last valid rotation when there is no direction.

Questions

Does this message break anything?
The rotation simply does not change that frame, but the message is logged every frame while the vector stays zero, which floods the Console and costs time in the Editor.
What threshold should I check?
Compare the squared length to a small number: if (direction.sqrMagnitude > 0.0001f) transform.rotation = Quaternion.LookRotation(direction);. sqrMagnitude avoids a square root.
How do I rotate towards a direction in 2D?
LookRotation is for 3D. In 2D, compute the angle with Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg and set transform.rotation = Quaternion.Euler(0, 0, angle);.

Scripts that avoid it

Related errors

Got a different error? Paste it into the error lookup.