The SetParent
method allows you to set a new parent for the current GameObject
. This method is useful for organizing objects within a scene hierarchy, enabling you to change the parent-child relationships dynamically. The method takes two parameters:
value
: The new parentGameObject
to which the current object will be attached. Ifnull
, the object will be detached from its current parent and become a root object.keepWorldPosition
: A boolean value indicating whether the object should maintain its current world position when reparented. Iftrue
, the object's world position remains unchanged; iffalse
, the object's local position relative to the new parent is recalculated.