Hello I have the same issue. I’ve tried all the suggestions but it still wont work ![]()
No disrespect to anyone above, but the original issue is regarding a new script not being attached as a component. This likely is caused by an outdated editor.
If you have this issue, and nothing above resolves it for you, please try the following:
-
Navigate in the Unity Menu to “Window”
-
Select “Package Manager”
-
Make sure “In Project” is selected under “Packages”
-
In the "Unity Technologies section, look to see if all items listed there are up to date. You can tell if something is up to date because it will have a green checkmark.
-
If something is not up to date, it will have a circle with an up-facing arrow to the right of it. Click this, then install the update.
-
After waiting a few moments, navigate back to your script folder and delete the script that was causing the issue. (If you have data here you need, instead open it, copy and paste it into a new script)
-
Afterward select the Object/item/etc you wish to add the script to and drag the script to it. Or access the inspector and add as a component.
-
If the problem persists, make sure you have the latest version of unity installed.
I had this issue with a band new, empty script. I created in the Project window then got the ‘cannot find class’ window when I tried adding it to a gameobject. In my case since there was nothing in the script yet I simply deleted it and made a new one. The new one worked, go figure.
For me, it was caused by an error in another file. Weird.
Thanks, this worked !!
Hi everyone!
Seems like Unity does not like it when you rename the file (and or class) while it is referenced in other files.
I followed the ‘Ruby’s Adventure: 2D Beginner’ course and decided to rename my ‘Controller’ to ‘RubyController’ mid way through the course and got the exact same error.
No deletion, updating or anything helped.
What DID help:
Walk through every file with your socks off and find each and any reference to my old ‘Controller’ and replace it with ‘RubyController’. Hey presto! Suddenly Unity decided to like my scripts again and happily run along.
I hope that helps somebody!
Wild greetings,
Madweasel
Or, if you use the VS rename feature, you can rename all the values at once if they are properly referenced.
Well said. If I were a sane person I would do that.
This worked for me.
I am completely new to all of this and ended up having the same problem. Tried a lot of the above and nothing worked except for one post that said it was an error on another script. On closer inspection, I noticed errors on a script I created for ‘wheels’ from a tutorial I was following. Once those errors were corrected (my fault for typos) I could add scripts like before.
I wasn’t able to attach any scripts to anything just now. I had a couple scripts open in vs code from another project which I was referencing and once I closed out of those everything seemed to be fine again.
I recently started unity and when i type simple code such as Debug.Log(" hello ");
it says error too many characters in character literal and when i drag the script to my player cube it dosent work s help
No, the error you quoted here means you had used something like this ' hello ' instead of this " hello " The single quotes denote a character literal and not a string literal. A character literal defines a single char value. Some char values require an escape sequence but still denote a single char. For example '\n'. This is a single line feed character. Strings are sequential arrays of chars. You can read individual chars of a string like in an array:
string myString = "Hello World!";
char c = myString[6]; // c will contain 'W'
As it was said countless of times, if any of your code contains syntax errors, none of your code will be compiled. If your code is not compiled properly you can not use it. So make sure you don’t have any syntax error in your Unity console.
If you need further help, please do not hijack other ancient threads. Create your own thread and include your code that doesn’t work. Note when posting code you have to use code tags here in the forum. There’s a sticky thread in this subforum explaining how.
Though before carrying your issue to the community, make sure you put some efford into solving it yourself. Note that while the scripting forum is for any questions regarding scripting in Unity, it’s generally not meant to answer basic C# syntax related questions. This is not a tutoring platform for learning basic C#. Imagine the difference between a poetry class and an english class. In a poetry class a student would not expect to learn basic english. Programming languages are like normal human languages. Though they generally are much simpler but also have zero tolerance for errors. While everyone can understand Yoda’s messed up grammer, a computer does not understand you, if you don’t use proper syntax and grammer.
I had the same error but turns out my main class in the c# script was different from the filename itself. Please check that. Please check the photo for correspondence.
Got it too, and I solved it by upgrading to 2020.2.3. Great!
But when i made a new script component inside inspector it also not work
thank you good sir i just looked how to fix this and you saved me
Everyone, Every errors(the number of error is zero) need to be corrected

