TIP: Error when renaming scripts! "Script class cannot be found"

I’ve bumped into this more than once…usually when I double click on the name of a script file to change it … so in the first image I changed the file name from splash_timer to SplashTimer. No biggie right? Except when I try and drag it onto a game object I get a big fat error. (see pic)

The PROBLEM is that I have renamed the script but not the class (which the error message clearly tells us this but who reads those silly messages!?) … the class name is now out of sync with the script name and Unity hates that. Simply open the script and change the class name to the name of the script and viola! (see pic #2 )

image

image

If you are using Visual Studio, there is a feature that allows you to change the name of the class from within Visual Studio, and have VS also change the file name for you. At least I think standard Visual Studio can do this. I use the ReSharper plugin and it’s a feature in it, but a few of ReSharper’s features are just enhanced basic VS features.

This feature is VERY useful when referencing the script in other scripts because it will also make sure anything using the script will have the new name updated throughout the project.

Privacy & Terms