Unity3d no Monobehaviour scripts in the file, or their names don't match the file name
Hello everyone I’ve been working on my first game and suddenly I got this error and cannot run the game, I already installed the new version of unity but it persists. I see it can be caused for several reasons but had no luck so far, do you know the most probable causes and how to fix it?
When I select the scripts the only one where I do not get this error is the following:
But for example here I get the error:
And so on with every other script.
I’ve already installed a newer version of unity3d, uninstalled the antivirus, checked the file names but the error persists. I also do not have any class in a namespace..
2 Answers 2
Make sure your script file is named exactly as the MonoBehaviour class it contains.
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.
I had a strange variation of this issue, and did not see the solution posted anywhere else online.
TLDR
I had whitespace in the namespace for the classes which Unity could not identify as MonoBehaviours.
Background
I had the No MonoBehaviour scripts in the file or . warning text on two script files in my project, one a MonoBehaviour, and the other a ScriptableObject. Each issue had different symptoms:
MonoBehaviour
- The MonoBehaviour class was named like MyMonoBehaviourService .
- The script file was named MyMonoBehaviourService.cs
- The class was not partial, it had no nested types, nor any other types defined within the file.
- I could not attach MyMonoBehaviourService to a GameObject via the inspector, but I could via gameObject.AddComopnents<MyMonoBehaviourService>() . This resulted in the script attached to the object, looking and behaving correctly.
- Upon entering PlayMode, I would get the error: The referenced script (Unknown) on this Behaviour is missing!
- After exiting PlayMode, the GameObject with the MyMonoBehaviourService attached would now say that it was missing.
Scriptable Object
- The ScriptableObject class was named like MyScriptableServiceData .
- The script file was named MyScriptableServiceData.cs .
- The class was not partial, it had no nested types, nor any other types defined within the file.
- I was able to create a MyScriptableServiceData via C# and save it using the AssetDatabase .
- I was then able to see and modify the properties using the inspector.
- Upon exiting and re-opening the project, the asset would say that its script was missing.
Resolution Strangely enough, the issue was actually whitespace in the namespace for each class. I mistakenly thought I was seeing word-wrapping but actually, there was a newline in the namespace.
needed to be changed to this:
I’m not sure why this causes an issue with MonoBehaviour/ScriptableObject detection but it really took a while for me to uncover.
No monobehaviour scripts in the file как исправить
Reddit and its partners use cookies and similar technologies to provide you with a better experience.
By accepting all cookies, you agree to our use of cookies to deliver and maintain our services and site, improve the quality of Reddit, personalize Reddit content and advertising, and measure the effectiveness of advertising.
By rejecting non-essential cookies, Reddit may still use certain cookies to ensure the proper functionality of our platform.
For more information, please see our Cookie Notice and our Privacy Policy .
Unity: empty errors and No Monobehaviour scripts in the file…
Cразу при запуске у меня в консоли стали отображаться так называемые empty errors — пустые ошибки.
Empty errors in Console
Эти ошибки не стираются и по ним никаких данных редактор не отображает.
Но самой досадной ошибкой стал глюк Unity, при котором все создаваемые скрипты автоматически помечались сообщением — «No MonoBehaviour scripts in the file, or their names do not match the file name«.

Я начал искать способы решения проблемы в Яндекс. Перепробовал много всего ( и смену локализации, и переименование каких-то файлов, и чистку в системе с последующей переустановкой и т.д.), но ничего не помогало.
Тогда я просто тупо открыл логи Unity и начал оттуда выписывать все ошибки, а потом проверять их в Яндексе.
В итоге я наткнулся на интересную статью, где описывалась ошибка «Failed to create CoreCLR, HRESULT: 0x8007001F on MacOSX«. В ней описывался баг, который возникал при запущенной Parallels Desktop. Оказывается, при запуске этой программы все команды dotnet в консоли вызывают ошибку и не работают. При закрытии Parallels Desktop и остановке всех её процессов в системе dotnet оживал и никаких ошибок не возникало.
Я проверил это в своей системе и увидел аналогичную картину. Дело в том, что я активно пользуюсь Parallels Desktop в режиме Coherence, при котором все приложения Windows 10 становятся как бы частью Mac OS. Это очень удобно.
Я закрыд программу Parallels Desktop, затем открыл запущенные процессы в Mac OS и убил там процесс Parallels Desktop (да, при закрытии программы всё равно висят некоторые процессы).
После этого Unity запустилась без ошибок Надеюсь, Вам это поможет, если Вы столкнулись с аналогичной ошибкой в Unity, запущенной в Mac OS.
В файле нет сценариев моно-поведения. имена ДЕЙСТВИТЕЛЬНО совпадают
У него ДЕЙСТВИТЕЛЬНО такое же имя, и, насколько мне известно, я все делаю правильно. Это единственный сценарий в проекте. Пробовали в других пустых проектах, искали везде. Не понимаю, почему он выдает эту ошибку. Кто-нибудь может сказать мне, как это решить? РЕДАКТИРОВАТЬ: вот ошибка консоли: 
1 ответ
Поскольку я не мог легко найти ответ, на случай, если кто-то наткнется на это, вот как это было решено.
Перейдите в «C:\Program Files\Unity\Hub\Editor\2019.2.14f1\Editor\Data\Tools\RoslynScripts»