Can't Add Script Component 2019.3

I keep trying to move a newly created script into an object, but it keeps saying this every time I try this.

“Can’t add script component because the script class cannot be found. Make sure there are no compile errors and that the file name and class name match.”

The class and file name match and there are no compile errors because I have the default script in. How do I fix this?

Hello,
here are a few checks to do:

  • The script must inherit from MonoBehaviour
  • FileName.cs for FileName class. It is case-sensitive !
  • Maybe paste your code ?
  • Try to create it directly from Add Component… does it do it again? Reboot Unity. “When in doubt, reboot”
1 Like

My code is just

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
       
    }
}

default stuff.
Also I cant find anything on how to reboot unity how would I be able to do that? Just uninstall and reinstall?

Nah, sorry, sometimes just closing it and relaunch when things are way weird do the trick.
But… is the file really called NewBehaviourScript.cs ?

2 Likes

Yep file name, script name, and class name are all the same.
I already relaunched it, deleted it, re-downloaded it, and nothing changed so I’ll just create a new project, move all of the assets there, and see how it goes.

Moved it to a new file. No problems

Nevermind