Component Filter

Have you ever had the trouble of finding components in the inspector while viewing a gameobject in Unity? Well our team did! So we made a Component Filter to categorise, filter and find components faster. In this blog post we are going to tell you how it works, looks and talk about what we had to do to get it done!

The Component Filter is a rework of the already existing Unity Inspector view that allows users to filter the component list based on categories and includes a search bar.

Why A Component Filter?

The reason our team decided we wanted to make a tool that filters the components on an object, is because some objects, such as enemies, get more and more components on them as work on the game progresses. This also makes finding that one specific component where you need to edit or check a variable annoying and slow. Our Component Filter massively speeds up this process.

How it works

After you selecting a gameobject, the user will be faced with the default inspector as usual. However, now there will also be a grid of labels/categories which when clicked on, will filter all the components on that gameobject, showing only the ones that are part of the selected category.

The user will also have the option to use the Component Searchbar, allowing them to filter out specific components or components that contain part of a word they search for.

Now we will explain how all of this works behind the scenes!

Component Categoriser

Every time the user selects a gameobject, the Component Categoriser (script) will compare the components on the object to the ones already in the Component Collection, whenever a new component is detected that is not yet in the Collection, it will automatically be added to the Other category in the Component Collection.

Component Collection

The Component Collection is a scriptable object which works in cooperation with the Component Categoriser to categorise every detected script in the game.

The user can then proceed to add/move components to categories in the Collection, which then affects which filter labels are shown in the inspector view.

Obstacles We Encountered

Adding to the Default Unity Inspector

One of the obstacles we ran into while making our Component Filter interface is that our script would overwrite the default Unity Inspector and there was, as far as our extensive research found, no way to “call” the default inspector in the Unity version we are/were working in. We did find scrambled evidence that suggests newer versions of Unity might be able to do something along those lines.

Solution:
We worked around this issue by basically remaking almost the entire default Unity Inspector from scratch, which provided plenty of headaches, but also heavily extended our knowledge about Unity Editors/Scripts.

Moving elements in a list of a list of structs

The Component Collection is a list of categories with components in them. The Component Collection allows for easy management of components in categories. You can simply select a category in a dropdown menu on each component in the Collection and it will automatically be moved to this category or create one if there is none already.

Trying to do this caused several issues, including but not limited to: Clearing the entire list accidently, not clearing the list accidently, getting duplicate components and much, much more…

Fixing these issues mostly just took a lot of time and trial and error work to fix. After extenstive testing we deemed the Component Collection “bug free”.

Bugs, Bugs & More Bugs

While making the Custom Component Filter, we, as the title suggets, ran into a LOT of bugs. One such bug had to do with hiding all the components on a gameobject because, for example, searching for a component that does not exist on the object. This would cause the entire Inspector to become entirely empty and an error to occur saying there was nothing to render.

Future Plans

While working on this, we generated a lot of extra ideas that could be beneficial to the project. Let’s get into them!

Finishing Recreating the Default Inspector

As mentioned in the Obstacles We Encountered section, we had to completely recreate the default Unity Inspector from scratch. But because of time restrictions we were never able re-implement every feature in the default Unity Inspector.

Inspector Foldouts

We wanted that in the inspector it would be more visable to see which scripts belongs to which category. So we thought about inspector foldouts. What this should do is placing all the scripts with the same category together. Where you can fold them in/out and the scripts have a unique color to their category.

Category Creator

If you want to create new categories you need to add them to an Enum. We wanted a visual category creator in the component collection. Where you just need to type a word and a new category is created.