Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Editor Script: How do I get all objects within a folder using Selection.GetFiltered?

Discussion in 'Editor & General Support' started by Dreamwriter, Jun 14, 2017.

  1. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    I'm trying to get all the objects in a specific Project folder with MeshRenderers on them. But this code doesn't work:

    Code (CSharp):
    1.         Object[] everything = Selection.GetFiltered(typeof(MeshRenderer), SelectionMode.DeepAssets | SelectionMode.Deep);
    2.         Debug.Log ("These are the assets I found: ");
    3.         foreach (MeshRenderer obj in everything)
    4.         {
    5.             Debug.Log (obj.name);
    6.         }
    7.  
    When I select a prefab, I get results. When I select the folder containing that prefab, I get nothing, though SelectionMode.DeepAssets is supposed to go into folders. Any ideas what I'm doing wrong?