C# COMPILER • CS1061

CS1061: 'Type' does not contain a definition for 'name'

The classic C# compiler error. Occurs when calling a variable or method that is either misspelled, declared private, or missing a using namespace.

Quick 3-Step Solution

  1. Make the member public: Change float speed; to public float speed; or expose a property public float CurrentSpeed => speed;.
  2. Fix Letter Casing: C# is case-sensitive! LinearVelocity != linearVelocity.
  3. Missing Namespace: If using UI methods, add using UnityEngine.UI; or using TMPro; at the top of the file.
Working on Vehicle Audio or Speedometers?
Check our specialized fix for vehicle script references: EngineController does not contain a definition for 'currentSpeed' →

Fixing "The referenced script (Unknown) on this Behaviour is missing!" in Unity

This classic Unity error occurs when a GameObject in your scene hierarchy or a saved prefab in your Project folder references a MonoScript asset whose GUID reference has broken or failed C# compilation. When this occurs, Unity displays an empty component banner with a warning icon and the label Script: None (Mono Script).

Root Causes and Immediate Solutions

  • Class Name vs Filename Mismatch: In C#, Unity strictly mandates that the class name deriving from MonoBehaviour must match the exact .cs filename, including case sensitivity. If the file is named PlayerHealth.cs but the code declares public class playerhealth : MonoBehaviour, Unity cannot associate the compiled type.
  • Compilation Errors Elsewhere in the Project: If any single C# script in your project contains a syntax error, Unity halts the entire compilation assembly. While compilation is blocked, Unity cannot link any scripts, making them temporarily appear as "missing" on GameObjects. Always resolve red compiler errors in the Console window first.
  • Corrupted .meta Files After Renaming: Renaming script files outside the Unity editor (in Windows File Explorer or VS Code) without updating the accompanying .cs.meta file breaks the internal 128-bit GUID link. Always rename scripts inside Unity's Project tab.
MissingScriptCleaner.cs (Editor Utility)
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

public static class MissingScriptCleaner
{
    [MenuItem("Khawajja Tools/Clean Missing Scripts from Active Scene")]
    public static void CleanAllMissingScripts()
    {
        GameObject[] allObjects = GameObject.FindObjectsByType<GameObject>(FindObjectsSortMode.None);
        int totalRemoved = 0;

        foreach (GameObject go in allObjects)
        {
            int count = GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
            if (count > 0)
            {
                totalRemoved += count;
                Debug.Log($"Removed {count} missing scripts from: {go.name}", go);
            }
        }

        Debug.Log($"<color=green>[Clean Completed]</color> Total missing scripts purged: {totalRemoved}");
    }
}
#endif