Can't Add Script (Can't add new ones NewBehaviourScript, can't even add old ones that work)

I created a new script and tried to assign it to my object. I’ve done this several times in this project, but suddenly could not. I tried adding old scripts that were already assigned to other objects, and get the can’t add script error. How is that possible? I didn’t change all of the old ones that no longer can be assigned.

I created a new script, changed nothing, and can’t add script. The filename matches the class.

Is this a bug? Or is there some newfangled thing we have to do? Thanks!!

Here is the code, I changed nothing:

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()
{

}
}

5045135--494828--error.PNG

Check the console window log for errors.

Make sure the red error button is enabled in the upper right.

Thanks.
Absolutely nothing worked for this, so I reverted to an older version and redid a few days work. Never ran into the same problem again, and can’t recreate it.
:confused:

1 Like

Ah well, it happens. As you gain more familiarity you’ll learn some more handy tips and techniques for this. Here’s a few of them:

  • you can try doing Reimport-All by right-clicking in the Project window. That generally triggers a full recompile.

  • in the Library directory there is a ScriptAssemblies folder you can delete, which contains the DLLs that Unity transiently builds. Sometimes those get wedged in a state that Unity can’t handle: shut Unity, delete the Library/ScriptAssemblies folder, reopen Unity.

  • if VS/Mono doesn’t open, you can blow away the .sln, .csproj and .userprefs files; Unity recreates them next time you edit a source file.

1 Like

Hey willdegra, what version of unity did you downloaded when you didn’t ran into the same problem?

Either you had errors in your project or broken cache. This message often arises when you added new class to a project wich have compilation errors or broken assebly cache. First can be fixed by just fixing those compilation errors, second can be fixed by closing the editor and deleting Library folder where all caches live. But second will reimport whole project so prepare yourself a cup of tea if it is big.

Does your script have the same name as your class ?