I’ve made a plugin that you can use to collapse/expand all Explorer widget folds in Studio, until they add this functionality to Studio by default.
- If you have nothing selected, it will close all Explorer folds in the entire game (excluding Service folds).
- If you have something selected, it will close all folds at/underneath those selected objects.
- If you have nothing selected, it will open all Explorer folds in the entire game.
- If you have something selected, it will only open folds at/underneath those selected objects.
It also has shortcuts you can configure: (via File > Advanced > Customize Shortcuts…)
(Please note that this plugin banks on some hacks explained further down below and may break at any time.)
I hate that it has a toolbar, it takes up space…
Ok, you can disable the toolbar by dumping this in the Command Bar in Studio: (and then restart Studio)
game:GetService("CollectionService"):AddTag( Instance.new("BoolValue", game), "EXPLORER_FOLDS_TOOLBAR_OFF" )
To re-enable: (no need to restart afterwards)
game:GetService("CollectionService"):AddTag( Instance.new("BoolValue", game), "EXPLORER_FOLDS_TOOLBAR_ON" )
How does it work
The Explorer doesn’t have any sort of API attached to it, so we have to get a little creative.
To collapse hierarchies, we take advantage of the fact that the Explorer doesn’t remember the state of folds when you unparent the object from DataModel and then parent it back. (i.e. parent to nil and back) This is what the Collapse action uses. Unfortunately we cannot reparent Services, so we can only collapse folds within services.
To expand hierarchies, we abuse the fact that the Explorer automatically unfolds hierarchies up to the point of an instance you select. So to expand something, we search through the entire tree from that instance down, and we select (at least) 1 inner child of each branch of the hierarchy. Unfortunately the Explorer doesn’t update this immediately, so we need to wait some undetermined amount of time (I’ve made it 0.5 seconds, it’s possible that this can be tighter) before restoring the original selection that the user had before the operation. This means the expanding operation can unfortunately not be quite as instant as collapsing.
For expanding, I do some smart selection of objects to make sure that it selects the minimal amount of objects needed to fully expand a hierarchy, rather than selecting literally everything (this helps with performance due to the otherwise very high number of selection boxes and the large size of the selection).
Caveats (please read before using)
- Expanding takes an extra brief moment of time (~0.5-1 second) and temporarily adds a lot of objects to your selection (it will restore your original selection right after)
- Cannot collapse Services themselves if they have children that can’t be unparented (i.e. can collapse everything in Workspace, but cannot collapse Workspace itself, because Workspace always has a Terrain in it that can’t be unparented)
- May cause a flicker of game window when collapsing
- May cause a short freeze / cpu spike when using collapse or expand for large places
- May interfere with plugins that do not expect certain game elements to be parented in/out of the DataModel
- Explorer view may shift up/down erratically when using collapse or expand
- May not work great in team create when multiple people are active at the same time [needs testing]
- Collapse will affect all collaborators
- Expand will temporarily cause a lot of instances to be selected which other collaborators can see too through your selection boxes
- Collapse may cause replication issues in team create (because it reparents potentially a lot of stuff)
- Collapse and expand may impact performance and briefly lag/freeze yourself and other collaborators (same as above)
- When other collaborators are interacting with certain objects (dragging builds, writing scripts) collapsing may kick them out of that interaction and cause other weird effects, because of the instances being reparented
Use at your own risk! (in sessions where only 1 developer is active most/all of the time, this should be pretty safe)
Dear god what were you thinking
I’m sorry it had to be done (because I could)
For any staff members reading this
Please add built-in hotkeys / context menu items for mass-collapsing/expanding Explorer hierarchies!
Relevant feature request you can refer to: Ability to collapse all folds in explorer