Search Unity

Invalid/Missing script - Cannot apply GameObject changes

Discussion in 'Editor & General Support' started by kai_226, Mar 5, 2019.

  1. kai_226

    kai_226

    Joined:
    Jul 6, 2017
    Posts:
    53
    Hello community,

    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". http://prntscr.com/mtnwbt

    When I look into the GO, I see for example this: http://prntscr.com/mtnx81
    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.

    Is my project now broken? Just out of the blue? :(
     

    Attached Files:

  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Do you have any compile errors in your console?
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    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.
     
  4. kai_226

    kai_226

    Joined:
    Jul 6, 2017
    Posts:
    53
    No, the console is completely empty.

    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.
     
  5. kai_226

    kai_226

    Joined:
    Jul 6, 2017
    Posts:
    53
    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:
    http://prntscr.com/mv8tw0

    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...]:
    http://prntscr.com/mv8wd0

    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....
     
  6. ArdaOzcan

    ArdaOzcan

    Joined:
    Dec 9, 2017
    Posts:
    7
    I had this issue too, have you updated Unity recently?
     
  7. kai_226

    kai_226

    Joined:
    Jul 6, 2017
    Posts:
    53
    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...
     
  8. mrVentures

    mrVentures

    Joined:
    Nov 11, 2018
    Posts:
    9
    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.
     
  9. ilicstefan0307

    ilicstefan0307

    Joined:
    Oct 14, 2020
    Posts:
    1
    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.