- Home /
No Monobehavior scripts in the file error after trying to rename a script.
I tried to rename a script file name rather than recreating it.
Now I have an issue where all of my scripts say in the editor "No MonoBehavior scripts in the file, or their names do not match the file name".
I suspect the Unity generated files and reference numbers (guid's) now don't match the .meta numbers for my .cs scripts.
Is there anyway to reimport all my scripts without recreating the entire project?
Or is another issue causing this? I'm quite sure there is nothing wrong with the scripts themselves as they were all working prior to me renaming the one script file.
Want to add. This is Unity 5 Personal 64bit on Windows 10 (Windows 8 compatibility mode).
Answer by tanoshimi · Aug 10, 2015 at 11:31 AM
Script filenames need to match the name of the class defined within them. So if you changed MyScript.cs
to MyNewScript.cs
, you also need to change public class MyScript : Monobehaviour
to public class MyNewScript : Monobehaviour
Not the issue. I have deleted the script I tried rena$$anonymous$$g and I am sure I renamed it correctly. Now every script on my project now has the error and I cannot add them to game objects.
If I do drag and drop my scripts onto the game objects I get "The associated script cannot be loaded", or it asks me to fix any compile errors before scripts can be loaded. Except there are no compile errors on the console, and all these scripts were previously working.
Answer by C4ptainZA · Aug 10, 2015 at 12:22 PM
I have solved this issue.
One of my scripts had a compiler error. Seems this can block the editor from recognizing new scripts but also the console posting the compiler error (possible bug).
I only realized when I deleted all my scripts and re-added them one by one to the project.
Answer by unity_r_Q4A19IbyMMAQ · Nov 21, 2021 at 09:21 AM
This happened with me recently. I know this must have already been solved for you but I just thought I'd spread word that I fixed it by making a blank script with the same name as the old script, then deleting the blank script.
Your answer
Follow this Question
Related Questions
How to rename a script file? 8 Answers
rename scripts 1 Answer
[Solved] Renaming game object clones instantiated 1 Answer
Reimport standard meshes in Unity? 1 Answer
Linking a file outside the Asset folder to update an asset on reimport 0 Answers