<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/RealityRenderer/subscribe(to:on:componentType:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation0A8RendererC9subscribe2to2on13componentType_AA17EventSubscriptionVxm_AA0I6Source_pSgAA9Component_pXpSgyxctAA0I0RzlF"
  },
  "title" : "subscribe(to:on:componentType:_:)"
}
-->

# subscribe(to:on:componentType:_:)

Subscribes to an event type, optionally limited to
events affecting a source entity or scene,
or limited to
a specific component type for component events.

```
func subscribe<E>(to event: E.Type, on sourceObject: (any EventSource)? = nil, componentType: (any Component.Type)? = nil, _ handler: @escaping (E) -> Void) -> EventSubscription where E : Event
```

## Parameters

`event`

The event type to subscribe to.
For example [`SceneEvents.Update`](/documentation/RealityKit/SceneEvents/Update) or [`ComponentEvents.DidAdd`](/documentation/RealityKit/ComponentEvents/DidAdd).

`sourceObject`

An optional source for the event, such as an entity or a scene.
Set to `nil` to listen for all events of the event type within the [`RealityRenderer`](/documentation/RealityKit/RealityRenderer).

`componentType`

An optional component type to filter events to if the event is of the type [`ComponentEvents`](/documentation/RealityKit/ComponentEvents).
Set to `nil` to listen for all events of the event type within the [`RealityRenderer`](/documentation/RealityKit/RealityRenderer).

`handler`

A closure that runs when the `event` occurs.

## Return Value

An object that represents the subscription to this event stream.

---

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)