<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/BehaviorTreeAction/subscribe(to:_:)-9mrvx",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation18BehaviorTreeActionPAAE9subscribe2to_yAA0E9EventTypeV_AA0E6ResultOAA0eH0VyxGctFZ"
  },
  "title" : "subscribe(to:_:)"
}
-->

# subscribe(to:_:)

Subscribes to a serializable action event and returns a `ActionResult`.

```
@MainActor @preconcurrency static func subscribe(to eventType: ActionEventType, _ handler: @escaping @MainActor (ActionEvent<Self>) -> ActionResult)
```

## Discussion

For example, you can call this method to subscribe to the update event,
which the system calls each frame it evaluates the action:

```swift
struct MyAction: BehaviorTreeAction, Codable {
    // ...
}
MyAction.subscribe(to: .updated) { event in
    // Return value is the action result.
    return .success
}
```

---

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)