docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method SetParent

    SetParent(EntityManager, Entity, Entity, bool)

    Establish a new link between a child and parent entity.

    Declaration
    public static void SetParent(this EntityManager em, Entity child, Entity newParent, bool preserveWorldTransform = true)
    Parameters
    Type Name Description
    EntityManager em

    The EntityManager.

    Entity child

    The entity whose parent should be changed.

    Entity newParent

    The new parent entity for child. If this value is Null, child will have no parent and will become the root of a new hierarchy.

    bool preserveWorldTransform

    If true, the world-space transform of child will be preserved as closely as possible by setting its LocalTransform component to match its current world-space transform. Slight differences are still possible due to floating-point rounding.

    If false, child's LocalTransform components will not be modified. However, the existing value will now be relative to world-space instead to its previous parent; this may cause a significant instantaneous change in its world-space transform.

    Remarks

    This operation completes synchronously, leaving all effected transform hierarchies in a consistent state. It guarantees the following postconditions:

    • If newParent exists, child will have the Parent and PreviousParent components with the value set to newParent, and newParent will have a Child buffer component containing child.
    • If newParent does not exist, child will not have the Parent or PreviousParentcomponent.
    • If child already had the Parent component with a value other than newParent, the previous parent will no longer contain a reference to child in its Child buffer. If this would have left the previous parent's Child buffer empty, its buffer component will be removed.

    This function must not be used from an ExclusiveEntityTransaction context. Manipulating transform hierarchies from worker threads is not safe.

    Exceptions
    Type Condition
    ArgumentException

    Thrown if child does not exist.

    ArgumentException

    Thrown if newParent is not Null and does not exist.

    InvalidOperationException

    Thrown if preserveWorldTransform is true, but child or newParent (or their ancestors) do not have the required LocalTransform component.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)