Runtime Targets and Behavior Patterns
Bind movement fields to Graph variables when perception, player commands, encounters, or other gameplay systems must replace a target or destination.
Supply dynamic targets
Use a Transform or GameObject for a target that can move. The task derives its current position during later updates. Use a Vector3 for an authored point or value snapshot.
When another task discovers a destination, store it in one shared variable and bind the movement task to that variable instead of copying the value across several branches.
Change a target from code
This component updates a GameObject variable named MovementTarget. Bind the same variable to Seek, Pursue, Follow, Flee, or Evade as appropriate:
using Opsive.BehaviorDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
public class MovementTargetDriver : MonoBehaviour
{
[SerializeField] private BehaviorTree m_BehaviorTree;
private SharedVariable<GameObject> m_MovementTarget;
private void Awake()
{
m_MovementTarget = m_BehaviorTree.GetVariable<GameObject>("MovementTarget");
}
public void SetTarget(GameObject target)
{
if (m_MovementTarget != null) {
m_MovementTarget.Value = target;
}
}
}
The name and capitalization must match the Graph variable, and the task field must be bound to it. See Accessing Variables and the Behavior Designer Pro API.
Decide whether to continue or abort
Changing a variable does not choose a different graph branch. Use conditions and conditional reevaluation to decide whether a Running task should continue with the new target, be aborted, or yield to another action.
Keep one task or controller responsible for the agent’s destination. When the graph changes from Pursue to Flee, let the first task end or be aborted before the second begins.
Compose common behaviors
Patrol and investigate
Patrol until a perception branch writes a suspicious position, Seek it, then return to Patrol.
Chase and hold distance
Pursue while far away, Follow at the preferred range, and Rotate Towards before the attack action.
Escape and recover
Flee or Evade until a distance conditional succeeds, wait or recover, then reevaluate the threat.
Find cover and engage
Cover selects and reaches protection. A later branch handles peeking, aiming, weapon selection, and attacking.
Put detection conditions outside a long-running movement task when they must interrupt it. A conditional abort can reevaluate perception and stop the current destination without embedding every combat rule in the movement action.