Search Unity

"The referenced script on this Behavior is missing" driving me crazy

Discussion in 'Scripting' started by DallonF, Jul 21, 2015.

  1. DallonF

    DallonF

    Joined:
    Nov 12, 2009
    Posts:
    620
    So one thing I really want to do in my current project is use Unity's ability to recompile scripts while the game is running.

    When I do that, though, I get two "The referenced script on this Behavior is missing" warnings. Exactly two! Normally I see those when a script's been renamed or moved improperly but this only happens on script recompilation (in Play mode).

    They don't seem to be hurting anything; everything in the scene works and nothing seems to be missing any scripts. But the warnings are hurting my perfectionist side... where are they coming from? I'd attach a project to reproduce the problem but it only seems to happen in a real project and I don't feel like sending that whole thing over.
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I know it is not what you want to hear and it doesn't answer your question and that's why I just want to make that statement without further comments:
    Don't even try it, it is not worth the effort!
     
  3. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Based on this http://answers.unity3d.com/question...ed-script-on-this-behaviour-is-missing-2.html
    someone stated about applying changes made to your prefab in the scene.

    I was getting this missing behavior warning too, but after I applied a prefab in my scene and reloaded the scene it seemed to have gone away, but I dont think there was anything to really apply, but maybe I renamed a script outside of unity, reassigned it to the prefab in the scene and didnt apply it, and so now the actual prefab didnt get the updated name and was missing the script, but since I was not instantiating that prefab and was only using the one already in the scene, and since that one was updated properly, I wasnt getting errors.
    I will look out for it next time.
     
  4. DallonF

    DallonF

    Joined:
    Nov 12, 2009
    Posts:
    620
    Thanks, but I actually don't have any Prefabs yet...so that's probably not the issue. *shrug*

    Edit: Just started up Unity again and the problem seems to have fixed itself.



    Back to work!
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's probably script execution order. As when you recompile, unity has to reload all the scripts. If some depend on others, this might occur where it wasn't much of an issue on first start. I can't tell but it sounds like that could be something. I really wouldn't bother.
     
    Pascal_NotVeryMoe likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    To prevent this sort of thing in the future, you should be using source control and committing regularly.

    Mercurial and Git are free, don't require any central server, and I cannot even begin to COUNT the number of times something weird has happened in Unity3D, and then when I look in source control I see what piece of data got changed, revert it back and I'm back in business.

    Doing development without source control is like playing a Skyrim-sized adventure game without save games.
     
  7. DallonF

    DallonF

    Joined:
    Nov 12, 2009
    Posts:
    620
    What makes you think I didn't initialize a Git repo before even opening Unity? ;) Well, besides the fact that most rookies like me don't do that...

    But anyways, it wasn't a metadata issue like this error normally is. (At least I don't think it was...) Nothing was permanently borked in my project, I was just getting annoyed by meaningless warnings!
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    I feel your pain. This particular message essentially means Unity knows you have a script attached but something has happened to the GUID linkage between the object with the script and the GUIDs in your project.

    This can happen if you move files around outside of Unity, or cut/paste stuff in or out of your project directly from other unity projects.

    When you enable source control, you will enable visible meta files too, and do NOT source control the Library or Temp directories, and then if/when this sort of thing happens, you can trivially see the mis-linked script and revert the offending change, regardless of how the change happened.