recently when I started my project, I have some GameObjects that I can’t change. The editor says “The prefab file contains an invalid script”. Screenshot by Lightshot
When I look into the GO, I see for example this: Screenshot by Lightshot
In this case I know which script is missing, so I try to add it again but still I cannot save the GameObject.
What’s even worse, I have lots of Objects that include a light and another missing script attached to it. In this case I don’t even know what script that was since I have a “Missing script” on many of my GO’s.
I already reimported the whole assets, since this was a solution I found on the internet, but the problem remains. I also use Version Control but even reverting to older commits does not resolve this issue.
This can happen if you’ve manually changed the class name of a script, such that the class name and the file name are no longer the same. For scripts to work in Unity, the file name needs to match the class name.
One thing to try: At the top-right of the Inspector window, there’s a tiny hamburger menu (three lines and an arrow) next to the tiny padlock. Click the menu, and change from “Normal” to “Debug”. It’s possible that might show you the name of the script it’s expecting. (Be sure to switch back to “Normal” again later.) If it’s fixable, the fix is probably to just verify whether all your MonoBehaviour scripts have the same Class name as their file name.
I haven’t. I just moved to another place so in the past weeks I did not work on my project and now that I opened it again, I had those errors…
But thanks for your suggestion. I will try it later today when I am back at home.
Recently I noticed scripts were missing on more objects than I expected. Some of them are quite weird.
For example, when the game is not playing, everything looks okay:
But once the game is in play mode, the script is gone and a warning gets thrown in the console [the functionality of what the script does, however, is still there…]:
The console then says The referenced script (Unknown) on this Behaviour is missing!
This is really the weirdest bug I experienced since I work with Unity…
Not before. I was on 2018.1. something but now I updated it as I thought I could resolve the issue, but the update didn’t help.
But I think I got it all cleared now. I did the manual work and checked every scene GO and compared it to the prefab.
Warnings are all gone now, no more missing script. But it was my whole Friday eve of work. I hope it won’t happen again…
I had to run the game and then an error message came up in the log that I was able to click and it selected the offending game object in the inspector.
For my prefab, the missing script wasn’t showing in the inspector, only when I entered the prefab was there a missing script shown. Removing that script solved it. Probably was an issue with renaming attached scripts as mentioned earlier.