Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Collapse All Folders in Project/All GameObjects in Hierarchy (Editor Script)

Discussion in 'Immediate Mode GUI (IMGUI)' started by yasirkula, Oct 29, 2017.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,092
    Hi there,

    I'd like to share a simple editor script that allows you to collapse all folders in the Project view or collapse all GameObjects in Hierarchy view programmatically.

    EDIT: Up-to-date version of the script is available at: https://gist.github.com/yasirkula/0b541b0865eba11b55518ead45fba8fc

    Simply create an EditorCollapseAll.cs script in Assets/Editor folder of your project and paste the above code in it.

    Collapsing Hierarchy View
    To collapse all GameObjects in the currently active Hierarchy view, either use the GameObject menu or right click a GameObject and select "Collapse All".

    Collapsing Project View
    To collapse all folders in Project view, either use the Assets menu or right click an asset and select "Collapse Folders". Note that folders containing the selected assets will not be collapsed.

    Enjoy!
     
    Last edited: Feb 7, 2020
  2. morphinegames

    morphinegames

    Joined:
    Mar 13, 2015
    Posts:
    33
    Just wanted to say thank you - I was just looking for some way to do this and this works great.
     
    yasirkula likes this.
  3. StylishCoding

    StylishCoding

    Joined:
    Apr 21, 2018
    Posts:
    140
    Unity indeed supports this feature natively. Hold alt key to collapse/expand any item in Hierarchy or Project View, it collapse/expand all under this item.
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,092
    The code actually simulates the same behaviour programmatically, only that it selects all the root folders and collapses them all at once, so that you won't have to alt-click them all one by one (can be useful when you have many root folders).
     
    protopop likes this.
  5. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,470
    Thank you! file this under simple lifesavers. I have thousands of files and sometimes the length of my project hierarchy scares me:) This is exactly what i needed and works great.
     
    yasirkula likes this.
  6. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,470
    Forgot to mention, put the script inside a folder called editor - any one or make your own - so it won’t be included in the build
     
  7. Gulliver

    Gulliver

    Joined:
    Jan 8, 2013
    Posts:
    79
    Thank you !
     
    yasirkula likes this.
  8. SynthOverseer

    SynthOverseer

    Joined:
    Aug 23, 2011
    Posts:
    21
    Thanks so much. This is a life saver!
     
    yasirkula likes this.
unityunity