Setting filters on ObjectField ObjectPicker

Hello,

I would like to set the filter of the objectPicker of an ObjectField in a custom Inspector. The reason is that I want to only show the assets that have a certain Asset label. The reason being that I organize my objects per category and I can easily set the category name as an asset label.

When I create my own objectPicker I can do this using this function:

EditorGUIUtility.ShowObjectPicker<MyScriptableObject>(null, false, string.Format("l:{0}", myCategoryName), 0);

It would be great if there was a filter property on ObjectField so that I could do this:

myObjectField.filter = string.Format("l:{0}", myCategoryName) ;

If there is any way of setting the filter of the ObjectPicker when it is open from a certain ObjectField, please let me know as I haven’t found a workaround yet.

2 Likes

This sounds great, though I would want the filter to be a Func<Object, bool> so the filter can be an arbitrary check rather than just exactly a filter for an asset label.

6 Likes

That would be even better!

It’s a good suggestion but it’s not related to UIElements. This is an IMGUI feature request. Moving thread to:

Having more flexibility for EditorGUIUtility.ShowObjectPicker and EditorGUILayout.ObjectField would be great.

I´d like to have the option to let the user only select from a provided list of assets/scene objects. Currently the best way seems to be a combination of GenericMenu/AdvancedDropdown and an object field that checks the selected asset after it´s being assigned.

A custom filter function would help a lot when it comes to writing custom editor GUI. Not sure about performance though when every single asset in your project has to go through the filter function. Maybe it might be better to let the user assemble the list of valid objects and pass it as a parameter.

1 Like

Meandered into this today. Really, really need to narrow down the amount of objects the user can choose from. When it’s textures and you only want linear R8 maps, or if it’s normals and you only want… normals, it’s a godsend for editor tooling.

As it is, it’s become the slowest part of using the tools I have made as the project expands. So I’m probably heading toward having to replace that functionality now, which isn’t much fun really.

2 Likes

I feel like the Object Picker is a bit naïve and could us some improvements in addition to the ones mentioned above.

  • Being able to pass a list of sub folders where the assets reside would be great improvement (via an Attribute or just passing a list to the ShowObjectPicker.
  • Also being able to see the full scene path of the object (vs just the gameobject.name) would be really helpful. This solvers the ambiguity issue when there are several objects in the scene with the same name (See screen shot)

In the following example, many prefabs objects are added to the scene. It is impossible to know which one is selected from the Object Picker. Having a setting to be able to toggle on/off to display the full scene path of the object would be great.
7448603--913532--upload_2021-8-25_13-56-34.png

3 Likes