Как исправить ошибку can t add script
Текущее время: 30 апр 2024, 11:22
can’t add script component
Форум для самых маленьких, а так же тех, кому недосуг читать справку самостоятельно.
Сообщений: 3 • Страница 1 из 1
can’t add script component
haawkeey 06 май 2019, 12:59
Добрый день, при попытке добавить скрипт на GameObject выскакивает ошибка:
«Can’t add script component ‘Head’ because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.»
Я так понял, что юнити ругается на не соответствие названия скрипта и класса, хотя название скрипта и класса совпадают.В чем может быть причина?
редактор кода Visual studio 2019
юнити последняя версия
haawkeey UNец Сообщения: 1 Зарегистрирован: 06 май 2019, 12:34
Re: can’t add script component
1max1 06 май 2019, 13:11
Не наследуется от MonoBehaviour
1max1 Адепт Сообщения: 5505 Зарегистрирован: 28 июн 2017, 10:51
Re: can’t add script component
AngryCat 08 май 2019, 21:27
Как написали выше, смотри, чтоб в название класса было написано «НАЗВАНИЕ_КЛАССА : MonoBehaviour». И еще. Не забывай, что название скрипта не может содержать пробелов!!
Здесь могла бы быть ваша реклама.
AngryCat Старожил Сообщения: 716 Зарегистрирован: 20 июл 2018, 22:29 Skype: Дискорд — Флеш#4099
Сообщений: 3 • Страница 1 из 1
Кто сейчас на конференции
Сейчас этот форум просматривают: Yandex [Bot] и гости: 13
- Список форумов
- Техподдержка • Наша команда • Удалить cookies конференции • Часовой пояс: UTC + 3 часа
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Русская поддержка phpBB
проблема с unity. ошибка: Can’t add script
ошибка: Can’t add script component ‘Player’ because the script
dass cannot be found. Make sure that there are no
compile errors and that the file name and class name
match.
также пробовал новый скрипт но он тоже не хочет работать
Дополнен 4 года назад
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
// Start is called before the first frame update
void Start()
// Update is called once per frame
void Update()
Лучший ответ
В Unity обязательное требование, чтобы имя файла скрипта было точно
таким же, как имя главного класса в скрипте.
Проверьте совпадают ли у вас эти имена.
В скрипте у вас имя главного класса PlayerController, а файл скрипта
наверное имеет другое название.
На фото пример (как должно быть) с именем KEY.
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.

124k 22 22 gold badges 240 240 silver badges 331 331 bronze badges
asked Aug 6, 2018 at 18:18
971 3 3 gold badges 16 16 silver badges 38 38 bronze badges
unity5 to 2018.2.2f1 is a big jump. It would have been better to do unity5 to 2017 then 2018.2.2f1 to reduce the chances of issues arising in the updated project. Where is the «CubeScript» placed in your project?
Aug 6, 2018 at 18:24
@Programmer It is in my assets in a folder _scripts and I opened it from the assets and the script opens as usual in monodevelop.
Aug 6, 2018 at 18:26
There is a floder Packages next to Assets do I have to do something with it? @Programmer
Aug 6, 2018 at 18:30
That is totally not professional I want another solution
Aug 6, 2018 at 18:41
My Project Is so big and i can’t go to every folder and do that manually is there any way better than this
Aug 6, 2018 at 19:01
14 Answers 14
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.
Can’t add script

Добавил в ассетс код, который позволит мне управлять персонажем. Пытаюсь перетащить на перса код, а он мне выдаёт ЭТО. Что ему надо от меня?
Can’t add component because it doesn’t exist. Check to see if the file name and class name match.
Невозможно добавить компонент, потому что он не существует. Проверьте, если имя файла и имя класса матча.
Ответ
ehnaton — 15 фев. 2015
Этот комментарий был скрыт. Нажмите, чтобы развернуть.
sleep, в коде скрипта есть строчка в начале
public class classname : monobehaviour,
где classname — имя класса и оно должно совпадать с учетом регистра с именем файла — classname.cs.