Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by juliang · May 10, 2013 at 08:50 PM · compiler error

can't add script, Unity says class name doesn't match

Trying to put a script on an object, Unity refuses with:

Can't add script RingPlaneController. The scripts file name does not match the name of the class defined in the script!

The script is in a file called RingPlaneController.cs - here are the first few lines

 using UnityEngine;
 using System.Collections;
 
 public class RingPlaneController : TVWMeshGenerator {

TVWMeshGenerator subclasses from MonoBehavior

Since the filename does in fact match the class name, the error message must mean something else, but what?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rutter · May 10, 2013 at 08:55 PM 0
Share

Hmm... check capitalization? You might try copy-pasting both names into another text editor or diff tool, just to be sure that they're exactly the same.

6 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by icemacsea · Sep 11, 2014 at 02:16 PM

I just ran into this problem with javascript script. There's no way to get the classname wrong on a .js script, because the compiler just takes the name of the script as the classname! So I knew that it was something else. In my case, it turned out to be a C# script that wasn't compiling because of an error. Once I deleted that script, I was able to add my .js script to a gameObject with no problem.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Jessy · May 11, 2013 at 02:02 AM

You spelled MonoBehaviour with the American spelling; i.e. no u.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image juliang · May 11, 2013 at 07:42 AM 0
Share

Ha ha. But I'm compiling here in Silicon Valley, so it still counts.

avatar image Jessy · May 11, 2013 at 01:35 PM 0
Share

If you're actually using "$$anonymous$$onoBehavior", it's not going to compile. I know of several issues that cause this problem, but unless you edit your question to show that this simple fix isn't the problem, I won't offer anything. What you've written so far is confusing because of spelling. Also, use namespaces. The Asset Store is full of packages with these stupid initialisms.

avatar image juliang · May 15, 2013 at 07:27 AM 0
Share

Whoa, you're right! That spelling thing is just the kind of thing that slipped by an American. What's even more strange is that like probably most people, the script was set up by copying and pasting from other scripts. That script was actually a month old, I wonder how it ever got through. So thanks, fixed that, but - the problem persisted. After more work, I'm convinced it has to do with all the temporary files Unity generates. I made a simple edit to the script to force a recompile and then Unity was happy. I've tried it a couple more times, and each time forcing a recompile got rid of the problem.

avatar image
0

Answer by shroge · Sep 03, 2014 at 05:14 PM

I ran into the exact same problem, however, I had no MonoBehavior/MonoBehaviour spelling issues, the names were in fact identical. It seemed to stem from creating a script from the asset panel. I was following this tutorial: https://www.youtube.com/watch?v=7GgbblB2Hmo#t=16 and when I got to the 2 min mark (I was following the exact click, drap, drop sequence that the tutorial showed) I received the same Class Name Doesn't Match error.

My fix was to simply restart Unity and it worked fine after that. This leads me to believe that there was some temp file messup on Unity's part.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by SamTam · Feb 26, 2016 at 08:19 PM

Hello guys, i have read all you're problem's, and i wanted to help you guys. Read this carefully. First off look at the console and look if there are any errors(if it hasn't got any errors than look at the last script that you made, that one before the error). Then open the script and (Ctrl + A) copy it and then make a new text folder on you're desktop(or anywhere as long as you can find it) on the text folder paste the hole script, then save it. Go back to Unity and then delete the hole script(make sure you pasted it on the text folder) and then make a new one (if it's a C# script make sure to name it the same as you're last script, the one you coped) paste it in the script and then save it. It works for me.

I really hoped i helped you.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by MrBadDragon · Mar 08 at 09:45 AM

Error message means that the name you have saved the file under does not match the class name.

Class MyClass needs to be saved in a file MyClass.cs

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Compiler errors when opening unity 0 Answers

All scripts come up with compiler errors 3 Answers

Compiler errors 2 Answers

Destroying a wall after collecting X amount of items? 1 Answer

Making script object without declaring script name 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges