One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

TransientComponent

protocol · iOS 15.0+ · SDK 27.1

protocol TransientComponent : Component

An interface for components that aren’t saved to file or cloned. Components that conform to the ``TransientComponent`` protocol aren’t included when RealityKit serializes its owning entity to save it to a file. Similarly, when you clone an entity, any transient components on that entity aren’t copied to the clone. To ensure that cloned entities, or entities saved to file get a copy of the transient component with default values, create and initialize the component in your entity’s `init()` method: ```swift class MyEntity: Entity { required init() { let newComponent = MyComponent() components[MyComponent.self] = newComponent return newComponent } } ``` Alternatively, you can create a computed property for your component that initializes it to default values the first time your code accesses it. ```swift class MyEntity: Entity { var myComponent: MyComponent { // If the component exists, return it. if let component = components[MyComponent.self] { return component } // Create a new component and return it. components[MyComponent.self] = MyComponent() return newComponent } } ``` Use transient components to represent runtime state for an entity. For example, an entity representing a fish in a virtual aquarium might store attributes such as hunger in a transient component. In networked AR experiences, RealityKit sends transient components to peers when it sends the entity, if the component also conforms to <doc://com.apple.documentation/documentation/swift/codable>. If transient components don’t conform, ReaityKit still sends the entity to network peers, but it excludes the transient component.

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →