An interface that provides access to a parent entity and child entities.
All entities automatically adopt this protocol because the ``Entity`` base
class does. This adoption gives all entities a collection of methods for
managing the hierarchy.
Removes the given child from the entity.
See the ``HasHierarchy`` protocol’s definition of
``HasHierarchy/removeChild(_:preservingWorldTransform:)`` for more
information.
- Parameters:
- entity:
- preservingWorldTransform: A Boolean that you set to `true` to preserve
the entity’s world transform, or `false` to preserve its relative
transform. Use `true` when you want a model to keep its effective
location and size within a scene.
Removes the entity from its current parent or from the scene if it is a
root entity.
This method behaves like the
``HasHierarchy/setParent(_:preservingWorldTransform:)`` method with a
value of `nil` for the `parent` parameter, except that method has no
effect on root entities. A root entity is one that is stored in a
scene’s ``Scene/anchors`` collection.
The ``HasHierarchy/children`` collections of any modified parent
entities are automatically updated as well.
- Parameters:
- preservingWorldTransform: A Boolean that you set to `true` to preserve
the entity’s world transform, or `false` to preserve its relative
transform. Use `true` when you want a model to keep its effective
location and size within a scene.
get · iOS 13.0+
parent
Swift declaration
@MainActor @preconcurrency var parent: Entity? { get }
The parent entity.
An entity has at most one parent entity. If an entity isn’t part of a
hierarchy, or if it is a root entity, the ``HasHierarchy/parent``
property is `nil`.
Use the ``HasHierarchy/setParent(_:preservingWorldTransform:)`` method
to change an entity’s parent. Use the
``HasHierarchy/removeFromParent(preservingWorldTransform:)`` method to
remove the parent. These methods automatically update the corresponding
``HasHierarchy/children`` collections of the new and old parent.
Adds the given entity to the collection of child entities.
See the ``HasHierarchy`` protocol’s definition of
``HasHierarchy/addChild(_:preservingWorldTransform:)`` for more
information.
- Parameters:
- entity:
- preservingWorldTransform: A Boolean that you set to `true` to preserve
the entity’s world transform, or `false` to preserve its relative
transform. Use `true` when you want a model to keep its effective
location and size within a scene.
get · iOS 13.0+
children
Swift declaration
@MainActor @preconcurrency var children: Entity.ChildCollection { get set }
The child entities that the entity manages.
An entity can have any number of child entities.
Use the ``HasHierarchy/addChild(_:preservingWorldTransform:)`` method to
add a child to an entity. Use the
``HasHierarchy/removeChild(_:preservingWorldTransform:)`` method to
remove one from an entity. These methods automatically update the
``HasHierarchy/parent`` properties of the child entities.
set · iOS 13.0+
children
Swift declaration
@MainActor @preconcurrency var children: Entity.ChildCollection { get set }
The child entities that the entity manages.
An entity can have any number of child entities.
Use the ``HasHierarchy/addChild(_:preservingWorldTransform:)`` method to
add a child to an entity. Use the
``HasHierarchy/removeChild(_:preservingWorldTransform:)`` method to
remove one from an entity. These methods automatically update the
``HasHierarchy/parent`` properties of the child entities.
Attaches the entity as a child to the specified entity.
Attaching an entity to a new parent automatically detaches it from its
old parent.
The ``HasHierarchy/children`` collections of both the old and new parent
are automatically updated as well.
- Parameters:
- parent: The new parent entity. Use `nil` to detach the entity from its
current parent.
- preservingWorldTransform: A Boolean that you set to `true` to preserve
the entity’s world transform, or `false` to preserve its relative
transform. Use `true` when you want a model to keep its effective
location and size within a scene.
> Important: On visionOS, only use `preservingWorldTransform` when
> moving an entity within the same `AnchorEntity`, `ImmersiveSpace` or
> SwiftUI `WindowGroup` hierarchy. Moving entities across these
> hierarchy boundaries while `preservingWorldTransform` is set to
> `true`, is not supported.