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.
  2. Dismiss Notice

Highlighting a component of a gameobject in the inspector from a custom editor window?

Discussion in 'UI Toolkit' started by Sangemdoko, Sep 23, 2020.

  1. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    217
    Hi,

    I'm making a custom editor that allows be to create a lot of game objects and components. I would like to be able to bounce around components in the inspector from my custom editor.

    Selecting the game object is easy, but I can't find a reliable way for scrolling to the target component and highlighting it. My system is quite advanced with some gameobjects having around 10-20 components. It makes it a pain to find the components I'm looking for, especially for people who are not familiar with the system.

    This is as far as I was able to get (It highlights the wrong thing)

    Code (CSharp):
    1. public class HiearachySelectionButton : Button
    2.     {
    3.         public HiearachySelectionButton(Func<Object> GetObject)
    4.         {
    5.             text = "Select in hierarchy";
    6.             clicked += () =>
    7.             {
    8.                 var obj = GetObject();
    9.                 Selection.SetActiveObjectWithContext(obj, obj);
    10.                
    11.                 var result = Highlighter.Highlight("Inspector", "m_Script", HighlightSearchMode.Auto);
    12.                 Debug.Log(result);
    13.             };
    14.         }
    15.     }
    The Highlighter class seems obsolete when most of the inspectors are custom inspectors I made with UIElements. From what I understand it works by reading the IMGUI stack.

    The highlighting is not necessary for my purpose (although it would be nice). What I'm really after is the scrolling to the correct component in the inspector.

    If you have any ideas I'm all ears.
     
  2. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    217
    Hi,

    I tried something but it still doesn't work for me. i get a warning and nothing gets highlighted I would assume because of the warning.

    The idea was to use a HighlightIdentifier on the rect of my custom inspector
    Code (CSharp):
    1. Highlighter.HighlightIdentifier(container.contentRect, "CustomIdentifier"+target.GetInstanceID());
    And then when I wish to highlight it using the following code, which is run when clicking a button in a custom editor
    Code (CSharp):
    1. public void SelectInHierarchy()
    2.         {
    3.             var obj = m_GetObject();
    4.             Selection.SetActiveObjectWithContext(obj, obj);
    5.            
    6.             //The identifier text is the same as on the custom inspector.
    7.             var highlightTask = HighlightDelayed("CustomIdentifier"+obj.GetInstanceID());
    8.            
    9.         }
    10.  
    11.         protected async Task HighlightDelayed(string indentifier)
    12.         {
    13.             await Task.Delay(500);
    14.            
    15.             var result = Highlighter.Highlight("Inspector", indentifier, HighlightSearchMode.Identifier);
    16.             Debug.Log(result);
    17.             await Task.Delay(500);
    18.             Highlighter.Stop();
    19.         }
    I get the following warning:

    Code (CSharp):
    1. Warning:
    2.  
    3. Highlighter recursion detected.  You are calling Highlighter.Highlight() with too much abandon.  Avoid highlighting during layout and repaint events.
    4. UnityEditor.Highlighter:Highlight(String, String, HighlightSearchMode)
    Any help would be extremely appreciated :)
     
  3. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    217
    Hi,

    I'm sorry to tag you @uMathieu but since you've been so helpful in other posts I was hoping you could direct me to someone who could help me with this issue I have.

    The highlither documentation is here: https://docs.unity3d.com/ScriptReference/Highlighter.Highlight.html
    and here : https://docs.unity3d.com/ScriptReference/HighlightSearchMode.html

    What I really wish to achieve to to jump from one component to another in the in the inspector from a custom editor window. If it could be highlited for half a second that would be even better which is why I'm trying to make Highlighter work with UIelement custom component inspectors.
     
    MostHated likes this.
  4. sebastiend-unity

    sebastiend-unity

    Unity Technologies

    Joined:
    Nov 9, 2015
    Posts:
    183
    Hi Sangemdoko,

    The Highlighter functionality is broken at the moment -- has been for a while. We are now aware and a fix is being worked on. To be fair, @uMathieu has been investigating the problem, I'm answering on his behalf :) Thanks for the usecase, we will make sure yours works with the fix.

    Sebastien
     
  5. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    217
    Thank you @sebastiend-unity , I'm glad to know it will be fixed some day.

    I'm working on an asset on the asset store and currently the required version is 2019.3f+.
    Would you know if that fix would be introduced as a fix on 2019.4 LTS or will it be added in 2020.X+?

    Either way if I want to keep the required version to 2019.3f+ I guess I'll have to find a custom solution. It'll probably require some reflection to get the inspector window such that I can move the scroll value. I'll figure out something for replacing the component highlight.

    If you have any tips on that I'm all ears.
     
  6. sebastiend-unity

    sebastiend-unity

    Unity Technologies

    Joined:
    Nov 9, 2015
    Posts:
    183
    It's a possibility that we might backport the fix all the way to 2019.4 LTS, I can't confirm that information right now.
     
  7. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    242
    any updates?

    I'd like to be able to highlight specific types of components in the inspector for the currently selected game object. You can make some pretty convenient tools with this I think
     
    Last edited: Feb 6, 2021
  8. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    CBHM likes this.
  9. antti_partagames

    antti_partagames

    Joined:
    Nov 5, 2015
    Posts:
    18
    Same problem. Bumping this up.
     
    andersemil likes this.
  10. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    107
    @sebastiend-unity @uMathieu what is the status on this? Do you have a link to issue or some such
     
    Last edited: May 23, 2023
  11. cpalma-unity

    cpalma-unity

    Unity Technologies

    Joined:
    Nov 30, 2020
    Posts:
    90