Course contentsShow
← Unity Game Development
Lesson 553 of 8288. Artificial IntelligenceFree lesson

Integrating GOAP with Unity Animation Controllers

Synchronize the output of the planner with state-driven animations to create fluid transitions between different gameplay actions.

In this lesson, you will learn how to bridge the gap between your GOAP planner’s abstract decision-making and your character's visual representation by synchronizing plan execution with Unity’s Animator states.

The Decoupling Challenge

A GOAP planner operates in a logical space—it sees the world as a set of states like HasWeapon: True or TargetInRange: False. However, your Animator operates in a temporal space defined by clips, transition durations, and blend trees. The bridge between these two is the Action Controller. When your agent selects an action, such as AttackAction, the planner doesn't automatically know when the swing animation finishes. To create fluid movement, you must treat your Animator parameters as a visual reflection of your Blackboard state.

Synchronizing via Parameters

The most robust way to integrate these systems is to map your GOAP actions to Animator parameters (Booleans or Triggers). Avoid driving the animation directly inside the Action.Perform() method, as this creates a tight coupling that ignores transition times. Instead, define an interface where each GOAP Action tells the Animator to enter a state, then relies on Animation Events or State Behaviours to notify the planner that the action is complete.

For example, when your Perform() method starts:

public override bool Perform(GameObject agent) {
    // Tell the animator to transition to the action state
    animator.SetBool("IsAttacking", true);
    
    // Return false to keep the action "active" until the animation triggers a callback
    return isAnimationFinished; 
}

Ensuring Fluid Transitions

To prevent jitter, use Animator layers or AnyState transitions with exit times. When the GOAP planner switches to a new node, it updates the Blackboard. Your script should observe these changes and update the Animator parameters, but allow the Animator to handle the blending. If you interrupt a plan, clear the triggers immediately to ensure the Animator can blend back to an "Idle" or "Locomotion" state gracefully, rather than snapping abruptly.

Key Takeaway: Use the GOAP Blackboard as the source of truth to drive Animator parameters, treating animation completion as the signal that an action's logical effect has been fulfilled.