Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity: "The referenced script (Unknown) on this Behaviour is missing!"

Tags:

unity3d

Sometimes when I start my game, I get pointless warnings. I do not know where they come from and I do not have any objects that address a script that does not exist. How can I remove or fix these messages?

Console:

Inspector:

When I right click on the icon of the file in the inspector I get two possible options. Both of them do not work or when I try to click on them nothing happens.

Inspector context menu:

like image 603
Timisorean Avatar asked Mar 03 '19 14:03

Timisorean


People also ask

How do I fix scripts in unity?

To fix just delete ALL the meta files in the assets folder and reopen your project. Unity should rebuild all the script references. Also make sure to remove all compile errors.


2 Answers

It happens when the file and the name class has not the same name.

Example:

  • The file is named SingleCube.cs
  • The class definition is public class Cube : MonoBehaviour

In this case, Unity is not able to link the file and the class. Both have to have the same name.

  • The file should be SingleCube.cs
  • And the class definition public class SingleCube : MonoBehaviour
like image 198
Sergio Lema Avatar answered Sep 20 '22 19:09

Sergio Lema


I had this same issue as well. I think it's caused by deleting the default scene but not changing the "Scenes in Build" in the build settings. Here's how I fixed it.

  1. Go to your build settings (File > Build Settings). There should a greyed out box that says "deleted". This is the (now missing) default scene.
  2. Right click on it and remove it
  3. Add your current scene
like image 28
Idyia Avatar answered Sep 20 '22 19:09

Idyia