Root objects are not dragged in the hierarchy.
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
- Create a new scene
- Create a Canvas on the scene
- Drag the RuntimeHierachy prefab to the Canvas
- m_canReorganizeItems set in status "true"
- 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
@yasirkula I think problem in HierarchyDragDropListener in logic DropTransformOnto
I'll take a look at this. Just haven't had the chance yet.
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.
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; }.
It will throw an exception but feel free to try it for yourself.
Bump! Kindly look into this.
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.