Runtime exceptions
Look rotation viewing vector is zero
The exact message
Look rotation viewing vector is zeroVariants 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.
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
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
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
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.
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.
Related errors
- NullReferenceExceptionWhy Unity throws NullReferenceException, how to read the stack trace to find the exact line, and the five causes that account for nearly all of them.
- Non-convex MeshColliderWhy Unity rejects a concave MeshCollider on a moving Rigidbody, what PhysX can and cannot simulate, and the four ways to get the collision you wanted.
Related tools
- Game MathsInteractive cheat sheet with live visualisations. Distance, lerp, dot product, vectors, and more with Unity C# code.
- Easing VisualiserInteractive curves with Unity code output. DOTween, LeanTween, and AnimationCurve snippets for every standard easing function.
- UI AnchoringVisual reference for Unity RectTransform anchors with code for every preset and common UI patterns.
Sources
- Unity Scripting API: Quaternion.LookRotation
- Unity Scripting API: Vector3.sqrMagnitude
- Unity Discussions: simple fix for Look rotation viewing vector is zero
- Unity Discussions: Look rotation viewing vector is zero, how do I fix it
- Unity Discussions: if fix for Look rotation viewing vector is zero not working
- Unity Issue Tracker: Look rotation viewing vector is zero warnings after setting a spot light's range to 0 in SRP