• Register
1 vote
1.8k 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
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 12 views
12 views
Problem error building player because scripts have compile errors in the editor
asked Feb 11 charles mathews 3.8k points
0 votes
1 answer 7 views
7 views
Problem invalidcastexception: cannot cast from source type to destination type.
asked Feb 11 charles mathews 3.8k points
0 votes
2 answers 628 views
628 views
Problem : I am new to Unity5. I am facing following error while trying to do setDestination. "SetDestination" can only be called on an active agent that has been placed on a NavMesh. UnityEngine.NavMeshAgent:SetDestination(Vector3) CompleteProject.EnemyMovement:Update() (at Assets/ ... ; } } } } May I know what is wrong with the above code? Does anyone have any solution on my issue?
asked Nov 27, 2019 alecxe 7.5k points
1 vote
1 answer 269 views
269 views
Problem : Looking for the solution on bellow problem setting the parent of a transform which resides in a prefab is disabled to prevent data corruption
asked Nov 8, 2019 peterlaw 6.9k points
0 votes
1 answer 12 views
12 views
Problem: Unity: The referenced script on this behaviour is missing!
asked Feb 18 Shovo210 3.3k points
0 votes
1 answer 13 views
13 views
Problem: trying to send command for object without authority.
asked Feb 18 Shovo210 3.3k points
1 vote
2 answers 104 views
104 views
Problem: I am beginner to C# with Unity engine. I have already started learning C# with Unity engine. I have tried to write the very basic script as shown below for your reference: using UnityEngine; using System.Collections; public class scriptMyBall : MonoBehaviour { / ... but unable to fix the Unity Engine related error. I need Unity Engine&rsquo;s expert who can guide me in fixing above error.
asked May 23, 2020 Martin K 6.6k points
0 votes
1 answer 281 views
281 views
Problem : I am very new to C#. I have written the below C# code. void UpdateAxis () { float myxP = Input.GetAxis ("Horizontal")*Time.deltaTime * 20; transform.Translate (Vector3(myxP,0,0));//error is here transform.position.x = Mathf.Clamp (transform. ... the above code. error : Expression denotes a type', where avariable', value' ormethod group' was expected` Kindly suggest the solution if any.
asked Dec 3, 2019 alecxe 7.5k points
0 votes
1 answer 449 views
449 views
Problem : I am trying to create the test app using unity but facing following issue: readpixels was called to read pixels from system frame buffer, while not inside drawing frame.
asked Nov 14, 2019 peterlaw 6.9k points