Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Other Made you an amazing "find missing scripts" script

Discussion in 'Scripting' started by singelsnick, Jul 20, 2023.

  1. singelsnick

    singelsnick

    Joined:
    Jul 11, 2023
    Posts:
    1
    Hi all,

    Since the solutions I was able to find didn't really suit my needs, I've made a script that can:
    - Find all missing script objects in the selected scene
    - Find all missing script objects in your assets

    It will provide you with a nice GUI, in which you can click on all of the search results and it will highlight the object in question for you. I was also able to make a script that goes through all of the scenes, and although it works it involves a lot of virtual scenes, opening closing scenes and such, which I think may scare too many people off. But let me know if I should include that as well.
     

    Attached Files:

    ina, Bas-Smit, ramonsmelo and 8 others like this.
  2. Volgix

    Volgix

    Joined:
    Jun 20, 2017
    Posts:
    4
    Thank you, it was very useful!
     
  3. IndigoGorki

    IndigoGorki

    Joined:
    Mar 2, 2018
    Posts:
    39
    Good work,
    I use this code to delete all missing scripts in the scene.

    Code (CSharp):
    1.  
    2. [MenuItem("Tools/Find missing scripts/DeleteAll")]
    3. static void FindAndDeleteMissingScripts()
    4. {
    5.     foreach (GameObject gameObject in GameObject.FindObjectsOfType<GameObject>())
    6.     {
    7.         foreach (Component component in gameObject.GetComponentsInChildren<Component>())
    8.         {
    9.             if (component == null)
    10.             {
    11.                 GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameObject);
    12.                 break;
    13.             }
    14.         }
    15.     }
    16. }
    Right now I don't have time to adapt the code of the script made by singelsnick. So you can see how automatic deletion works and add to the code as you wish, where you want and how you want.
     
  4. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    278
    thanks a lot

    a few tweaks:
    - survive domain reload
    - remove deleted gameobjects from list
    - exclude prefabs in packages
     

    Attached Files: