Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Searching for 'Missing' References script?

Discussion in 'Scripting' started by JamesHans, Aug 12, 2014.

  1. JamesHans

    JamesHans

    Joined:
    Jul 3, 2014
    Posts:
    8
    I've noticed that sometimes in Unity I lose references on GameObjects e.g. textures or meshes, something could go and I get a ‘missing’ (mesh) reference on the inspector somewhere. It tends to happen when Unity is doing an update (e.g. when you switching between version control and back to Unity, and perhaps a file hasn't finished writing for example).

    This means that sometimes a mesh might just disappear from an object and when you have a big scene that's a lot that could just disappear and go unnoticed.

    I was therefore wondering if there was a script in existence (though hopefully it would be a relatively short / simple script) in Unity to loop through all assets and return in a window a list of any reference that simply said ‘missing’?

    I am sure this is far faster than me having to do sweeps on hundreds of assets? Any input would be greatly appreciated!

    Thanks

    James
     
  2. PrimalCoder

    PrimalCoder

    Joined:
    Aug 12, 2014
    Posts:
    9
  3. JamesHans

    JamesHans

    Joined:
    Jul 3, 2014
    Posts:
    8
    That's great, but do you know what I would need to modify for it to look for missing references say for meshes, materials or textures whereby on disc they are no longer there?

    Is it something around this line?
    Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(c=>c.GetComponents<Component>().Any(o=>o==null)).ToList();
    }