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.
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.
Things to try:
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.
I appreciate your answer but public datatypes used in
FPSController
all is gone and other scripts also have reset the data I entered in unity Editor's inspector window.If #3 is your last resort then you have to manually do it. Unless you have the old project, there is really nothing you can do other than recreating and re-assigning them yourself. I know it sucks but I always tell people to do variable initialization via script and this is why. Sometimes, scene can go crazy due to an update or crash. If the initialization such as variables and script attaching is done via script then all you have to do is drag the script to another folder then drag it back.
It happens. You don't even have to update Unity for that to happen. I think you should take my advice and start attaching scripts from scripts. This will save you time in from having the-same issue in the future. Always make a copy of the project before updating it. This is a must.
@Confused Yes. Instead of dragging and dropping the script on a GameObject which is easier. you should create a script named
ComponentInit
that is attached to an empty project. That script you should use to find GameObjects then attach the necessary scripts to them. This is true especially when you have large project. For example,GameObject shipObj = GameObject.Find("Ship").AddComponent<ShipScript>();
.Oh Thanks that is important it is the first time I see
.AddComponent
That would be much handy.