UnityRuntimeInspector icon indicating copy to clipboard operation
UnityRuntimeInspector copied to clipboard

Root objects are not dragged in the hierarchy.

Open 8bitniksis opened this issue 10 months ago • 7 comments

Description of the bug

After the build of the project, the root objects in the hierarchy are not dragged, but in Unity itself they are dragged. demonstration in 1 video

Reproduction steps

  1. Create a new scene
  2. Create a Canvas on the scene
  3. Drag the RuntimeHierachy prefab to the Canvas
  4. m_canReorganizeItems set in status "true"
  5. m_canDropDraggedParentOnChild set in status "true"

Platform specs

Please provide the following info if this is a Unity 3D repository.

  • Unity version: 2020.3.48f1
  • Platform: Windows
  • How did you download the plugin: GitHub

Additional info Video in Unity and after build

https://github.com/user-attachments/assets/49921aeb-1ce1-484d-9b88-5ef0a7d6283b

https://github.com/user-attachments/assets/77a40f22-dd9c-4c87-bce5-605ab5b9b86d

8bitniksis avatar Feb 15 '25 17:02 8bitniksis

@yasirkula I think problem in HierarchyDragDropListener in logic DropTransformOnto

8bitniksis avatar Feb 15 '25 17:02 8bitniksis

I'll take a look at this. Just haven't had the chance yet.

yasirkula avatar Feb 18 '25 16:02 yasirkula

I reproduced the issue and then found this: https://discussions.unity.com/t/bug-getsiblingindex-always-returns-zero-on-scene-root-game-objects-in-build-runtime/563503. Neither GetSiblingIndex nor SetSiblingIndex work for root GameObjects.

yasirkula avatar Feb 23 '25 09:02 yasirkula

Hmm @yasirkula. Maybe can fix in runtime by int GetSiblingIndex(Transform child, Transform parent) { for (int i = 0; i < parent.childCount; ++i) { Debug.Log(child.GetInstanceID() + " - " + parent.GetChild(i).GetInstanceID()); if (child.GetInstanceID() == parent.GetChild(i).GetInstanceID()) return i; } Debug.LogWarning("Child doesn't belong to this parent."); return 0; }.

8bitniksis avatar Feb 23 '25 15:02 8bitniksis

It will throw an exception but feel free to try it for yourself.

yasirkula avatar Feb 23 '25 15:02 yasirkula

Bump! Kindly look into this.

Javasamurai avatar Mar 05 '25 09:03 Javasamurai

Transforms are reordered using SetSiblingIndex in Hierarchy. In builds, neither SetSiblingIndex nor Scene.GetRootGameObjects work for root Transforms (see the thread I've posted before). It should be possible to overcome these issues by keeping track of root Transforms and their order in a dedicated List per scene but it'll have a performance cost as the number of root Transforms increase in a scene because we need to sync that List with Scene.GetRootGameObjects at each refresh (add new Transforms and remove old Transforms). I'm not particularly against this enhancement but I'm worried about its downside.

yasirkula avatar Mar 05 '25 12:03 yasirkula