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.
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.
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.
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.
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.
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.
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.