Class AIBehaviorTree
Root container for a behavior tree. Assign to BehaviorTree to give an NPC high-level decision-making above the state machine.
The tree is evaluated once per AI tick (governed by AI LOD). If the root node
returns Success, the tree produced a state transition
and the current state's UpdateState is skipped for that tick.
If it returns Failure, the current state continues normally.
Example tree:
AIBehaviorTree (root = Selector)
├─ Sequence: [Condition: IsDead] → [StateTransition: DeadState]
├─ Sequence: [Condition: HP ≤ 30%] → [StateTransition: RetreatState]
├─ Sequence: [Condition: EnemyNearby] → [StateTransition: AttackState]
└─ StateTransition: WanderState
[CreateAssetMenu(fileName = "New AI Behavior Tree", menuName = "FishMMO/Character/NPC/AI/Behavior Tree/Behavior Tree")]
public class AIBehaviorTree : ScriptableObject
- Inheritance
-
ObjectScriptableObjectAIBehaviorTree
- 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
Root
The root node of the behavior tree. Typically a AISelector or AISequence.
[Tooltip("Root node of the behavior tree. Typically a Selector.")]
public AIBehaviorNode Root
Field Value
TickRate
How often (in seconds) the tree is re-evaluated. Lower values make the NPC more responsive but cost more CPU. Defaults to 0.5 seconds.
[Tooltip("Seconds between behavior tree evaluations.")]
public float TickRate
Field Value
Methods
Evaluate(AIController)
Evaluates the tree starting from the root.
public AINodeResult Evaluate(AIController controller)
Parameters
controllerAIControllerThe NPC's AI controller.
Returns
- AINodeResult
The result of the root node evaluation.