Home / Unity / U21

Unity error: CS0103: The name 'name' does not exist in the current context — cause and fix

At Unity script compile time, an identifier referenced inside the current scope does not e

ID
U21
Engine
Unity
Verification
官方文档引用
Frequency
未公开

Original message (verbatim)

CS0103: The name 'name' does not exist in the current context

Placeholders such as %s / %d are kept verbatim from the engine source and are not replaced with concrete values.

Trigger

At Unity script compile time, an identifier referenced inside the current scope does not exist (misspelled variable or method, missing using, a field declared elsewhere, or inside a conditional block), and Assembly-CSharp fails to compile.

Typical cause

The Roslyn compiler cannot find the name in the current class, namespace, or scope, emits CS0103, and the script does not produce an assembly.

Step-by-step fix

  1. Check the identifier spelling and casing, and confirm the variable or method is declared in a visible scope of the same class.
  2. Add the missing using directive for the namespace.
  3. Check whether the member is excluded by a conditional compilation define.

Source links

Per-entry sources and capture date are listed at /sources#U21.

Related errors

Related Unity errors

Need an offline quick-reference checklist?

Atlas error library Pro pack: 123 error references (110 single + 13 merged) plus a quick-fix guide, $19 one-time purchase, delivered as electronic files.

View Pro pack / order

Back to the all-errors index Checkout and buy the Pro pack — $19.00