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. It is a warning rather than an exception, so the game keeps running, which is why it usually arrives as a console full of identical messages rather than as a crash.

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, because floating point rarely produces exactly zero.

    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;
    
            // Comparing against Vector3.zero uses an approximate equality that
            // still admits directions too small to normalise usefully.
            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

    A target field that is empty, or that points at a destroyed object, gives a position of zero from Unity's perspective in some code paths, and subtracting that from the object's own position produces a direction that is meaningless rather than merely zero. The warning is then a symptom of a reference problem rather than of the maths.

    The fix: Check the target reference before computing the direction. Where the warning appears alongside NullReferenceException or MissingReferenceException in the console, fix those first; this warning usually disappears with them.

    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 equality for vectors is approximate but still admits directions small enough to normalise into nonsense, and sqrMagnitude avoids an unnecessary square root.

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?
A warning. Unity logs it and carries on, leaving the rotation unchanged for that call. Nothing crashes, which is why it typically appears hundreds of times rather than once. It still indicates a real problem in the calling code, because asking to face a direction that does not exist is never intentional.
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 your check is comparing against Vector3.zero and letting through a direction that is tiny but not exactly zero. 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?
It works, but it is the weaker option. Unity's vector equality compares with a small tolerance, so it catches exact and near-exact zeros, but directions slightly above that tolerance still normalise into unreliable results. Comparing sqrMagnitude against your own threshold is more explicit about what counts as too small, and avoids a square root.
What does LookRotation do when the vector is zero?
It logs the warning and returns without producing a usable rotation, leaving the value unchanged. It does not throw, and it does not reset the object to an identity rotation. That is why the visible symptom is usually an object that stops turning rather than one that snaps somewhere unexpected.

Last updated: