Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Setting filters on ObjectField ObjectPicker

Discussion in 'Immediate Mode GUI (IMGUI)' started by Sangemdoko, Aug 21, 2019.

  1. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    195
    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:
    Code (CSharp):
    1. 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:
    Code (CSharp):
    1. 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. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,027
    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.
     
  3. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    195
    That would be even better!
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,177
  5. HG_SB

    HG_SB

    Joined:
    Dec 9, 2015
    Posts:
    36
    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.
     
    NotaNaN likes this.
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    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.
     
    NotaNaN and Vaarz like this.
  7. slippyfrog

    slippyfrog

    Joined:
    Jan 18, 2016
    Posts:
    32
    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.
    upload_2021-8-25_13-56-34.png
    upload_2021-8-25_13-55-51.png
     
    NotaNaN likes this.