<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/BehaviorTreeResource",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation20BehaviorTreeResourceC"
  },
  "title" : "BehaviorTreeResource"
}
-->

# BehaviorTreeResource

An immutable representation of a behavior tree.

```
class BehaviorTreeResource
```

## Overview

A `BehaviorTreeResource` can be produced by compiling a tree definition.
Once compiled, assign it to an entity via [`BehaviorTreeComponent`](/documentation/RealityKit/BehaviorTreeComponent) to begin driving behaviors:

let treeResource1 = try BehaviorTreeResource(definition: Data(behaviorTreeDefinition1.utf8))
let treeResource2 = try BehaviorTreeResource(definition: Data(behaviorTreeDefinition2.utf8))
let treeResources: [String : BehaviorTreeResource] = [“tree1” : treeResource1, “tree2” : treeResource2]
entity.components.set(BehaviorTreeComponent(behaviorTree: resource,
availableBehaviorTrees: treeResources))

## Parameters

The tree exposes a set of named parameters that control its behavior at runtime, such as
movement speed. Read the available parameters via [`parameterNames`](/documentation/RealityKit/BehaviorTreeResource/parameterNames). To set values at
runtime, use the entity’s parameter binding:

entity.parameters[“MoveSpeed”] = BindableValue(Float(1.0))

## Topics

### Creating a behavior tree

[`convenience init(definition: Data) throws`](/documentation/RealityKit/BehaviorTreeResource/init(definition:))

Compile a new resource from data, throws on failure.

### Validating a definition

[`static func validate(definition: Data) -> [String]`](/documentation/RealityKit/BehaviorTreeResource/validate(definition:))

Run the compiler and return all tree errors without producing a resource.

### Accessing parameters

[`var parameterNames: [String]`](/documentation/RealityKit/BehaviorTreeResource/parameterNames)

Returns the names of all parameters in the behavior tree resource.

## Relationships

### Conforms To

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

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)