---
title: "publisher(for:on:)"
framework: realitykit
role: symbol
role_heading: Instance Method
path: "realitykit/scene/publisher(for:on:)"
---

# publisher(for:on:)

Generates a publisher for events of the specified type.

## Declaration

```swift
@MainActor @preconcurrency func publisher<E>(for event: E.Type, on sourceObject: (any EventSource)? = nil) -> Scene.Publisher<E> where E : Event
```

## Parameters

- `event`: The event, like SceneEvents.Update.self.
- `sourceObject`: The source of the event. Set to nil to publish all events of the given type within the scene.

## Return Value

Return Value A publisher for events of the specified type.

## See Also

### Publishing and subscribing to events

- [subscribe(to:on:_:)](realitykit/scene/subscribe(to:on:_:).md)
- [publisher(for:on:componentType:)](realitykit/scene/publisher(for:on:componenttype:).md)
- [subscribe(to:on:componentType:_:)](realitykit/scene/subscribe(to:on:componenttype:_:).md)
