One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

Event

protocol · iOS 13.0+ · SDK 27.1

protocol Event : Sendable

A type that can be sent as an event. RealityKit provides a number of events you can subscribe to. The system notifies you whenever the event type occurs. For example, you can subscribe to ``RealityKit/CollisionEvents/Began`` to know when two objects begin colliding, or ``RealityKit/SceneEvents/Update`` every time the scene redraws. To subscribe to an event from inside of a ``RealityView`` builder, call one of the ``RealityViewContentProtocol`` `subscribe` methods, for example ``RealityViewContentProtocol/subscribe(to:on:_:)``. Here's an example of subscribing to the event ``CollisionEvents/Began``, which occurs when two entities collide: ```swift struct RealityGame: View { @State var collisionSubscription: EventSubscription? var body: some View { RealityView { content in // Create an entity with model and collision components. let model = ModelComponent( mesh: MeshResource.generateBox(size: .one / 10), materials: [SimpleMaterial(color: .red, isMetallic: false)] ) let collision = CollisionComponent(shapes: [ShapeResource.generateBox(size: .one / 10)]) let collisionEntity = Entity(components: model, collision) content.add(collisionEntity) // Subscribe to collision began event. collisionSubscription = content.subscribe( to: CollisionEvents.Began.self, on: collisionEntity, self.onCollisionBegan ) } } private func onCollisionBegan(_ event: CollisionEvents.Began) { print("collision started") let firstEntity = event.entityA // The entity whose collisions you're subscribing to. let secondEntity = event.entityB // Another entity in the scene. // Respond to collision event... } } ``` - Note: Add a ``CollisionComponent`` to any entities you want to detect collisions for.

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 →