Unity3d no Monobehaviour scripts in the file, or their names don’t match the file name

Make sure your script file is named exactly as the MonoBehaviour class it contains.

MyScript.cs:

using UnityEngine;

public class MyScript : MonoBehaviour
{
}

Also, if your script file contains helper classes, make sure they are placed on the bottom of the file, never on top of the MonoBehaviour subclass.

Also, Unity will sometimes have problems when your MonoBehaviour classes are in namespaces. I don’t know when exactly this happens, it simply does every now and then. Taking the class out of a namespace fixes the error.

Leave a Comment