Game Dev Cheat Sheet

Runtime exceptions

Look rotation viewing vector is zero

The exact message

Look rotation viewing vector is zero
Variants of this message
  • Look rotation viewing vector is zero.
  • Look Rotation Viewing Vector Is Zero
  • UnityEngine.Quaternion:LookRotation

What it means

Quaternion.LookRotation was given a direction of zero length, so there is no direction to face and no rotation it can produce. A rotation needs a direction to point along, and a zero vector has none. Unity logs an error and returns Quaternion.identity. Assigning that result resets the rotation, so skip the assignment when the direction is too small.

Causes and fixes

Ranked by how often they actually occur, most common first.

  1. The target and the object are at the same position

    Subtracting two positions to get a direction gives a zero vector when they are equal. A follower that reaches its target exactly, a projectile spawned at the point it is aiming at, or a camera at the same position as its subject all produce this. It is intermittent by nature: it happens only on the frames when the two positions coincide.

    The fix: Test the direction before using it, and skip the rotation for that frame. Compare the squared magnitude against a small threshold rather than comparing the vector to Vector3.zero, so you can choose an explicit minimum direction length.

    sqrMagnitude avoids a square root and the epsilon avoids near-zero directions.

    using UnityEngine;
    
    public class Follower : MonoBehaviour
    {
        [SerializeField] private Transform target;
    
        void Update()
        {
            if (target == null) return;
    
            Vector3 direction = target.position - transform.position;
    
            // Choose a minimum direction length appropriate to this movement.
            // Vector3 equality also has a tolerance, but it is not configurable.
            if (direction.sqrMagnitude < 0.0001f) return;
    
            transform.rotation = Quaternion.LookRotation(direction);
        }
    }

    Source: Unity Scripting API: Quaternion.LookRotation, Unity Discussions: simple fix for Look rotation viewing vector is zero

  2. A velocity or input vector is zero while stationary

    Facing a character along its movement direction works while it moves and breaks the moment it stops, because velocity is then zero. The same applies to facing along a joystick or WASD input vector when nothing is pressed. The warning therefore appears exactly when the player stands still, which makes it easy to reproduce and easy to misread as a movement bug.

    The fix: Only update the rotation when there is movement to align with, and otherwise leave the previous rotation in place. Keeping the last non-zero direction in a field gives a character that stays facing the way it was going.

    Remember the last real direction rather than recomputing from a zero input.

    using UnityEngine;
    
    public class CharacterFacing : MonoBehaviour
    {
        [SerializeField] private float turnSpeed = 720f;
        private Vector3 lastDirection = Vector3.forward;
    
        public void FaceMovement(Vector3 movement)
        {
            if (movement.sqrMagnitude > 0.0001f)
            {
                lastDirection = movement.normalized;
            }
    
            transform.rotation = Quaternion.RotateTowards(
                transform.rotation,
                Quaternion.LookRotation(lastDirection),
                turnSpeed * Time.deltaTime);
        }
    }

    Source: Unity Discussions: Look rotation viewing vector is zero, how do I fix it

  3. The direction is computed from an uninitialised or destroyed reference

    Reading position from a null or destroyed Transform raises a reference exception; Unity does not supply a zero position. A zero direction can arise if your own fallback code substitutes Vector3.zero or leaves a direction variable at its default value.

    The fix: Check the target before reading its position. If it is missing, skip the rotation update rather than passing a fallback zero direction to LookRotation.

    Source: Unity Discussions: if fix for Look rotation viewing vector is zero not working

  4. A zero-sized transform or light range produces it internally

    The call is not always yours. A RectTransform with a width or height of zero has produced this warning from inside Unity's own UI code, and a spot light with its range set to zero has produced it from the Scriptable Render Pipeline. In those cases the stack trace names engine code rather than your scripts, and no guard you add will silence it.

    The fix: Read the stack trace before changing your own code. Where it points into engine code, look for a zero-sized RectTransform or a zero-range light in the scene and give it a small non-zero value instead.

    Source: Unity Issue Tracker: Look rotation viewing vector is zero warnings after setting a spot light's range to 0 in SRP

How to prevent it

Guard every LookRotation call that takes a computed direction. The check is two lines and removes an entire class of console noise, and there is no case where facing a zero direction is meaningful.

Compare sqrMagnitude against a small epsilon rather than comparing the vector to Vector3.zero. Unity's vector equality already uses a tolerance; an explicit squared-magnitude threshold lets you choose the tolerance for your movement scale.

Keep the last non-zero direction where an object should hold its facing while stationary. Recomputing from a zero input each frame is what produces both the warning and a character that snaps to a default orientation.

Treat a console full of this warning as worth fixing rather than filtering. It is cheap to silence properly, and a noisy console hides the errors that do matter.

Unity version differences

The warning text is unchanged across supported versions. Two engine-side sources of it have been fixed: the zero-sized canvas RectTransform case was resolved in Unity 2017.2, and the SRP spot light case is recorded separately in the issue tracker.

Sources

Frequently asked questions

Is this a warning or an error?
Unity logs an error and returns Quaternion.identity; this call does not throw an exception. If the caller assigns the result to a Transform, its rotation changes to identity.
I added an if check and still get the warning, so what am I missing?
Two possibilities. Either another LookRotation call elsewhere is the real source, which the stack trace will tell you, or the direction changes between the check and the call. Compare sqrMagnitude against a small epsilon instead, and read the stack trace to confirm which call site is firing.
Why does it only happen sometimes?
Because it depends on the frame. The direction is only zero when the two positions coincide exactly, or when velocity or input happens to be zero, which is usually the instant an object arrives at its target or the player stops moving. That intermittency is the signature of this warning and a good clue to which of the causes applies.
Does Vector3.zero == direction work as a check?
Yes. Unity's vector equality uses a small tolerance rather than exact component equality. Comparing sqrMagnitude against your own threshold lets you choose what counts as too small for this operation.
What does LookRotation do when the vector is zero?
It logs an error and returns Quaternion.identity. The method does not change a Transform itself, but assigning its result to transform.rotation resets that rotation. To preserve the previous rotation, check the direction and skip the assignment when it is too small.

Last updated: