UnityRuntimeInspector icon indicating copy to clipboard operation
UnityRuntimeInspector copied to clipboard

Selecting a Transform any other way than clicking it in the hierarchy, leads to wrong results when range selecting afterwards

Open i-xt opened this issue 4 years ago • 3 comments

Description of the bug

When a Transform is selected without clicking it's field in the hierarchy (either by calling RuntimeHierarchy.Select() or by enabling RuntimeHierarchy.syncSelectionWithEditorHierarchy and clicking the GameObject in Unity's hierarchy) RuntimeHierarchy.multiSelectionPivotTransform and RuntimeHierarchy.multiSelectionPivotSceneData are not set. As a result, the wrong items are selected when range selecting afterwards, without clicking another item in the hierarchy first.

Reproduction steps

The easiest way to reproduce this is to use the syncSelectionWithEditorHierarchy option.

  1. Set RuntimeHierarchy.syncSelectionWithEditorHierarchy and RuntimeHierarchy.m_allowMultiSelection to true
  2. Start play mode
  3. Select an item in the runtime hierarchy
  4. Select an item in Unity's hierarchy
  5. Range select another item in the runtime hierarchy

Result: The items between the one that was selected in step 3 and the one that was selected in step 5 get selected. Expected result: The items between the one that was selected in step 4 and the one that was selected in step 5 get selected.

2021-12-20-13-45-05

Platform specs

  • Unity version: 2020.3.19f1
  • Platform: Windows
  • How did you download the plugin: Package Manager (GitHub)

i-xt avatar Dec 20 '21 13:12 i-xt

Thank you for the detailed Issue. I've been working hard on other plugins for a long while (hopefully not for long now) so I couldn't take a look at most other Issues (including this). Will see what can be done about it. It won't be trivial because objects can appear in pseudo-scenes as well and they can also be filtered in RuntimeHierarchy.

yasirkula avatar Dec 27 '21 17:12 yasirkula

What is the field/property that lets the hierarchy know which one is the last selected by clicking it in the hierarchy?

public List<HierarchyField> GetDrawers(Transform transform) =>
	drawers.FindAll(val => val.Data.BoundTransform == transform);
	
public void TreatAsLastSelected(HierarchyField drawer)
{
	lastClickTime = Time.realtimeSinceStartup;
	lastClickedDrawer = drawer;
}

I tried adding this on RuntimeHierarchy.cs and then call it like this

var items = hierarchy.GetDrawers(list[list.Count - 1]);
if (items.Count > 0)
    hierarchy.TreatAsLastSelected(items[items.Count - 1]);

but it seems like I got the wrong lastClickedDrawer? Still has the same behavior as the issue....

Rhitomaic avatar Jul 11 '24 03:07 Rhitomaic

It's this one: https://github.com/yasirkula/UnityRuntimeInspector/blob/52ff3168983d48f012119f6c013d7b495c9f44a4/Plugins/RuntimeInspector/Scripts/RuntimeHierarchy.cs#L824

However, the hierarchy uses a recycled list view, meaning that only the visible Transforms' HierarchyFields are generated.

Here's how I had resolved this issue on another project. Note that line numbers may not match exactly:

image

yasirkula avatar Jul 11 '24 14:07 yasirkula