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)
public class HiearachySelectionButton : Button
{
public HiearachySelectionButton(Func<Object> GetObject)
{
text = "Select in hierarchy";
clicked += () =>
{
var obj = GetObject();
Selection.SetActiveObjectWithContext(obj, obj);
var result = Highlighter.Highlight("Inspector", "m_Script", HighlightSearchMode.Auto);
Debug.Log(result);
};
}
}
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.
And then when I wish to highlight it using the following code, which is run when clicking a button in a custom editor
public void SelectInHierarchy()
{
var obj = m_GetObject();
Selection.SetActiveObjectWithContext(obj, obj);
//The identifier text is the same as on the custom inspector.
var highlightTask = HighlightDelayed("CustomIdentifier"+obj.GetInstanceID());
}
protected async Task HighlightDelayed(string indentifier)
{
await Task.Delay(500);
var result = Highlighter.Highlight("Inspector", indentifier, HighlightSearchMode.Identifier);
Debug.Log(result);
await Task.Delay(500);
Highlighter.Stop();
}
I get the following warning:
Warning:
Highlighter recursion detected. You are calling Highlighter.Highlight() with too much abandon. Avoid highlighting during layout and repaint events.
UnityEditor.Highlighter:Highlight(String, String, HighlightSearchMode)
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.
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.
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.
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.
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
Hey all, stumbled across this while trying to do something similar and figured I’d share what I found. I’ve wasted enough time on trying to get this to work, but if anyone else has any additional insights that’d be great.
Like @Sangemdoko 's original post I’m trying to setup a button that when pressed will cause the inspector to jump to a component on another object. I was able to get the Highligher to work, but it has a few quirks that don’t make it a great solution.
First off, Highlighter won’t be able to find things in collapsed components. So if you have like a 20 components on an object and their all collapsed to save on space Highlighter won’t be able to find whatever your looking for and you’ll get an “Item itemName not found in window Inspector.” warning instead.
The second issue I ran into is that changing the selected object seems to conflict with the highlighter? I was only able to get the highlighter to work for highlighting items on the same object, with an implementation like in the original post by @Sangemdoko where a different object is selected before highlighting what ends up happening is the Inspector updates to the new selection but just doesn’t do the highlight. I’m guessing the inspector window refreshing messes with the highlight, delaying the highlight till after the window is redrawn might work but I didn’t test it.
Finally last, and most damning, is that when I did get the highlighter to finally work it was… super slow? I had expected it to instantly snap to the highlighted item, but instead it sloooooowly scrolled up through the list of components until it got to the highlighted item. I get that something like that might be useful if you want to show exactly where the highlighted item is in relation to the current inspector view, but if my goal is quickly snapping between components then I might as well just scroll through the component list myself at that point.
If anyone has any ideas on how to achieve this sort of instant snapping between components on different objects that’d be great, it feels like there’s some sort of really obvious solution I’m missing, but I can’t spend any more time on this.
Edit: This is all on 2023.2.20f1, don’t know if it’s different in later versions