setParent(_:preservingWorldTransform:)
Attaches the entity as a child to the specified entity.
Declaration
@MainActor @preconcurrency func setParent(_ parent: Entity?, preservingWorldTransform: Bool = false)Parameters
- parent:
The new parent entity. Use
nilto detach the entity from its current parent. - preservingWorldTransform:
A Boolean that you set to
trueto preserve the entity’s world transform, orfalseto preserve its relative transform. Usetruewhen you want a model to keep its effective location and size within a scene.
Discussion
Attaching an entity to a new parent automatically detaches it from its old parent.
The children collections of both the old and new parent are automatically updated as well.