Class AIBehaviorNode
Abstract base class for all behavior tree nodes. Nodes are ScriptableObject assets so designers can build trees entirely in the Unity inspector without code.
Behavior trees sit above the state machine layer and decide which BaseAIState the NPC should transition to. The state machine then handles the actual movement, combat, and animation logic.
Node types:
- AISelector — Tries children left-to-right, returns first success.
- AISequence — Runs children left-to-right, fails on first failure.
- AIInverter — Inverts the child's result.
- AIRepeater — Repeats the child a configurable number of times.
- AIConditionNode — Leaf that checks an AIAbilityCondition.
- AIStateTransitionNode — Leaf that transitions to a BaseAIState.
public abstract class AIBehaviorNode : ScriptableObject
- Inheritance
-
ObjectScriptableObjectAIBehaviorNode
- Derived
- Inherited Members
-
ScriptableObject.SetDirty()ScriptableObject.CreateInstance<T>()Object.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Fields
EditorComment
[TextArea(1, 3)]
[Tooltip("Designer note — has no runtime effect.")]
public string EditorComment
Field Value
EditorPosition
[HideInInspector]
public Vector2 EditorPosition
Field Value
- Vector2
MAX_EVALUATION_DEPTH
Maximum node depth a tree may descend to in one evaluation.
public const int MAX_EVALUATION_DEPTH = 64
Field Value
Remarks
Generous enough that no sane hand-authored tree reaches it, small enough that hitting it costs nothing. A tree deeper than this is a cycle, not a design.
Properties
DepthExceeded
True when the evaluation in progress has descended past MAX_EVALUATION_DEPTH, which means the tree contains a cycle.
public static bool DepthExceeded { get; }
Property Value
Methods
Ascend()
Leaves a child node.
protected static void Ascend()
BeginEvaluation()
Resets the depth counter at the start of a tree evaluation.
public static void BeginEvaluation()
EndEvaluation()
Clears evaluation state once a tree evaluation finishes.
public static void EndEvaluation()
Evaluate(AIController)
Evaluate this node for the given NPC. Called once per behavior tree tick (not every frame).
public abstract AINodeResult Evaluate(AIController controller)
Parameters
controllerAIControllerThe AI controller of the evaluating NPC.
Returns
- AINodeResult
The result of this node's evaluation.
EvaluateChild(AIBehaviorNode, AIController)
Evaluates a child node with depth accounting.
protected static AINodeResult EvaluateChild(AIBehaviorNode child, AIController controller)
Parameters
childAIBehaviorNodeThe child to evaluate. Null returns Failure.
controllerAIControllerThe AI controller of the evaluating NPC.
Returns
- AINodeResult
The child's result, or Failure when the depth limit was hit.
TryDescend()
Enters a child node, refusing to descend when the depth limit has been reached.
protected static bool TryDescend()
Returns
- bool
True when it is safe to descend.
Remarks
Composite and decorator nodes call this before evaluating a child. Returning false turns a cyclic tree into a failed evaluation — the NPC falls back to its state machine — instead of a stack overflow that takes the server process down with it.