• Register
1 vote
2.1k views

Problem :

I am very new to unity. Recently I had updated my unity from the earlier unity5 to the current 2018.2.2f1. And after that update my Unity scripts are not at all loading. I had also tried to play my Scene but my scripts are not at all loading and I am unable to add my script again it shows me below 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.

I have already wasted a lot of my time on fixing above error but still unable to fix it so looking for the expert help who can help me in fixing my issue in less time.

8 5 2
3,230 points

Please log in or register to answer this question.

3 Answers

2 votes

Solution :

I also had the same problem which you have mentioned above and below is my method to fixed it :

Firstly you need to click on your Console then you will see the blank error. It is the Editor bug, and you can still see your Editor Log by selecting your console's window dropdown and after that you need to select the Open Editor Log. My problem was that the "Tools\Roslyn\csc" was missing it is very important as it is the something that Unity will always use to compile your C# files. So to fix it I simply opened the below one:

C:\Program Files\Unity\Hub\Editor\2019.2.14f1\Editor\Data\Tools\RoslynScripts\unity_csc.bat 

And after that I added the ".exe" to below line 

"%APPLICATION_CONTENTS%\Tools\Roslyn\csc" /shared %*

Above line must now be : 

"%APPLICATION_CONTENTS%\Tools\Roslyn\csc.exe" /shared %*

Now it works perfectly after making above changes.

8 4 1
5,680 points
help in optimizing your site for search engines
<a href=https://kwork.com/optimization/13215554/fast-seo-website-promotion>website promotion seo</a>
1 vote

Solution:

Here are the few possible reasons you may get this error

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.

  1. Open the script, copy its content into notepad.

  2. From the Editor and on the Project tab right click on the script "CubeScript", select "Find References In Scene".

  3. 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.

The problem was that "Tools\Roslyn\csc" could not be found, something that Unity uses to compile C# files.

I opened C:\Program Files\Unity\Hub\Editor\2019.2.14f1\Editor\Data\Tools\RoslynScripts\unity_csc.bat and I added ".exe" to the line "%APPLICATION_CONTENTS%\Tools\Roslyn\csc" /shared %*
This line should now be : "%APPLICATION_CONTENTS%\Tools\Roslyn\csc.exe" /shared %*

Now, it should worked perfectly.

10 6 4
31,120 points
1 vote
problem fixed here : https://youtu.be/dx35_RNnJEQ
0 points
Thanks a lot for the link it really helped.

Related questions

0 votes
1 answer 3 views
3 views
Problem: Once I try to play the Scene the scripts are not loaded and I can't add the script again it gives this error.
asked 2 days ago salim1 60.6k points
0 votes
1 answer 3 views
3 views
Problem: 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.
asked 2 days ago sumaiya simi 43.9k points
0 votes
1 answer 5 views
5 views
Problem: I have project in Unity and also new to C#. Problem is that I got error The script needs to Derive from MonoBehaviour. I understand what does that mean but when I use MonoBehaviour I'm getting tons of Errors like this: Errors in console ... : BaseWindow { public UIGuideWindow() { //mScenesType = EScenesType.EST_Login; //mResName = GameConstDefine.UIGuideRestPath; //mResident = false; }
asked Apr 24 Humaira ahmed 50.7k points
0 votes
1 answer 58 views
58 views
Problem: Any idea how do I fix this error: The associated script cannot be loaded. Please fix any compile errors and assign a valid script. Thanks
asked Mar 16 ummesalma 29.2k points
0 votes
0 answers 1 view
1 view
Problem: Please can anyone tell me the right procedure to do it? Unity check if gameobject has component
asked 3 days ago Ifra 34.7k points
0 votes
1 answer 2 views
2 views
Problem: I'm new to Unity and I've been trying to test the scene with the script attatched to a character. However, it keeps saying "The associated script cannot be loaded. Please fix any compile errors and assign a valid script."
asked 3 days ago Moumita Bhowmick 12.4k points
0 votes
1 answer 25 views
25 views
Problem: I am creating an editor script for a certain type of component script, I'd like to access the specific component script referenced by that instance of the editor script.
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 64 views
64 views
Problem error building player because scripts have compile errors in the editor
asked Feb 11 charles mathews 5.5k points
0 votes
1 answer 48 views
48 views
Problem: Can someone help, How to fix &ldquo;Can't Play a Disabled Audio Source&rdquo;? Any help is appreciated :)
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 17 views
17 views
Problem invalidcastexception: cannot cast from source type to destination type.
asked Feb 11 charles mathews 5.5k points