Editor Script: How to replicate the Hierarchy Search effect (isolate certain objects)

Hi all-

Say I have a scene with many parts, and I want to “isolate” only those parts with a script called “SomeScript”. Unity has the super handy search bar in the hierachy now- just how could I replicate this via script?

ie, I’d like to have a function that does something like:

function IsolateObjects()
{
     var filteredObjects = GameObjects.FancyHierarchySelectByScript("SomeScript");
     FancyIsolate(filteredObjects);
}

I understand that I could loop through each and every game object in the scene, checking for the script, and add it to an array to “Isolate”, but that could be really, really slow. Also, I’d still need to “isolate” it, which is the really neat part that Unity’s hierarchy search does. Everything else fades to grey, and only the filtered objects can be selected/manipulated.

So- does anybody know of a way to tap into this? Would be much appreciated, thanks!

I know this is not exactly what you are looking for, but i believe that there is an easier way of doing what you are trying to achieve:

Using static arrays:

Have a public static array of SomeScript’s called All - I would store it inside SomeScript itself.

When a SomeScript is created, have it add itself to All. When it is destroyed, have it remove itself from All.

That way every script can ask for: SomeScript.All; and get all currently active SomeScripts.

I hope that makes sense, and helps :slight_smile:

You could go into the project view, find the script, right click the script, Find References In Scene, and then select all those objects in the Hierarchy…

It’s pretty fast and accomplishes your goal :slight_smile:

Hi Yohadahan,

It’s been a while, but I’m facing today the same issue. Did you find a way to achieve your effect ?

Many thanks,
Ben

I never did, sorry :frowning:

Hello, I succeed by using a second camera with a new layer and occlusion culling. On the main camera you can add a post effet to make all the background grey.

1 Like