---
title: ActionHandlerProtocol
framework: realitykit
role: symbol
role_heading: Protocol
path: realitykit/actionhandlerprotocol
---

# ActionHandlerProtocol

The base protocol for action handlers.

## Declaration

```swift
protocol ActionHandlerProtocol
```

## Overview

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: 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: 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

- [ActionType](realitykit/actionhandlerprotocol/actiontype.md)

### Instance Methods

- [actionEnded(event:)](realitykit/actionhandlerprotocol/actionended(event:).md)
- [actionPaused(event:)](realitykit/actionhandlerprotocol/actionpaused(event:).md)
- [actionResumed(event:)](realitykit/actionhandlerprotocol/actionresumed(event:).md)
- [actionSkipped(event:)](realitykit/actionhandlerprotocol/actionskipped(event:).md)
- [actionStarted(event:)](realitykit/actionhandlerprotocol/actionstarted(event:).md)
- [actionTerminated(event:)](realitykit/actionhandlerprotocol/actionterminated(event:).md)
- [actionUpdated(event:)](realitykit/actionhandlerprotocol/actionupdated(event:).md)

### Type Aliases

- [ActionHandlerProtocol.EventType](realitykit/actionhandlerprotocol/eventtype.md)

### Type Methods

- [register(_:)](realitykit/actionhandlerprotocol/register(_:).md)

## Relationships

### Inherited By

- [BehaviorTreeActionHandler](realitykit/behaviortreeactionhandler.md)

## See Also

### Action management

- [EntityAction](realitykit/entityaction.md)
- [ActionAnimation](realitykit/actionanimation.md)
- [ActionEntityResolution](realitykit/actionentityresolution.md)
