<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/Entity/ComponentSet",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation6EntityC12ComponentSetV"
  },
  "title" : "Entity.ComponentSet"
}
-->

# Entity.ComponentSet

A collection of components that an entity stores.

```
@MainActor @preconcurrency struct ComponentSet
```

## Overview

A `ComponentSet` represents all the components that an entity holds.
Use this set to add, remove, and update components on an entity.
This set can hold one component of each type.

Access the `ComponentSet` of an [`Entity`](/documentation/RealityKit/Entity)
using its [`components`](/documentation/RealityKit/Entity/components) property.

`ComponentSet` conforms to
<doc://com.apple.documentation/documentation/Swift/Sequence>,
allowing you to iterate over it to access and use each component, as the example below shows:

```swift
for component in entity.components {
    print(component)
}
```

## Topics

### Updating the set

[`func set<T>(T)`](/documentation/RealityKit/Entity/ComponentSet/set(_:)-8sii2)

Adds a new component to the set, or overrides an existing one.

[`func set([any Component])`](/documentation/RealityKit/Entity/ComponentSet/set(_:)-2qzsc)

Adds multiple components to the set,
overriding any existing components of the same type.

[`func remove(any Component.Type)`](/documentation/RealityKit/Entity/ComponentSet/remove(_:))

Removes the component of the specified type from the collection.

[`func removeAll()`](/documentation/RealityKit/Entity/ComponentSet/removeAll())

Removes all components from the collection.

### Accessing members

[`subscript<T>(T.Type) -> T?`](/documentation/RealityKit/Entity/ComponentSet/subscript(_:)-5wdsf)

Gets or sets the component of the specified type.

[`subscript(any Component.Type) -> (any Component)?`](/documentation/RealityKit/Entity/ComponentSet/subscript(_:)-47rhg)

Gets or sets the component with a specific dynamically supplied type.

### Counting members

### Checking for membership

[`func has(any Component.Type) -> Bool`](/documentation/RealityKit/Entity/ComponentSet/has(_:))

Returns a Boolean value that indicates whether the set contains a
component of the given type.

### Accessing components

[`subscript<T>(componentType _: T.Type) -> T?`](/documentation/RealityKit/Entity/ComponentSet/subscript(componentType:)-8y2jv)

Gets or sets the component of the specified type.

[`subscript<T>(T.Type, Void) -> T?`](/documentation/RealityKit/Entity/ComponentSet/subscript(_:_:)-404se)

Gets or sets the component of the specified type.

### Accessing animatable components

[`subscript<T>(componentType _: T.Type) -> T?`](/documentation/RealityKit/Entity/ComponentSet/subscript(componentType:)-3miek)

[`subscript<T>(T.Type, Void) -> T?`](/documentation/RealityKit/Entity/ComponentSet/subscript(_:_:)-b2gl)

[`subscript<T>(withoutAnimation _: T.Type) -> T?`](/documentation/RealityKit/Entity/ComponentSet/subscript(withoutAnimation:))

Gets or sets the component of the specified type, without considering implicit animations.

### Setting components by name

[`func set(qualifiedComponentName: String, representation: some Encodable) throws`](/documentation/RealityKit/Entity/ComponentSet/set(qualifiedComponentName:representation:))

Adds component data to an entity that is written to a Reality file but has no other effect at author time.

### Instance Properties

[`var count: Int`](/documentation/RealityKit/Entity/ComponentSet/count)

The number of components in the collection.

[`var entity: Entity`](/documentation/RealityKit/Entity/ComponentSet/entity)

### Instance Methods

[`func set(_:)`](/documentation/RealityKit/Entity/ComponentSet/set(_:))

Adds multiple components to the set,
overriding any existing components of the same type.

### Subscripts

[`subscript(_:)`](/documentation/RealityKit/Entity/ComponentSet/subscript(_:))

Gets or sets the component with a specific dynamically supplied type.

[`subscript(_:_:)`](/documentation/RealityKit/Entity/ComponentSet/subscript(_:_:))

Gets or sets the component of the specified type.

[`subscript(componentType:)`](/documentation/RealityKit/Entity/ComponentSet/subscript(componentType:))

Gets or sets the component of the specified type.

## Relationships

### Conforms To

[`Copyable`](/documentation/Swift/Copyable)

[`BidirectionalCollection`](/documentation/Swift/BidirectionalCollection)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Escapable`](/documentation/Swift/Escapable)

[`Sequence`](/documentation/Swift/Sequence)

[`Collection`](/documentation/Swift/Collection)

[`Sendable`](/documentation/Swift/Sendable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)