Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] The Referenced Script On This Behaviour Is Missing

Discussion in 'Scripting' started by busterlock, Jan 24, 2016.

Thread Status:
Not open for further replies.
  1. busterlock

    busterlock

    Joined:
    Sep 26, 2015
    Posts:
    58
    I have a Game Object where I store a prefab and a script to use on a GUI button. Basically, you click on the button and the script instantiates a clone of the prefab (and another function that destroy such clone). The script works fine but Unity keeps giving me these error messages:


    The referenced script on this Behaviour (Game Object 'Capsule') is missing!
    The referenced script on this Behaviour (Game Object '<null>') is missing!
    The referenced script on this Behaviour (Game Object 'Capsule') is missing!

    Again, the game works and runs perfectly, the script just as much, but these messages are starting to bother me. Here's a sample of my script:

    Code (CSharp):
    1. public class BuildMenu : MonoBehaviour
    2. {
    3.     public GameObject tower;
    4.     public bool towerTrigger;
    5.     public Transform tPosition;
    6.     GameObject towerClone;
    7.  
    8.     void Start()
    9.     {
    10.         towerTrigger = true;
    11.     }
    12.  
    13.     public void TowerSpawn()
    14.     {
    15.         if (towerTrigger)
    16.         {
    17.         towerClone = Instantiate(tower, tPosition.position, tPosition.rotation) as GameObject;
    18.         towerTrigger = false;
    19.         Debug.Log("Tower Created");
    20.         }
    21.     }
    22.     public void TowerDestroy()
    23.     {
    24.         if (!towerTrigger)
    25.         {
    26.             Destroy(GameObject.Find("Capsule(Clone)"));
    27.             Debug.Log("There's already a tower here");
    28.             towerTrigger = true;
    29.         }
    30.     }
    31. }
    The object where the script is stored is being used in the GUI button on the Mouse Down () void.

    SOLUTION = I had created a script and attached it to the prefab but later on erased it, so Unity was telling me that this script (outside from the one posted in the thread) was missing. Noob mistake.
     
    Last edited: Mar 9, 2018
  2. Jack_Black_1

    Jack_Black_1

    Joined:
    Mar 30, 2017
    Posts:
    1
  3. ryanfry88

    ryanfry88

    Joined:
    Feb 24, 2018
    Posts:
    1
    thanks man i was scratching my head about this all night.
     
    busterlock likes this.
  4. busterlock

    busterlock

    Joined:
    Sep 26, 2015
    Posts:
    58
    Hey, man, the only thing I would think about changing is the GameObject.Find, since everyone around the forum say the function sucks. Maybe use the tag of the collider it is hitting seems like a better strategy? Hope it helps.
     
  5. Gerold_Meisinger

    Gerold_Meisinger

    Joined:
    Sep 8, 2015
    Posts:
    93
    I got a lot of "The referenced script on this Behaviour (Game Object '<null>') is missing!" (note the <null>) warnings and couldn't find it with any "FindMissingReference" script and paid tools from the asset store in the scene or prefabs. Apparently the problem was a corrupt scene file. Solution: Create a new scene, load it into the bogus scene and copy all objects. You should also check the references of the scripts and UI input handling. Some references were lost in copyation and I had to remove and readd the EventSystem o_O.
     
  6. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Thank you a thousand times over for this! I had just about given up hope. I knew what removed script was causing the issue, and bringing it back removed the warning. I was certain there were no references to it in my project. I stumbled upon this, created a new scene, copied the contents across and sure enough the warnings are gone!
     
    Last edited: Jul 4, 2018
    clueduppstephen and facejets like this.
  7. Gerold_Meisinger

    Gerold_Meisinger

    Joined:
    Sep 8, 2015
    Posts:
    93
    I'm glad it helped. However I'm still seeing some warnings every now and then, so it didn't fix it completely.
     
    anycolourulike and junctionboss like this.
  8. malexeev

    malexeev

    Joined:
    Oct 7, 2016
    Posts:
    1
    Thanks a lot for the update, I know this is a bit late but u saved me so much time I was head over heels trying to figure out whats wrong :p
     
  9. VRDUDEZ

    VRDUDEZ

    Joined:
    Dec 4, 2018
    Posts:
    4
    Hi @all

    I found this post by search a solution for my issue maybe someone can help me i search for months!!! ^^

    Its a livestream problem with my oculus rift into the facebook spaces app, when i go live the stream stops and give me a error text dat

    its look like that

    (Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

    The referenced script on this Behaviour (Game Object '<null>') is missing!

    (Filename: Line: 1744)

    Thanks you so much for helping

    best regards
     
  10. VRDUDEZ

    VRDUDEZ

    Joined:
    Dec 4, 2018
    Posts:
    4
    https://www.mediafire.com/file/igf88ifz22oxhs3/facebook_spaces_crash.rar/file
     
  11. mibragg

    mibragg

    Joined:
    Apr 10, 2015
    Posts:
    3
    Bump. I just experienced this problem and, in my case, it was pretty easy to fix..

    The referenced script on this Behaviour (Game Object 'LineUp') is missing!
    The referenced script on this Behaviour ('Unknown') is missing!
    The referenced script on this Behaviour (Game Object 'LineDown') is missing!
    The referenced script on this Behaviour ('Unknown') is missing!

    I had created two game objects, each to hold a line renderer. I then created a script to work with them and attached it to the each game object.

    I later deleted this script in Visual Studio (not removing it from the LineUp gameobject in the Unity Editor by right clicking and choosing remove component) as the script was just for testing. This caused the problem in the two game objects (each missing the deleted script) and I had the above set of annoying and stressful messages.

    Of course, I made many changes to the project before I noticed the issue. Took me a bit to find this post. Best to stop and fix those issues!

    So, i think the errors were caused by deleting the script in Visual Studio without removing the script component in the Unity Editor first. Down at the bottom of each offending gameobject’s component list, you will see a script is attached with no name, it just says SCRIPT (I.e., no script name)

    The fix for me was to create a new empty game object, copy the linerenderer component from the old one to the new one and then go back and delete the offending old game object. Renamed the new one to the same name as before and the problem was solved.

    Hopefully a similar fix will work for others...

    Good luck
     
    MrMajorThorburn and yneishii like this.
  12. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,771
    I don't get this at all! I removed the tools I was using and every script file from the prefabs in the scene and it still gives the error messages pointing me to the prefabs but the prefabs have nothing on them and everything works fine when I hit play.
     
    RiverExplorer and junctionboss like this.
  13. RandomPoint

    RandomPoint

    Joined:
    Jul 21, 2017
    Posts:
    14
    Wouldn't it be great if Unity saved the name of the script that was attached, so when it disappeared you had a chance of figuring out what was there so you could fix it? Apparently this is not enough to jog my memory: upload_2019-4-25_16-17-13.png

    Does anyone have a good suggestion for how to keep track of which script components are attached to which GameObjects? For me, they usually get broken during a Unity upgrade or in a Git merge of YAML files, and when the problem is discovered, I often can't remember what script was attached.
     
  14. Paul_Bronowski

    Paul_Bronowski

    Joined:
    Sep 3, 2014
    Posts:
    55
    +1. It would be helpful...

    - If the asset Guid was included in the message, if available..

    - A 'find missing/broken references in assets/objects' tool was built-in.

    - SerializedProperty was changed such that we can no longer easily detect broken references. That needs to be improved - not deprecated. I have a cobbled together missing references tool that (gulp) cracks asset YAML and tries to match things up. It's quite ugly and barely works only for some things.

    - thanks
     
  15. Dazo1985

    Dazo1985

    Joined:
    Mar 13, 2019
    Posts:
    26
    +1
    Copying scene content to a new scene
    removed the warnings.
     
    decimate_3d likes this.
  16. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    +1
    Copying old scene content to a new scene, the warnings went away when playing the new scene. Strangely enough, it also removed the warnings of the old scene, so the warnings went away when playing the old scene. I think it's a Unity bug.
     
    tangentkorea likes this.
  17. drHogan

    drHogan

    Joined:
    Sep 26, 2012
    Posts:
    201
    I had 1646 fake Missing script warnings after upgrading the project from 2017.3 to 2018.4. It was object in scene that never had a single script attached sometimes, so obviously just a bug. They had a hidden flag set to 2 in the meta files, setting that to 0 they became visible but i could only remove them by hand.
    After days of pain, i managed to find this https://answers.unity.com/questions/15225/how-do-i-remove-null-components-ie-missingmono-scr.html and after upgrading to 2019.2 it worked and they were all gone.
    I have 4 left, 2 per scene. Appearing only at runtime and belonging to unexisting objects. Double clicking the warning opens up in the inspector a prefab that doesn't exist anymore in the project, with 2 missing scripts.
    The IDs don't exist in the meta files.
    Spooky. Anyone had anything like that?
     
  18. gtzpower

    gtzpower

    Joined:
    Jan 23, 2011
    Posts:
    318
    Ran into a similar issue where I was getting this error for an object that didn't appear in the hierarchy. Deleted all objects and was still getting the error. Turns out that there were hidden objects in the scene! I followed the suggestion linked below, installed the editor script, and was able to track down and remove the game object:
    https://answers.unity.com/questions/1291622/object-in-scene-not-in-hierarchy.html
     
    junctionboss likes this.
  19. ThyanC

    ThyanC

    Joined:
    Apr 7, 2020
    Posts:
    1
    Well, in my case, copying the scene content to another scene did NOT solve the problem. What I did though, was to find the GameObject that was missing the script (when you click on the warning message it highlights the problematic GameObject in the hierarchy) and noticed that it had a Script component that had an empty reference to a script. I removed that Script component and everything went back to normal ;).
    This might save time and help someone, and this is the only reason I'm writing this post...
     
    firebird721 likes this.
  20. holo-krzysztof

    holo-krzysztof

    Joined:
    Apr 5, 2017
    Posts:
    77
    So, I also stumbled into this too and nothing in the thread solved it, so here goes:

    The root cause was that some references in the scene were missing, due to scripts not being present because the assembly they were part of was not marked as supported for the platform I was building for (UWP).

    There was no build time warning at all, which puzzles me.

    After marking the `.asmdef` as supporting UWP the errors were gone.
     
    sicklepickle likes this.
  21. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    386
    Same issue here, for me it was addressables leaving behind hidden game objects with missing scripts after quitting play mode f.e.
     
  22. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,771
    Copying the scene into a new file didn't do a thing, I'm getting the same errors! :mad::mad::mad: Still, there is no solution to this even today! :(

    Nvm, I got it figured out.
     
    Last edited: Apr 19, 2021
  23. bimoldas

    bimoldas

    Joined:
    Aug 29, 2020
    Posts:
    1
    Your script file name and public class name should be same. Like Test.cs so public class should be public class Test
     

    Attached Files:

  24. patrickreece

    patrickreece

    Joined:
    Nov 14, 2019
    Posts:
    23
    I had a problem where the assembly definition for the script I wanted to use was referencing other editor-only assembly definitions. No build warnings, just warnings in play mode when it couldn't find the script, and errors if any data was serialized for it.
     
  25. MufasaSuCasa

    MufasaSuCasa

    Joined:
    Dec 12, 2020
    Posts:
    8
    So I'm not sure if this will help anyone else with this missing reference issue but my solution was to simply open my prefab (a ball) and remove the missing script from the inspector of the opened ball prefab. Once I did this, my errors disappeared. The script I had deleted from my scripts folder was still attached in the prefab window.

    I'm fairly new to coding but I hope this helps someone!
     
  26. Shadow_Blade44

    Shadow_Blade44

    Joined:
    Jul 21, 2021
    Posts:
    1
    Yooo thanks, That was bothering me too!
     
  27. maurofuentes

    maurofuentes

    Joined:
    Apr 5, 2018
    Posts:
    8
    I believe the error is due to a gameObject living in the scene without a proper Transform (In my case) (don't ask)

    So, here is what I did:

    _Create a dummy class "FindMe"

    _Play the game

    _After being prompted with the warning "The referenced script()" Stop

    _Double-click the warning, so you can see the missing script on the Inspector

    _Press the cork and change the missing script to FindMe

    _On the same place, right-click the script and select Find Reference on Scene

    _You'll see Unity shows you an empty-empty_not-existant gameObject

    _You can't select the object because it doesn't exist, but if you drag the created transform gizmo you will be able to delete it with Supr key

    _Problem solved

    Hope it makes sense to you guys. It helped me!
     
    vozcn likes this.
  28. elpeedros

    elpeedros

    Joined:
    Jun 6, 2013
    Posts:
    14
    Hey everyone, sorry for resurrecting this thread but I'm adding my two cents in because my issue was different than the ones I read here. For me, I was using a singleton ScriptableObject class that would load assets from a resource folder. It worked great in the IDE, but once I made builds (desktop and quest apks) I'd get the infamous error.

    This threw errors:
    Resources.LoadAll<T>("")

    Refactoring to this threw no errors!
    Resources.Load<T>(specificFileName)
     
    DelRod, hubinbin2020 and dev2X like this.
  29. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Also resurrecting this thread, because relevant.
    If you have build scripts running on a separate build machine or agent, be sure to have checked in the Unity meta files into your repository. D'oh. Basically, my builds were working locally because I was building with the Editor, which auto-generates meta files if they don't exist. But, build machines may not do this. They would just take the existing source from a source repository and attempt to build. Without the meta files for some scripts, the scene cannot find the referenced scripts.
     
  30. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,262
    This has to ALWAYS be true or you are openly courting complete project disaster.

    Some info about Missing script warnings, GUIDs, renaming GUIDs, etc:

    https://forum.unity.com/threads/problem-with-git-and-missing-scripts.1090876/#post-7024801
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6487297
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6488230

    EVERYTHING in Unity is connected to the above GUID, which is stored ONLY in the metafile. It is super-easy to inadvertently change it by renaming outside of Unity. Don't do that. Instead:

    - close Visual Studio (important!)
    - rename the file(s) in Unity
    - in Unity do Assets -> Open C# Project to reopen Visual Studio
    - now rename the actual classes, and MAKE SURE THE FILE NAMES DO NOT CHANGE!

    If you are NOT using source control while you do this, renaming files is an EXTREMELY dangerous process. Use source control at all times so that you can trivially revert if you miss a critical step and damage your project.

    Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    Here's how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally setting Unity up (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  31. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Definitely true. As much as my issue was that meta files weren't checked into the repo, ultimately, it was due to my gitignore already masking those files without me knowing.

    I had a .gitignore at the root of the project based on VS (https://github.com/github/gitignore/blob/main/VisualStudio.gitignore). It ignores meta files because of VS.
    My git repo contains a few other VS projects, so that gitignore must be moved into those VS projects separately.

    It was a complete oversight on my part, and I had only discovered this when an independent autobuild was kicked off.
     
    lllisten likes this.
  32. recaremo01

    recaremo01

    Joined:
    Jun 28, 2022
    Posts:
    2
    Fixed my issues well and took a few seconds to do
     
  33. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101
    i have this warning

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

    i have no idea how aand where is the traceback and where to search for the problem

    will try the fixes above...
     
  34. OnatKorucu

    OnatKorucu

    Joined:
    Apr 18, 2018
    Posts:
    8
    First click "Add Component" in the Editor. Add the script named "NameFinder". Open your IDE (Rider, Visual Studio etc.). Fill the class with following lines.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class NameFinder : MonoBehaviour
    {
    // Update is called once per frame
    void Update()
    {
    Debug.Log("Name of the object is:" + gameObject.name);
    }
    }

    Come back to Unity and watch console while in Play mode. Name of your object should be printed each frame. If you can find it in the scene, good. Get out of the play mode and delete it.

    If you can not find it in your scene, your scene file is corrupted. Close unity, open your scene file in a text editor, search for the name of your object and delete the object manually.

    You may want to see how Unity stores scene objects. In my case I had to search for GUID and delete the stuff that has the same reference. (Transform and other components should be removed.)
     
    firebird721 likes this.
  35. Stepan717

    Stepan717

    Joined:
    Oct 26, 2022
    Posts:
    2

    Simply delete the component and create a new one with the same parameters!!
    it WORKS !!! 10/28/2022
     
  36. semirobot

    semirobot

    Joined:
    Mar 10, 2019
    Posts:
    1
    For me it was related to Visual Effect Graph.
    I believe I compiled an effect from the VFXG editor without saving it and kept the VFXG editor opened.
    Once I saved it the warning was gone.
     
  37. Tarodev

    Tarodev

    Joined:
    Jul 30, 2015
    Posts:
    190
    So this had me running around. In one of my scripts on scene A, I would asynchronously load scene B and the warning was actually being triggered from scene B. Spent way too long scouring scene A...
     
  38. TecsiAron

    TecsiAron

    Joined:
    May 10, 2011
    Posts:
    5
    Just ran in to this! Removed all of the old/missing scripts from the scene, was still getting the warning.
    Turned out that even tough I removed the scripts from the scene, prefabs that contained missing scripts where still generating the warning, but without the possibility to see where the warning is "coming from".
    The problem went away once I edited the prefabs and removed the references to the missing scripts.
     
  39. unity_0404BF17DA04E7B0732E

    unity_0404BF17DA04E7B0732E

    Joined:
    Jun 30, 2023
    Posts:
    1
    It happens when you delete any script attached to that prefab.
    All you have to do is go to your prefab folder select prefab and open prefab from your inspector at the end in the inspector when all your script are attached you will be able to see that the script you deleted is still there and waiting for a prefab just remove that script from the three dots given on top right of the script component.
     
Thread Status:
Not open for further replies.