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 |
| bool | preserveWorldTransform | If true, the world-space transform of If false, |
Remarks
This operation completes synchronously, leaving all effected transform hierarchies in a consistent state. It guarantees the following postconditions:
- If
newParentexists,childwill have the Parent and PreviousParent components with the value set tonewParent, andnewParentwill have a Child buffer component containingchild. - If
newParentdoes not exist,childwill not have the Parent or PreviousParentcomponent. - If
childalready had the Parent component with a value other thannewParent, the previous parent will no longer contain a reference tochildin 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 |
| ArgumentException | Thrown if |
| InvalidOperationException | Thrown if |