no monobehaviour scripts in the file or their names do not match the file name

Hi. Everytime I write a script this message shows in the top of the inspector while I have the script selected : no monobehaviour scripts in the file or their names do not match the file name.

This image is not mine but I have the same problem as the one in the image.
And when I attach the script in the image it says :

But instead of saying missing it says None (Mono Script)

Also the problem is not that the asset file and class name do not match. They do match, so its something else.

The images are not mine!

You have a mismatched class/file SOMEWHERE in your project. Unity in their infinite wisdom show that warning above every script, not just the one that has the problem. So you need to dig into any scripts you may have changed recently and find the mismatched one. Did you rename anything recently?

Can you show the code for the boxmove class? You’re sure you didn’t name your class BoxMove, or something other than exactly “boxmove”?

Yep. The names are the exact same.

Thank you! I will look at the scripts and see. How will I be able to find the mismatched file/class. Like will the names just be different or something? (I’m sorry for not knowing, i’m new to unity)

Check all of your scripts. The class name should match the filename. For example a class called PlayerController should be in a file named PlayerController.cs. Make sure that’s true for all of your scripts.

I’m pretty sure the capitalization of all the letters has to match perfectly too.

Thank you so much. You can’t believe how helpful you are. I’ve been trying to find the solutions for 2 days straight and I had started losing faith.

Hi. I checked all of them and they all have the same name. There are some scripts that have the same name. Could that be the problem? I mean like I have 2 scripts that share the same name.

Yes that’s a problem. Isn’t Unity giving you a compile error about that?

It is giving me an error but when I looked it up they said that it was nothing and that it would go away after a day and that it’s just a bug. And also I could play the game fine without it saying fix any errors before you play. Thank you I will go fix it now!

Hi!
It is a problem in my unity editor that I have written the same file name and the class name but it also shows that error like no MonoBehaviour script that have added in the asset(the script) this thing made me full pressurize and worried about that. I am working on a Junior Programming Project and I am also a beginner.
What should I do?
IF YOU HAVE ANY SOLUTION THAT WILL MAKE ME WORRY FREE THEN TO SHARE THAT INFORMATION EARLY AS POSSIBLE. with me.

Early to share with me this problem to fix that worryful headache.

Do you have any compile errors in your Console? Does the game run anyway? When did this start, you already have several scripts in this game.

There are just project scripts, not the others.
I just want to add the script to that car but I is not working due to that Monobehaviour problem.
This is just awful. I really want to debug this error.
Do you have any solution?

You should always have the Console window open while working in Unity - to help you identify both script errors and asset problems.

You can open it from the menu - Window > General > Console.

Once you have that open you should be able to see if there are any other issues - could be you have an error in an unrelated script causing this one to not work correctly.