"No MonoBehaviour scripts in the file" error with -all- scripts

Hello,

I’m just getting started on this whole game development thing, so forgive me if this is a problem with a painfully obvious solution to more veteran eyes.

I have been running into this issue for the last couple days and it has really put a hamper on my drive to continue with Unity, since it’s preventing me from even completing the most basic of tutorials out there.

I first encountered the issue while attempting the 2D Roguelike tutorial from Unity Technologies - everything was smooth sailing until it came to using scripts. I followed the instructions in the tutorial videos to a T, but after saving my scripts and attempting to attach them to a game object I started receiving the ‘No MonoBehaviour scripts in the file’ error - searching for a fix I’ve tried everything I could find from making sure the name of the class matches the file name, making sure there were no compile errors, reimporting the scripts, restarting Unity, etc…I’ve even tried ditching the scripts I wrote while following along and re-creating them by copy/pasting the script from the tutorial page. Still have the same error.

Thought my issue might be with my desktop (Running Win 8.0), but the problem persists on a fresh install of Unity on my laptop (Running latest Win 8.1).

Decided to cut my losses and ditch the roguelike tutorial to instead tackle Brackeys’ platformer tutorial - one of the first steps is importing the Unity standard assets and I am having the same issue with those out-of-the-box scripts without even opening them in VS to fiddle with them.

I’m about at my wits’ end with this issue and any assistance would be greatly appreciated.
I didn’t bother including any of my code here since the issue persists across all scripts, even imported ones directly from the asset store.

Surely there is something I’ve just missed in searching out solutions for this issue.

Running Unity 2019.3.4f1, issue was also present on an earlier version of Unity on my desktop.

  • make sure your file bears the same name as the name of the class inside
  • check out if you have an intruding antivirus program meddling about
  • make sure you are using a default English keyboard character set (in terms of your OS settings, not literal keyboard)
  • try to find a similar topic, there are hundreds already, unfortunately all solutions have varying degrees in complexity, from complete beginner misunderstanding of how the setup works to operating system problems similar to what I described above
  • finally, give us an example of at least one MonoBehaviour class (use code tags pls) or make a scrshot so we can see something without reading too much into your insights which could be lacking
1 Like

So this is what he is referring to. Notice the caption in the error message. It is caused because the problem at the top right that is circled.

What is going on with your console errors? If any of those errors are compile errors, they all must be resolved before a compile can complete, and a compile must complete successfully before you can add any of the scripts to GameObjects. Otherwise it has no idea there is a MonoBehaviour class in the file because nothing in the script has been compiled.

1 Like

Ummmm… It doesn’t have any errors in the code. Does it need anything specific or special? OTHER than the public class being a MonoBehavior.

If it happens on two different computers with two different versions of unity installed, my first guess would be some kind of human error. Otherwise a lot more people should have the problem, even if it was Win8 exclusive.

However, from what you wrote you seem to have done everything correctly. The name of the file needs to match the name of the (first!) class inside of it, which also needs to be a Monobehaviour. Since you seemingly get the same error on a fresh install with only imported scripts, i think we can exclude human error. At least as far as Unity / Scripts go.

So if all of these conditions are met, there are two other reasons the problem may occur (at least two i can think of). First of all, if you have any compiler errors, you need to fix those before taking a closer look at any other problems. In a fresh project with only imported (thus most likely working) scripts from the asset store, there should not be any errors, however there are some cases in which Visual Studio (or whatever IDE you are using) and Unity are not properly linked, leading to problems. So when you look at the Unity console, are there any errors? Are there any errors remaining after clearing it? When you open a script, are there any errors (red markers or red squiggly lines) inside of them?

The only other thing i could think off, given all of the above, would be that it was an actual Unity bug. But then again… if it happened on different computers with different Unity versions, it would have to be a rather widely spread bug which should have been noticed before, so imho this seems very unlikely to be the case. Other than a problem between Unity and the IDE, it may also be some other program (which would have to be installed on both computers), causing the problem. This is getting rather specific, so you would have to look at other similar posts, like orionsyndrome suggested.

I have been experiencing the same problem for 5 days. I’m also going crazy. I uninstalled Unity, reinstalled, installed a newer version and then an older one, but nothing resolved. I scanned with an antivirus, used a program to search for malware, but nothing solved it. All scripts: “No Monobehariour scripts in the file”. I used Unity in the last few months and everything was ok, but now it doesn’t matter which version of Unity I install, none work, they all have the same error.

5601352--579451--unity erro 1.png

Start by creating a new project and then a single script. If the error persists then it’s the fault of the engine. If the error doesn’t persist then it’s the fault of your project.

If the fault is with your project the next step is to delete the Library folder for the project. The Library folder is a cache folder for increasing editor performance but it can be corrupted from time to time. It’s one of the first things you should check when a problem appears to be with your project.

If deleting the Library folder did not solve the problem the next step is to look at every script and verify that none of them have been corrupted. While it’s not very common it is possible for one single problem to cause every other script to fail compilation generating this error.

1 Like

I already tried all of that. Someone from Unity support answered me and gave me a solution:

  • Navigate to Edit> Project Settings> Player
  • Under the ‘Other Settings’ section set the Scripting Runtime Version from ‘.NET 3.5 Equivalent (Deprecated)’ to ‘.NET 4.x Equivalent’.

In my case, it was already on Net 4.0, so I changed it to Net 3.5 and that solved the problem. The error, which I consider to be a bug, is that Unity was incompatible with the C # version and was unable to notice this.

I didn’t mess with any settings, so I don’t know what made the change and caused the unavailability.

3 Likes

I was having a similar problem and it was driving me completely insane. I tried reinstalling, deleting solutions/Library, changing project settings. Nothing worked. What seemed to initially cause the problem was changing a single variable in a ScriptableObject class. Doing this suddenly rendered EVERY FILE in my project uncompilable, with the same message: “No monobehaviour scripts in the file…”

As it turns out, I had another script which referenced a variable that I took out of the previously mentioned ScriptableObject class, which caused an error. Fixing this then fixed every file. So the order was:

  1. Deleted var A from MySO.cs (every file is now broken)
  2. MyOtherScript.cs is now complaining because it references A (but doesn’t tell me in the console)
  3. Fix the reference issue and now all files compile.

So weird. SMH UNITY!

1 Like

that behavior is (relatively) normal and is essentially why this happens at all, but it is very hard to explain how this works to rookies.

basically if your assembly fails critically, you’re bound to have invalid errors reported in the console, the reason for this is extremely deep, and is likely outside of Unity’s scope. it’s probably because they can’t reliably determine the underlying reasons for the error, from their perspective MonoBehaviours simply cannot be found (because the assembly is broken or non-existent).

now it’s beyond me whether this can be fixed or what are the exact steps to reproduce. if you could nail the latter and the fix is feasible, maybe you should report that as a bug.

1 Like

Wish you the best of luck, however quite frankly this community wont miss people leaving such comments. I certainly understand how frustrating it can be to be stuck at a problem, but had you read / watched any of the sources you mentioned you would have known that reinstalling / updating Unity is not likely to be a solution. Unless you, for some reason, created a new account just to leave this comment, you also did not ask on the forum for help. So what good do you expect to come from your comment, which if effectively just you rambling about your own incompetence at solving problems or finding help? Not to be offensive, but maybe programming is not right for you if you throw the towel at the first problem you encounter.

3 Likes

I’m having the same trouble as you. does anyone know how to fix this properly

Try some other name than ‘new’, as that is a keyword in programming and likely not accepted as a class name. Dont forget to rename the file and class to the same name. For example ‘MyFirstScript’. Then see if the error still shows up.

I ran into this copying a simple flying object type script from a simple example I had written over to a new file from scratch. Turns out the script had a reference to an Animator object which I had not set up for my new sprite in my new file. Everything compiled filed but I got the “No Monobehavior” error. Removing that one line fixed the project.

I’m on 2020.2.5f1

Very easy solution. this video helped me out

1 Like

Thank you very much, I lost all placed objects, hours of meticulous object placing, and the player itself. Most of all, Unity still refuses to acknowledge the existence of MonoBehaviour. Next time, don’t suggest the deletion of the whole storage of the Unity project :smiling_face:

Not sure what you did, but you definitely did something wrong. The Library folder is a temporary cache. What you deleted was probably not the Library folder.

If you weren’t using source control or hadn’t backed up your project, that’s on you.

In any case, this error pretty much always pops up on the inspector of script assets, even if there’s nothing wrong. You only need to care if it prevents you from adding it to a game object.

1 Like