An External Behavior Tree stores reusable behavior in a project asset. Use one
when several agents share a tree or when a repeated branch should have a single
source of truth.

Create and open an external tree

  1. Open the source tree in the Behavior Designer editor.
  2. Choose Save As External Behavior Tree from the graph context menu or use
    the export control in the operations toolbar.
  3. Save the asset in a runtime folder.
  4. Select the asset and use Open to edit it.

The Attack External Behavior Tree describes seeking and attacking the target and exposes Position and Target variables.

Assign the asset to External Behavior on a Behavior Tree component when the
entire component should run it. Use a Behavior Tree Reference task when the
external tree should run as one branch of a larger tree.

Override variables

When a parent and external tree contain variables with the same name and type,
the parent’s value overrides the external asset’s default at runtime. This lets
one patrol asset use different destinations, speeds, or targets for each agent.

A Behavior Tree Reference task can also provide values for a particular
reference. Use per-reference values when the same parent tree invokes one
external asset more than once with different inputs.

Runtime assignment

You can switch the external tree through the component API. Disable the running
behavior before replacing ExternalBehavior, then enable it again so the new
tree starts cleanly.

using BehaviorDesigner.Runtime;
using UnityEngine;

public class BehaviorLoadout : MonoBehaviour
{
    [SerializeField] private BehaviorTree behaviorTree;
    [SerializeField] private ExternalBehavior externalBehavior;

    public void Apply()
    {
        behaviorTree.DisableBehavior();
        behaviorTree.ExternalBehavior = externalBehavior;
        behaviorTree.EnableBehavior();
    }
}

For a frequently reused runtime pool, instantiate each ExternalBehavior, call
Init() once to deserialize it, and then assign the initialized instance.

Verify reuse

Run two agents that reference the same external asset but override one variable
with different values. Both should execute the same structure while using their
own value. If an override is ignored, confirm that its name, capitalization, and
shared-variable type match the external variable exactly.

See Variables for scope and assignment rules and the
Behavior Tree component for component-level
external behavior settings.