0
votes

I can't seem to compile on Unity because all of my scripts have errors. The error messages keep on repeating, "The associated script cannot be loaded. Please fix any compile errors and assign a valid script." I have checked all of my scripts on Visual Studio 2017 and have not found any errors.

The image below shows the error showing on the inspector view of the unity engine:

Image of error

3
Check you error log list and fix what's there.Oen44

3 Answers

1
votes

If there are really no compiler errors as you say the reason might be incorrect file names or class types.

Make sure that the file names and the class names match!

If your class is called

public class Player_Collision1 : MonoBehaviour
{
    ...
}

the script/file must exactly be called

Player_Collision1.cs

and the other way round.

Attention: The Unity project view (Assets) strips of the file endings so there it should only display as

Player_Collision1

Another reason for a script to be not valid is e.g. if your class doesn't inherit from MonoBehaviour at all.

Unity would usually prevent you from adding those "invalid" scripts to an object but it might happen that you renamed them or changed their type afterwards. In this case you will see the error you currently have.

1
votes

Check you log and see if any compiler error has happened.If no have a look at your class name and file name are same.

0
votes

I see that you are (relatively) new here. welcome to Stack Overflow! ^^

what unity is trying to say is that it can't compile your scripts because there is one or more another script(s) that have errors in them.
in the Console, you will find your errors and by double left clicking on one of then, you will be taken to the script and the location of its error.

by selecting (left click) an error you will be able to read more a more detailed description of the error.

enter image description here