Search Unity

Question How does the gameobject drag in the inspector work to maintain the gameobject world position?

Discussion in 'UGUI & TextMesh Pro' started by lenamgiang, Feb 20, 2024.

  1. lenamgiang

    lenamgiang

    Joined:
    Apr 10, 2022
    Posts:
    6
    Hi guys, have a nice day.

    I'd like to ask the mechanic behind the gameobject drag in the inspector.
    I want to change an UI's parent from a heavily nested parent to a simple one in real time. I have tried the following but they did not work:
    - transform.SetParent(parent, worldPositionStays: true/false).
    - Cache transform.position, change parent, and set the new position to cached one.
    - transform.TransformPoint.
    - void OnTransformParentChanged

    I noticed that dragging the UI gameobject in the inspector worked just fine. But I do not know how the drag mechanic works.

    Thank you for your time.