Quick answer: CS0103 means the compiler found no variable, method or static class with that name visible from the line that uses it. Check the spelling and capitalisation first (gameObject, not gameobject). Then check where the name is declared: inside another method or block, on another script, in a namespace you have not imported with using, behind an #if, or in an assembly or package this script cannot see.
Unity stops compiling, the Console shows a red line ending in “does not exist in the current context”, and Play mode is locked until it is gone. The message is the compiler saying it looked everywhere it is allowed to look from that line and found nothing called that. Sometimes the name is misspelled. More often the thing exists and is simply out of reach: declared in a different method, living on a different component, or defined in a namespace, assembly or package the script has no access to. Below are the causes in the order they usually occur, how to tell CS0103 from its three lookalikes, and the fix for each.
- The exact error
- What “name” and “context” mean
- CS0103 and the three errors it gets confused with
- What causes it
- How to find which cause is yours
- Fix 1: correct the spelling and case
- Fix 2: declare the variable where every user can see it
- Fix 3: reach other scripts through a reference
- Fix 4: add the using directive
- Fix 5: keep conditional code and its users under the same #if
- Fix 6: make the defining assembly or package visible
- How to confirm the fix
- Where Bugnet fits, and where it does not
- Related guides
- Frequently asked questions
The exact error
Assets/Scripts/Enemy.cs(42,13): error CS0103: The name 'health' does not exist in the current context
The parts are: the file, the line and column in brackets (line 42, character 13), the compiler error code, and the name in quotes. Double-click the entry and Unity opens the file at that line in your code editor. It is a compile error, so it appears in the editor as soon as scripts recompile and in the build log when a player build compiles. Nothing runs until it is fixed, and no player ever sees it.
What “name” and “context” mean
A name here is a bare identifier used as a value or as the left side of a dot: health, rb in rb.AddForce(...), SceneManager in SceneManager.LoadScene(...), or a method called without a receiver such as Destory(gameObject).
The context is everything visible from that line: local variables declared earlier in the enclosing blocks, the method’s parameters, members of the class and its base classes (which is where transform, gameObject and Destroy come from in a MonoBehaviour), and types from namespaces imported with using. If the name is in none of those, you get CS0103.
CS0103 and the three errors it gets confused with
| Code | Example line | Message | What was not found |
|---|---|---|---|
| CS0103 | gameobject.SetActive(false); | The name ‘gameobject’ does not exist in the current context | A bare name used as a value |
| CS0246 | Rigidbody2d rb; | The type or namespace name ‘Rigidbody2d’ could not be found (are you missing a using directive or an assembly reference?) | A name used as a type |
| CS1061 | transform.Position = Vector3.zero; | ‘Transform’ does not contain a definition for ‘Position’ and no accessible extension method ‘Position’ accepting a first argument of type ‘Transform’ could be found (are you missing a using directive or an assembly reference?) | A member on an instance |
| CS0117 | Debug.log("hit"); | ‘Debug’ does not contain a definition for ‘log’ | A static member on a type |
So debug.Log("hit") is CS0103 (no such name as debug), while Debug.log("hit") is CS0117 (Debug exists, log does not). The same missing class produces CS0246 in a declaration and CS0103 in an expression, which is why a missing using often prints both. The full guides to those two are the type or namespace could not be found and CS1061.
What causes it
- A typo or wrong capitalisation. C# is case-sensitive:
gameobject,Transformwhere you meanttransform,Destory,playerSpeeddeclared andplayerspeedused. - The variable is local to another method or block. Declared in
Startand used inUpdate, or declared inside anif,for,usingortryblock and used after its closing brace. - The field or method lives on another script.
healthbelongs toPlayerHealth, and you typed it inEnemy. - A missing
usingdirective for a static class.SceneManager,File,Math,Addressables. - The class does not inherit what you think.
transform,GetComponentandStartCoroutinedo not exist in a plain C# class or aScriptableObject. - The declaration is inside
#if UNITY_EDITORor a platform or custom define, and the usage is outside it. The editor compiles; the player build fails. - The name is in an assembly this script cannot reference: a missing assembly definition reference, a class in an
Editorfolder used from runtime code, or ordinary scripts used fromAssets/Plugins. - The package is not installed, or an upgrade removed or renamed the class.
How to find which cause is yours
Start with the first error in the Console. One missing name can produce a dozen follow-on errors, and they disappear together. Then ask two questions about the quoted name.
Did you write it yourself? Search the project for its declaration (Ctrl+Shift+F in most editors). No declaration anywhere means a typo. A declaration inside another method or another class means causes 2 or 3. A declaration between #if and #endif means cause 6.
Is it a Unity, .NET or plugin class? Look it up in the scripting reference and note its namespace and, for packages, the package name. Compare the namespace with the using lines at the top of your file (cause 4), and the package with Window > Package Manager (cause 8). If your script sits under a folder with an .asmdef file, cause 7 is likely.
If the code editor shows no red underline where Unity reports the error, its project files are stale. Regenerate them from Edit > Preferences > External Tools > Regenerate project files.
Fix 1: correct the spelling and case
// Broken
gameobject.SetActive(false); // CS0103: 'gameobject'
Destory(gameObject); // CS0103: 'Destory'
// Fixed
gameObject.SetActive(false);
Destroy(gameObject);
Inherited Unity properties start lower-case (transform, gameObject, enabled, name); types and methods start upper-case (Transform, GameObject, Destroy). Accept the editor’s autocomplete instead of typing names out, and this class of mistake mostly ends.
Fix 2: declare the variable where every user can see it
// Broken: rb is local to Start and gone when Start returns
void Start()
{
Rigidbody rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.AddForce(Vector3.forward); // CS0103: 'rb'
}
// Fixed: rb is a field, assigned in Start
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
Do not keep the type in front of the assignment once the field exists. Rigidbody rb = ... inside Start declares a second, local rb, the field stays null, and the compile error turns into a NullReferenceException at runtime.
Blocks follow the same rule. A variable declared inside braces ends at the closing brace:
// Broken
if (other.CompareTag("Enemy"))
{
int damage = 10;
}
health -= damage; // CS0103: 'damage'
// Fixed: declare before the block, assign inside it
int damage = 0;
if (other.CompareTag("Enemy"))
{
damage = 10;
}
health -= damage;
This covers loop counters used after a for, a using (var reader = ...) variable used after the block, and something declared in try and read in catch or finally. Using a local above its declaration in the same block is a different code, CS0841 (Cannot use local variable 'damage' before it is declared), with the same cure: move the declaration up.
Fix 3: reach other scripts through a reference
// PlayerHealth.cs
public class PlayerHealth : MonoBehaviour
{
public int health = 100;
}
// Enemy.cs, broken
void Attack()
{
health -= 10; // CS0103: Enemy has no 'health'
}
// Enemy.cs, fixed
[SerializeField] private PlayerHealth playerHealth;
void Attack()
{
playerHealth.health -= 10;
}
Drag the player onto the field in the Inspector, or fetch the component from the object you hit with other.GetComponent<PlayerHealth>(). Writing the class name instead (PlayerHealth.health) swaps this error for CS0120, an object reference is required.
In a class that does not derive from MonoBehaviour, there is no transform or StartCoroutine to inherit. Pass in the component that owns them. Instantiate and Destroy are static methods on UnityEngine.Object, so from a plain class call them as Object.Instantiate(prefab) and Object.Destroy(target).
Fix 4: add the using directive
| Name in the error | Add at the top of the file |
|---|---|
SceneManager | using UnityEngine.SceneManagement; |
Debug, Mathf, Time, Physics | using UnityEngine; |
File, Path, Directory | using System.IO; |
Math, Convert, DateTime, Guid | using System; |
EventSystem | using UnityEngine.EventSystems; |
NavMesh | using UnityEngine.AI; |
Keyboard, Mouse, Gamepad | using UnityEngine.InputSystem; (Input System package) |
Addressables | using UnityEngine.AddressableAssets; (Addressables package) |
AssetDatabase, EditorUtility | using UnityEditor; (editor code only) |
Most editors offer this as a quick fix on the underlined name. If the using line itself turns red, the namespace is not available to this script, and you are in Fix 6.
Fix 5: keep conditional code and its users under the same #if
// Broken: compiles in the editor, CS0103 in a player build
#if UNITY_EDITOR
private string debugFolder = "Assets/Debug";
#endif
void Save()
{
Debug.Log(debugFolder);
}
// Fixed: the usage sits under the same #if as the declaration
void Save()
{
#if UNITY_EDITOR
Debug.Log(debugFolder);
#endif
}
The well-known case is EditorApplication.isPlaying = false; in a quit button: the UnityEditor namespace does not exist in a player, so the line needs #if UNITY_EDITOR around it and Application.Quit() in the #else. Custom symbols behave the same way. Scripting Define Symbols in Edit > Project Settings > Player are stored per platform, so code guarded by a plugin’s symbol can vanish when you switch from Windows to Android.
Fix 6: make the defining assembly or package visible
- Assembly definitions. A script under an
.asmdefsees only the assemblies listed in that asset’s Assembly Definition References. Select the.asmdef, add the assembly that defines the class (for exampleUnity.InputSystemorUnity.Addressables) and click Apply. Scripts with no.asmdefcompile intoAssembly-CSharp, which asmdef assemblies can never reference; move the shared class into an asmdef of its own. More in assembly definition reference errors. - Special folders. Classes in an
Editorfolder are invisible to runtime scripts, and scripts inAssets/Pluginscompile first and cannot see your ordinary scripts. - Packages. Install the package that defines the class from Window > Package Manager (under Window > Package Management in Unity 6).
- After an upgrade. Unity’s API updater rewrites most renames, but a class that was removed or renamed outright stays broken.
VRSettings, for example, becameXRSettings. Search the upgrade guide for the name and replace it by hand.
How to confirm the fix
Save the file, switch back to Unity and wait for the recompile: the red entries leave the Console and Play mode unlocks. Compile errors cannot be removed with Clear, so an empty Console after clearing is a real pass. Then make a player build for each platform you ship, because code under #if is only compiled there. If the Console is stuck on the generic message instead, see all compiler errors have to be fixed before you can enter Play mode.
Where Bugnet fits, and where it does not
Bugnet cannot help with CS0103 itself. A compile error stops the build on your machine, nothing runs, and there is no report to capture. Where it earns its place is the step after the code compiles. Fix 3 adds a serialized reference, and a reference that is never assigned in the Inspector becomes a runtime exception on whichever object you forgot. The Bugnet Unity SDK files those exceptions and error logs automatically, with the stack trace, recent log lines, platform and game version, and stacks repeats into one entry. A dashboard setting controls whether errors raised in the editor are filed too, which is useful while a team is still wiring references. Setup is one C# file; see getting started.
Related guides
- How to Fix “The type or namespace could not be found” in Unity
- How to Fix “error CS1061: does not contain a definition for” in Unity
- How to Fix “error CS0120: An object reference is required for the non-static field, method, or property” in Unity
- How to Fix “All compiler errors have to be fixed before you can enter Play Mode” in Unity
- How to Fix Unity Assembly Definition Reference Errors
Frequently asked questions
What does error CS0103 mean in Unity?
The C# compiler found no variable, method or class with that name visible from the line where you used it. The name is misspelled, declared in another method or block, belongs to another script, or sits in a namespace, assembly or package the script cannot see.
Why does the name SceneManager not exist in the current context?
SceneManager is in the UnityEngine.SceneManagement namespace, which is not covered by using UnityEngine. Add the line using UnityEngine.SceneManagement at the top of the script, or write the full name UnityEngine.SceneManagement.SceneManager where you call it.
What is the difference between CS0103 and CS0246?
CS0103 is reported when an unknown name is used as a value, such as a variable or the class in a static call. CS0246 is reported when an unknown name is used as a type, such as in a field declaration. A missing using directive can cause both.
Why do I get CS0103 only when I build the game?
The name is declared inside an if UNITY_EDITOR block, comes from the UnityEditor namespace, or depends on a scripting define symbol that is set for one platform and not another. The editor compiles that code and the player build does not.
Why can I not use a variable from Start in Update?
A variable declared inside a method is local to that method and stops existing when the method returns. Declare it as a field in the class body, then assign it in Start without repeating the type, and every method in the class can use it.
Find where the name is declared before you change the line that uses it. Whether that turns out to be nowhere, another block, another class or another assembly tells you which fix applies.