<!--
{
  "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/BehaviorTreeActionHandler",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation25BehaviorTreeActionHandlerP"
  },
  "title" : "BehaviorTreeActionHandler"
}
-->

# BehaviorTreeActionHandler

Behavior Tree-specific event handlers that allow an `ActionResult` to be returned from the handler.

```
protocol BehaviorTreeActionHandler : ActionHandlerProtocol
```

## Overview

Behavior trees send Started, Updated and Ended events. Optionally subscribe directly to any of
these events in order to override default event handling in cases when conforming a new, custom
event handler type.

Example:

```swift
struct MyAction: BehaviorTreeAction, Codable {
    // ...
}

struct MyActionHandler: BehaviorTreeActionHandler {
    typealias ActionType = MyAction

    //... add some optional state data here.

   // Action updated event handler.
   public mutating func actionUpdatedWithResult(event: EventType) -> ActionResult? {
       // ... handle the 'updated' event.

       // Return the action result.
       return .success
   }
}

// The handler must be registered in order to receive events:
MyActionHandler.register { event in
    return MyActionHandler()
}
```

## Topics

### Responding to action progress

[`func actionStartedWithResult(event: Self.EventType) -> ActionResult?`](/documentation/RealityKit/BehaviorTreeActionHandler/actionStartedWithResult(event:))

[`func actionUpdatedWithResult(event: Self.EventType) -> ActionResult?`](/documentation/RealityKit/BehaviorTreeActionHandler/actionUpdatedWithResult(event:))

[`func actionPausedWithResult(event: Self.EventType) -> ActionResult?`](/documentation/RealityKit/BehaviorTreeActionHandler/actionPausedWithResult(event:))

[`func actionResumedWithResult(event: Self.EventType) -> ActionResult?`](/documentation/RealityKit/BehaviorTreeActionHandler/actionResumedWithResult(event:))

### Responding to action completion

[`func actionEndedWithResult(event: Self.EventType) -> ActionResult?`](/documentation/RealityKit/BehaviorTreeActionHandler/actionEndedWithResult(event:))

[`func actionTerminatedWithResult(event: Self.EventType) -> ActionResult?`](/documentation/RealityKit/BehaviorTreeActionHandler/actionTerminatedWithResult(event:))

[`func actionSkippedWithResult(event: Self.EventType) -> ActionResult?`](/documentation/RealityKit/BehaviorTreeActionHandler/actionSkippedWithResult(event:))

## Relationships

### Inherits From

[`ActionHandlerProtocol`](/documentation/RealityKit/ActionHandlerProtocol)

---

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)