Can’t add script component...

Got the same error today, but it also said something along the lines of “Can your Unity install be corrupt?” So, if you just updated your engine, the install might be corrupt. If you did not, I do not know the reason.

Do you also need to download MonoDevelop on your pc or is that already in Unity?

This seemed to work for me! Thanks!

Edit: Having the same problem. Different script, and I used the same solution. Didn’t work. Feels like the error is getting smarter; every time we fins a solution it ‘evolves’ so that the solution doesn’t work anymore.

Edit 2: Just noticed that in the inspector the script has a speech bubble (noob coding language terms here) saying ‘No MonoBehavior scripts in this file, or their names do not match the file name.’

1 Like

Ive been having the same problems. I have no idea what to do as i have just started with unity. Please help me.

I tested by just creating a c# script i named it “Test Script” and dragged it into my player as a new component. It now displays the message, “Can’t add script component ‘Test script’ because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.” What do i do now?

1 Like

If you named the script “Test Script” then you may have an issue because class names can’t have spaces. I’d make sure your class name doesn’t have a space which could also lead to compiler errors.

1 Like

I was curious what happens when you create a script with a space as I’d never done it. So here it is. As you can see, the script is created with a space, but in the code it doesn’t have the space. It then says at the top, no MonoBehaviour scripts in the file or their names do not match. No compiler errors were thrown, but as suspected, you can’t add the script to a gameobject as it can’t find it due to the name mismatch.

3 Likes

Ok I am pissed really. So the standard assets are fracked really, the editor folder cause problems, so I moved that away from the standard assets, then I accidentally created a script in that piece of shit editor folder and moved it away and bam every script I have made stopped working.

I have been coding for 15 years so don’t give shite like your names don’t match or you can’t have spaces ok, I have been working on this project for 4 months now and my progress is fraking wasted.

I seriously want to drinik the blood of the guy responsible for this!

2 Likes

First, we understand you are upset, but being upset on the forums just to complain will not get you any help.

Second, I’ve been coding a lot longer than you. Unity does have a few of it’s own quirks and no matter how long you’ve been coding, I doubt you’ve written perfect code every time. I sure as heck haven’t.

Third, if you want help, ask for help instead of trying to attack people who could potentially help you even before you try to get help, because I seriously doubt your work is wasted.

And of course, as long as I’ve been coding, the best thing I ever did was start using source control. In the world of programming, there isn’t such a thing as “everything always goes right”. So the ability to roll back or access a previous commit is invaluable.

6 Likes

Yeah you ain’t helping. How can you, I see this thing persist since version 5 in various manifestations. Hey Unity-chan Instead of tech dem…erm fmvs try making a game once in awhile, you may find why your stable versions are not so stable after all.

This is so unnecessary. It’s 2020 (edit… 2022!)… please join us and install and use source control. Unity3D works really well with git and that combination saves my bacon almost every single day. Once you start using source control, your actual productivity goes up because you can fearlessly rip-tear-shred to try stuff and see how it goes, knowing you can always roll back. It is the ultimate peace of mind.

EDIT to add my “standard source control blurb:”

I’m sorry you’ve had this issue. Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

As far as configuring Unity to play nice with git, keep this in mind:

https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

Here’s how I use git in one of my games, Jetpack Kurt:

https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

Using fine-grained source control as you work to refine your engineering:

https://forum.unity.com/threads/when-to-make-a-separate-object-or-class-script-help-me-think-like-a-programmer-example-in-text.1048739/#post-6783740

Share/Sharing source code between projects:

https://discussions.unity.com/t/719810/2

Setting up an appropriate .gitignore file for Unity3D:

https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

Generally setting Unity up (includes above .gitignore concepts):

https://thoughtbot.com/blog/how-to-git-with-unity

It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.

“Use source control or you will be really sad sooner or later.” - StarManta on the Unity3D forum boards

6 Likes

If I delete this folder, won’t it also delete my packages? I’m already facing different issues with Cinemachine and Probuilder components.

And which framework does the newest version require, anybody know? New is to say, 2019.5.1f1

Felt like telling you thanks, because that’s the exact solution I needed!

1 Like

Just solved my problem, If you name your folder scripts or script change that now. mine is working after renaming it to f**kton

3 Likes

I had a similar problem. My problem was, one of my scripts was in plugins folder, and i was trying to access another script into that script which was not in Plugins folder… So moving that script out of Plugins folder solved my problem.

I was trying for ages to find the issue and this was it thanks!!

1 Like

problem fixed here :

6 Likes

I’ve already tried that it doesn’t work. I did move unity in a different hard-drive and visual studios in a same hard-drive. Now i’m having this problem too. I have copied pasted and reinstalled and uninstalled. Right now I am uninstalling everything and moving it to the original hard-drive I was using. I’m going to see if that solves my problem. What good is unity when you can’t make any simple scripts work?

2 Likes

I’ve gone through this whole thread looking for help on this problem, I’m just about to give up!! This is torture! Lol

1 Like

I don’t know if anybody else is having this problem, but after looking around online some more, someone suggested uninstalling from the package manager, “Rider Editor”, I deleted it and it automatically fixed all compiler errors, all scripts are working without any adjustments to naming in the code!! I hope this helps, cause it sure as hell gave me a big relief!! :slight_smile:

1 Like