Contents

init(components:)

Creates an entity with multiple components.

Declaration

@MainActor @preconcurrency convenience init(components: [any Component])

Parameters

  • components:

    The components to add to the entity.

Discussion

This initializer adds the contents of components to the new Entity. The components you specify in this initializer override any default components of the same type that RealityKit creates the entity with, such as Transform.

For example, you can use this initializer to create an entity that anchors to the floor, displays a 1x1x1m box, and has a y-position of 0.5:

let floorCubeComponents = [
    AnchoringComponent(.plane(.horizontal, classification: .floor, minimumBounds: [1, 1])),
    ModelComponent(mesh: .generateBox(size: 1), materials: []),
    Transform(translation: [0, 0.5, 0])
]

let floorCubeEntity = Entity(components: floorCubeComponents)

See Also

Creating an entity