Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Find GOs which use a transparent shader [in editor]

Discussion in 'Editor & General Support' started by fallingbrickwork, Dec 15, 2013.

  1. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    Hi all,

    Is there a quick way within the editor to find all the scene GOs that use a transparent shader? i.e. Transparent/Diffuse or Transparent/Cutout/Diffuse et al. I need to find all the Transparent derivatives

    Are we talking an Editor script or can this be done via the Hierarchy find box?

    Cheers,
    Matt.
     
  2. Kragh

    Kragh

    Joined:
    Jan 22, 2008
    Posts:
    651
    Well... You could use the shader renderqueue to determine this. But there may be better ways.

    So something like this:

    Code (csharp):
    1.     public List<GameObject> GameObjectsWithTransparency ()
    2.     {
    3.  
    4.         List<GameObject> result = new List<GameObject>();
    5.  
    6.         Renderer[] allRenderers = FindObjectsOfType<Renderer>();
    7.  
    8.         for (int i = 0; i < allRenderers.Length; i++)
    9.         {
    10.  
    11.             for (int j = 0; j < allRenderers[i].sharedMaterials.Length; j++)
    12.             {
    13.  
    14.                 if (allRenderers[i].sharedMaterials[j].shader.renderQueue >= 2450) {
    15.  
    16.                     result.Add(allRenderers[i].gameObject);
    17.  
    18.                     break;
    19.  
    20.                 }
    21.  
    22.             }
    23.  
    24.         }
    25.  
    26.         return result;
    27.  
    28.     }
     
unityunity