0

I create a brand new script through the Unity editor, doing nothing to it. Then when I try to attach it to an object I get this error:

"Can't add script component [script name] because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match."

This shouldn't happen! The file name and class name do match, and there aren't any compile errors. It's a brand new script!

does anyone have a clue what's going on?

Here's the script since you ask:

public class ClippingPlane : MonoBehaviour {
    //material we pass the values to
    public Material mat = Resources.Load("Glasses") as Material;

    //execute every frame
    void Update()
    {
        //create plane
        Plane plane = new Plane(transform.up, transform.position);
        //transfer values from plane to vector4
        Vector4 planeRepresentation = new Vector4(plane.normal.x, plane.normal.y, plane.normal.z, plane.distance);
        //pass vector to shader
        mat.SetVector("_Plane", planeRepresentation);
    }
}

and the name of the file is "ClippingPlane.cs" But it doesn't really matter what the code is or the filename since the same bug occurs with every script! Even if I make a new script in the inspector and don't touch it at all - but I'm repeating myself.

Edit: tried reimporting as that other post suggests. Still having the same issue.

derHugo
  • 83,094
  • 9
  • 75
  • 115
Ilan Elovitz
  • 1
  • 1
  • 2
  • 2
    Possible duplicate of [Can't add script component because the script class cannot be found?](https://stackoverflow.com/q/51713497/1092820) – Ruzihm Nov 22 '19 at 20:32
  • solutions 1. and 2. won't solve it - I'm having the problem with a brand new script. I tried reimporting as suggested there, but nothing changed. – Ilan Elovitz Nov 22 '19 at 20:52
  • Please include the source of the script you are attempting to attach – Ruzihm Nov 22 '19 at 20:56
  • that shouldn't matter, because it's a problem with any script – Ilan Elovitz Nov 22 '19 at 21:18
  • Anyways, it could be related to a lack of any `using` directives. – Ruzihm Nov 22 '19 at 21:32
  • @Ruzihm but these would throw compiler errors .. – derHugo Nov 23 '19 at 08:39
  • double check for any typos in the names. And please tell us in which folder exactly your script is placed. Note that within Unity it should only say `ClippingPlane` **without** `.cs` ... the `.cs` should only be there once if you look at your file in the system file explorer! – derHugo Nov 23 '19 at 08:41
  • @IlanElovitz did you find a solution to this problem? – Ruzihm Dec 10 '19 at 07:49
  • I reverted my project and updated to a newer version of unity and it started working. – Ilan Elovitz Dec 12 '19 at 18:43

0 Answers0