Contents

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.

Declaration

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

Parameters

  • event:

    The event type to subscribe to. For example Update or 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 Scene.

  • componentType:

    An optional component type to filter events to if the event is of the type Componentevents. Set to nil to listen for all events of the event type within the Scene.

  • handler:

    A closure that runs when the event occurs.

Return Value

An object that represents the subscription to this event stream.

See Also

Publishing and subscribing to events