<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/ActionHandlerProtocol",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation21ActionHandlerProtocolP"
  },
  "title" : "ActionHandlerProtocol"
}
-->

# ActionHandlerProtocol

The base protocol for action handlers.

```
protocol ActionHandlerProtocol
```

## Overview

One of two approaches can be taken when subscribing to, and responding to action events. Which approach is taken
is dictated by complexity of the action, and user preference.

The simplest approach is to process action events using an external closure. This saves having to define
a formal handler for the action. For example:

```swift
struct MyAction: EntityAction {
    ...
}
MyAction.subscribe(to: .started) { event in
    let action = event.action
    // Do something with the action.
}
```

The other approach is to use a formal handler. This requires defining a structure for the handler
that conforms to the `ActionHandlerProtocol` and registering the handler so it can be instantiated
when the action animation is played. It is only necessary to define the event functions for the event types
that one wishes to respond to.

For example:

```swift
struct MyAction: EntityAction { }

struct MyActionHandler: ActionHandlerProtocol {

   typealias ActionType = MyAction

   // Application data can be stored within the handler.
   var applicationData: ApplicationData

   // Customizable init
   init(action: MyAction, player: Entity, currentLevel: Int) { ... }

   // Process start events
   mutating func actionStarted(event: EventType) { }
}

MyActionHandler.register { event in
    // Create the handler.
    return MyActionHandler(applicationData: appData)
}
```

## Topics

### Associated Types

[`associatedtype ActionType : EntityAction`](/documentation/RealityKit/ActionHandlerProtocol/ActionType)

The action type associated that is associated with the handler.

### Instance Methods

[`func actionEnded(event: Self.EventType)`](/documentation/RealityKit/ActionHandlerProtocol/actionEnded(event:))

The function used to respond to action ended events.

[`func actionPaused(event: Self.EventType)`](/documentation/RealityKit/ActionHandlerProtocol/actionPaused(event:))

The function used to respond to action paused events.

[`func actionResumed(event: Self.EventType)`](/documentation/RealityKit/ActionHandlerProtocol/actionResumed(event:))

The function used to respond to action resumed events.

[`func actionSkipped(event: Self.EventType)`](/documentation/RealityKit/ActionHandlerProtocol/actionSkipped(event:))

The function used to respond to action skipped events.

[`func actionStarted(event: Self.EventType)`](/documentation/RealityKit/ActionHandlerProtocol/actionStarted(event:))

The function used to respond to action started events.

[`func actionTerminated(event: Self.EventType)`](/documentation/RealityKit/ActionHandlerProtocol/actionTerminated(event:))

The function used to respond to action terminated events.

[`func actionUpdated(event: Self.EventType)`](/documentation/RealityKit/ActionHandlerProtocol/actionUpdated(event:))

The function used to respond to action updated events.

### Type Aliases

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

The event type returned to each event function in the handler.

### Type Methods

[`static func register((Self.EventType) -> (any ActionHandlerProtocol)?)`](/documentation/RealityKit/ActionHandlerProtocol/register(_:))

Registers a handler that responds to raised action events for a particular action type.

## Relationships

### Inherited By

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

---

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)