Have an AI Recover When Energy Runs Low
Give an AI-controlled pawn the Recover ability and Energy attribute. The pawn should recover below 30 energy and resume its normal behavior afterward. Use the tree type that already drives your AI.
Choose recovery from the Blackboard
Give the pawn an AI Controller running your Behavior Tree. In its Blackboard, add a Float key called
CurrentEnergy. Attach the Update Attributes service to a Selector that stays active during both recovery and normal behavior. Map Energy toCurrentEnergy.Make the Selector's first child a recovery Sequence and the second its normal behavior. Add a Blackboard decorator to recovery for
CurrentEnergyless than 30. Set Observer Aborts to Lower Priority so a drop in energy can interrupt normal behavior.Add Activate Gameplay Ability to recovery. Choose Ability Class and select
GA_Recover. For the instant recovery move, turn off Wait for Ability to End. For a move with a recovery animation, enable that option and end the ability when the animation finishes.
If several recovery moves are available, the Select Gameplay Ability service can write a choice into a Blackboard Class key. Set the activation task to Blackboard Class to consume it. A custom C++ service can subscribe to GetGameplayAttributeValueChangeDelegate on the pawn's component to update another decision value. Read the initial value when binding and remove the delegate when the service stops.
Choose recovery in a State Tree
Give
GA_Recoverthe asset tagAbility.Training.Recover. Create a Blueprint State Tree evaluator, add it to the tree, and expose a float calledCurrentEnergy. Give it an initial value above 30 until the pawn is ready. On Tree Start and on Tick, use Get Float Attribute on the controlled pawn to read Energy. Only use the value when the attribute lookup succeeds.Place a Recover state before the normal state under a parent that selects its first eligible child. Bind a float comparison on Recover's enter conditions to the evaluator's output and test for less than 30. From normal behavior, add a conditional transition to Recover when energy drops below 30 so the tree checks it again while running.
In Recover, add Activate Gameplay Ability and set Ability Activation Tags to
Ability.Training.Recover. Enable Should Finish State When Ability Completes. Transition to normal behavior on success. If interruption should stop the move, enable Should Cancel Ability When State Finishes.
For a move with a cooldown, a utility-based State Tree can use the Ability Cooldown consideration. Match the tag granted by its cooldown effect and give the state a lower score while that effect is active. To limit repeated moves, the Ability Tracker evaluator exposes Consecutive Executions for abilities matching its filter.
A Blueprint listening outside either tree can use Wait For Ability End with a query for the recovery ability's asset tag. The callback reports whether the ability was cancelled.
Try It in Play
Start the pawn at 25 energy. Watch the pawn's Blackboard or State Tree debugger alongside its ability system. Recovery should run once, raise energy to 75, and return the pawn to normal behavior. Apply an effect that takes 50 energy away. The same pawn should choose recovery again when its value drops to 25. If the value changes but the pawn stays idle, check the ability grant on the controlled pawn and the class or asset tag used by the activation task.