Unity AI Decision Making Not Working - Behavior Tree Fix
Problem Statement
Your Unity AI or NPCs are not making decisions: they stand still, never change state, or the behavior tree (or state machine) never seems to run or advance. You expect the AI to choose actions, switch behaviors, or react to the player, but nothing happens.
Common symptoms:
- NPC does nothing or stays in one state
- Behavior tree root or nodes never execute
- Decisions never update (e.g. always same action)
- AI works in editor but not in build
- Custom behavior tree or decision script does not tick
- "AI not making decisions" or "behavior tree stuck"
Root Cause Explanation
AI decision making can fail for several reasons:
- Execution not running – The behavior tree, utility AI, or decision system is never ticked (missing update call, disabled component, or wrong execution order).
- Stuck nodes or conditions – A node never returns Success/Failure, or all conditions fail so the tree never advances.
- Data or references – Missing reference to player, world, or blackboard; null checks failing; or data not updated so decisions are stale.
- State or tree structure – Initial state wrong, no valid transition, or root node never runs because the runner is disabled or not in the right scene.
- Platform or build – Different behavior in build (e.g. timing, script stripping, or missing dependencies).
This guide walks through fixes in order of likelihood so you can get AI decision making working again.
Step 1: Confirm the Decision System Is Running
If the behavior tree or decision script never runs, no decisions will be made.
Steps:
- Locate the component that runs the AI (e.g. Behavior Tree runner, Utility AI runner, or your own script that calls
Tick()/Update()on the tree). - Ensure the GameObject is active and the component is enabled.
- In the Inspector, confirm the Behavior Tree (or decision asset) is assigned and not None.
- If using a package (e.g. Unity ML-Agents, third-party behavior tree asset): check that the agent or runner is in the scene and that Update or FixedUpdate is calling the tree (see package docs).
- Add a simple Debug.Log in the root node’s or runner’s update method; run the game and confirm the log appears every frame or at the expected interval.
Verification: You see your debug log (or breakpoint) when playing; the runner component is enabled and has a valid tree assigned.
Pro tip: Use the package’s debugger or visualization if available (e.g. behavior tree viewer in Scene/Game view) to see which node is active. If nothing is active, the tree is not running.
Step 2: Check for Stuck Nodes or Conditions
A node that never completes (e.g. infinite loop, or condition that never becomes true) can block the rest of the tree.
Steps:
- Open the behavior tree (or decision graph) and find the root and first child nodes.
- For Selector (priority) nodes: children are tried in order until one returns Success. If the first child never returns (e.g. a condition that never succeeds), the tree stays there. Temporarily simplify or bypass that node to test.
- For Sequence nodes: all children must succeed. If one never succeeds (e.g. "Wait for 10 seconds" but timer not implemented), the sequence never completes. Add timeouts or ensure leaf nodes eventually return Success/Failure.
- For conditions: ensure the condition can become true (e.g. reference to player exists, distance/angle values are correct). Add Debug.Log to condition checks to see if they are evaluated and what they return.
- If using a custom node: ensure it returns a status (Success, Failure, or Running) and that Running is only returned while the node is still working; otherwise the tree can hang on that node.
Verification: With debug or simplified nodes, the tree advances and you see other nodes run. You can then reintroduce the real logic and fix the stuck condition.
Common mistake: Using a "Wait" or "In Progress" node that never transitions to Success or Failure, so the parent never gets a result.
Step 3: Verify Data and References
Decision systems often depend on world data (player position, health, targets). If those references are missing or stale, decisions can be wrong or never change.
Steps:
- Open the Blackboard or data asset your behavior tree uses (if applicable). Ensure all required keys exist and are typed correctly.
- In the Inspector (or in code), check that references (e.g. Player Transform, Target, NavMeshAgent) are assigned and not None.
- If the AI uses world queries (raycasts, overlap sphere, pathfinding): ensure the layers and tags are set so the queries hit the right objects; otherwise "target found" might always be false.
- If decisions are driven by events (e.g. "OnDamageReceived"): ensure the event is actually invoked and that the behavior tree or state machine is subscribed and reacts (e.g. switches to a "Flee" or "Attack" state).
- In builds, confirm that the same references and data are available (e.g. no script stripping removing a type used by reflection, or missing scene object).
Verification: Log key inputs (e.g. distance to player, current target). Values update as expected when you move the player or change the world. No null references in the console.
Step 4: Check State Machine or Tree Structure
If the structure is wrong, the AI may start in a state or branch that has no valid transition or no actions.
Steps:
- Initial state or root: Ensure the behavior tree has a valid root and that the default branch can run (e.g. Idle → Patrol or Check Player → Chase).
- Transitions: For state machines, ensure at least one transition from the current state can fire (conditions are correct and the next state exists).
- Empty or disabled branches: If a node has no children or they are disabled, the node may return Failure immediately and the parent might not have a fallback; add a fallback or fix the branch.
- Execution order: If multiple scripts affect the same AI (e.g. one script sets "target" and another reads it), ensure they run in the right order (Script Execution Order or single coordinator script).
Verification: In the behavior tree debugger or with logs, you see the expected initial node and transitions when you change the game state (e.g. player in range).
Step 5: Build and Platform Checks
If AI works in the Editor but not in a build, the cause is often environment-specific.
Steps:
- Script stripping: In Player Settings, if "Strip Engine Code" or aggressive stripping is on, ensure no AI or reflection-dependent code is removed. Test with stripping disabled to confirm.
- Frame rate or timing: If the decision system runs in Update and the build has a very different frame rate, or if it uses unscaled time incorrectly, behavior can differ. Prefer delta time and consistent tick rates.
- Scenes and prefabs: Ensure the AI runner and tree are in the built scene (or instantiated at runtime) and that prefab overrides did not clear the tree or blackboard reference.
- Logs and debugging: Add a simple log or on-screen text in build to confirm the AI script is running and the tree is assigned.
Verification: Same behavior in development build as in Editor, or you have identified a stripping/timing/scene difference and fixed it.
Summary
- Confirm the decision system runs – Runner enabled, tree assigned, and Tick/Update called; use debug logs or package debugger.
- Fix stuck nodes – Ensure every node eventually returns Success/Failure (or correct Running); check conditions and timeouts.
- Verify data and references – Blackboard and references filled; world queries hit the right objects; events fire and are handled.
- Check structure – Valid root and initial state; transitions can fire; no empty or broken branches.
- Test in build – Rule out stripping, timing, and scene/prefab issues.
Bookmark this page for quick reference when AI decision making or behavior trees stop updating. If your issue is with pathfinding (NavMesh) or ML-Agents, see our Unity AI NavMesh Not Generating and Unity AI Integration guides for more targeted steps.