Как исправить ошибку can t add script
Reproduction steps:
1. Create a new script.
2. Change the filename of that script.
3. Add script to an object in the scene.
Expected error message: «Can’t add script component ‘NewBehaviourScript’ because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.»
Actual error message: «Can’t add script behaviour VisualContainerAsset. The script needs to derive from MonoBehaviour!»
Reproduced: 2018.1.0a5, 2018.1.0f1
Not reproducible: 2017.1.3p1, 2017.2.1p3, 2017.3.1f1, 2018.1.0a4, 2018.2.0b1
Cant add script component. Script Class cannot be found.
It’s a bit difficult to diagnose without seeing your code and directory structure of your Scripts folder, but I would start by double-checking that the script file and the class inside it are both named «RandomSoundPlayer» without any typos and that the class compiles without errors.
bryson thornton
bryson thornton
thanks. it worked
Tojo Alex
Tojo Alex
thanks i had same issue
Posting to the forum is only allowed for members with active accounts.
Please sign in or sign up to post.
Can't add script component because the script class cannot be found?
Yesterday I updated unity from unity5 to 2018.2.2f1. Unity scripts are not loading after Update 2018.2.2f1.
Once I try to play the Scene the scripts are not loaded and I can’t add the script again it gives this error:
Can’t add script component ‘CubeScript’ because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.

![]()
![]()
12 Answers 12
If you still have the old copy of the project, upgrade the Unity project to Unity 2017 first then to 2018.2.2f1.
Here are the few possible reasons you may get this error(Ordered from very likely)
1.Script name does not match class name.
If script name is called MyClass , the class name must be MyClass . This is also case-sensitive. Double check to make sure that this is not the issue. To make sure that’s not the issue, copy the class name and paste it as the script name to make sure that this is not the issue.
Note that if you have have multiple classes in one script, the class name that should match with the script name is the class that derives from MonoBehaviour .
2.There is an error in your script. Since this is an upgrade, there is a chance you’re using an API that is now deprecated and removed. Open your script with Visual Studio and see if there is an error there then fix it. There is usually a red line under a code that indicates there is an error.
3.Bad import with the Unity importer and its automatic upgrade script.
A.The first thing to do is restart the Unity Editor.
B.Right click on the Project Tab then click «Reimport All»
C.If there is still issue, the only left is deleting the problematic script and creating a new one. There is an easier way to do this if the script is attached to many GameObjects in your scene.
A.Open the script, copy its content into notepad.
B.From the Editor and on the Project tab right click on the script «CubeScript», select «Find References In Scene».
C.Unity will now only show all the GameObjects that has this script attached to them. Delete the old script. Create a new one then copy the content from the notepad to this new script. Now, you can just drag the new script to all the filtered GameObject in the scene. Do this for every script effected. This is a manual work but should fix your issues when completed.
How to solve «Can’t Add Script» in Unity
In this article we look at the causes of the «Can’t Add Script» error in Unity in order to understand why it occurs and identify what actions to take to fix it.
Dear reader
In the channel there lots of videos about Blender, Unity and programming
in which we solve different problems and we provide useful information on these topics.
In the following video you can see a brief description on how to solve the «Can’t Add Script» error in Unity:

ABOUT THIS VIDEO
In this video we see how to solve «CAN’T ADD SCRIPT» error in Unity through code.
HERE MY UNITY PLAYLIST

Why do the «Can’t Add Script» Error occur in Unity?
This error in which we are not allowed to add a Script or component to a GameObject can arise for two reasons.
Case 1: The name of the script and the name of the class it defines do not match
The first one is that the name of the Script, that is to say, the name of the file with extension «.cs» does not match the name of the programming class that is defined inside it. This usually happens when we create a Script and then change the name of the file without doing a Refactoring process.
To solve this problem first we must identify the Script that has conflicts, this can be done with the information provided by the «Can’t Add Script» error window that appears when we try to add the Script with conflicts to a GameObject. If you do not remember which Script produced the error, you can create an Empty GameObject and start adding each of the Scripts until the error appears.
Once we know which is the Script that generates the «Can’t Add Script» error, we open it and we locate the part of the class definition, which begins as follows:
public class NameOfTheClass …
The name of the class is the name that has to match the name of the file, so what you can do is modify the name of the class to match the name of the file, or modify the name of the file to match the name of the class.
Once this problem is solved it will be possible to add the Script to a GameObject. If you need to rename the Script the best way is to right click on the «NameOfTheClass» name and then click on «Rename», this will make Unity modify that name in all the places where that Script is used.
I can't add script in unity
I’m a beginner in unity so I got this problem. Here is the script:
I don’t know why but it keep saying that Can’t add script component ‘Player control’ because the script class cannot be found.Make sure that there no compile errors and that the file name and class name match.
![]()
3 Answers 3
Check the file name of the script and make sure it’s the same as the class name. I’ve had this problem before after renaming a script through the editor.
Old question, but I solved this problem using the Help menu and then Reset Packages to defaults.
You either have a compile error in this script, or you have one in a different script. If this is the first time you’re trying to use this script, the entire solution needs to compile before Unity knows about this new class you’re introducing.
Locate your error and correct it before trying to add this script. It could be a compile error or something like a name mismatch like SanSolo suggests.
![]()
You must log in to answer this question.
-
The Overflow Blog
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.3.11.43304
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.