Runtime Perception
Use Graph variables to move sensor results between tasks and gameplay code. Keep current perception separate from remembered state so the graph can distinguish “visible now” from “seen recently.”
Read perception from gameplay code
Bind a detecting task’s output to a GameObject Graph variable named DetectedTarget. A MonoBehaviour can read the same result without repeating the sensor query:
using Opsive.BehaviorDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
public class DetectedTargetReader : MonoBehaviour
{
[SerializeField] private BehaviorTree m_BehaviorTree;
public GameObject DetectedTarget
{
get
{
var target = m_BehaviorTree.GetVariable<GameObject>("DetectedTarget");
return target != null ? target.Value : null;
}
}
}
The variable name, capitalization, and type must match the Graph, and the task output must be bound to it. See Accessing Variables and the Behavior Designer Pro API.
Acquire, remember, and investigate
- Use Can Detect Object to acquire a currently detectable target.
- Store the detected object and last-known position in separate variables.
- When direct detection fails, let an investigation branch use the remembered position.
- Clear memory through a timeout, state transition, or project-specific confidence rule.
Reading a detection variable does not extend sensor memory automatically. The game owns how long a target remains tactically relevant.
Drive sensor inputs from code
Gameplay code can write bound variables that select a target, threshold, category, or investigation point. Prefer changing those variables over finding and mutating a running task instance.
Changing a variable does not switch branches by itself. Use conditional reevaluation when a new perception result must interrupt a Running patrol, movement, or interaction task.
Convert continuous readings into stable behavior
Use Get Sensor Amount to store the current value, then compare it with different entry and exit thresholds. For example, enter a “too hot” branch above one temperature and leave it only after the value falls clearly below that boundary.
When noise comes from a moving pivot, network correction, or fluctuating emitter, stabilize the input or require the result to remain valid briefly rather than increasing every sensor range.