The Priority Selector task orders its children by their reported priority values and evaluates the highest-priority child first. It returns success as soon as a child succeeds, continues to the next child when one fails, and returns failure if every child fails.

Use Priority Selector

Add this task from the Composites list and connect its children in the order they should be considered. The composite controls which child runs next and derives its own status from those children.

Choosing the highest-priority branch

Each child starts with a Priority Variable Evaluator. The evaluator reports the value of its assigned Shared Variable, and the Priority Selector sorts the branches from highest to lowest before starting a child. The visual position of a branch does not determine its priority.

In Play Mode, each Priority Variable Evaluator expands to display its current Value. This is the value that the Priority Selector uses to order the branches, so the runtime label is useful for confirming why one branch was selected before another.

A Priority Selector with three Priority Variable Evaluator branches, each leading to a Wait task.

In this example every branch can succeed. The selector starts the branch with the highest value and returns success when that branch’s Wait task completes successfully; the lower-priority branches are not run.

Trying the next priority after a failure

At runtime, the highest-priority branch has failed and the next-highest branch is running.

The right branch adds a Return Failure decorator around its Wait task. Its priority value is 3, so the selector starts it first. In the runtime screenshot, that branch’s Wait has succeeded, Return Failure has converted the result to failure, and the priority-2 branch is now running. A later success ends the selector immediately.

When every branch fails

All three branches and their Priority Selector show settled failure, with Start inactive.

Here every branch is wrapped by Return Failure. The runtime screenshot shows that each Wait succeeded, each decorator converted that success to failure, and the Priority Selector failed after exhausting all three branches.

Creating a custom priority evaluator

Use the built-in Priority Variable Evaluator when a float Shared Variable already represents the priority. For a calculated priority, create a task that inherits PriorityEvaluator and override GetPriorityValue(). Higher values run before lower values.

using Opsive.BehaviorDesigner.Runtime.Tasks.Decorators;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;

public class LowHealthPriorityEvaluator : PriorityEvaluator
{
    [SerializeField] private SharedVariable<float> m_Health;

    public override float GetPriorityValue()
    {
        return 100f - m_Health.Value;
    }
}

Add the custom evaluator directly above the single child task or branch that it scores, in the same position as a Priority Variable Evaluator. This example gives a higher priority to a branch when health is lower. When the Priority Selector starts, it compares the evaluator values and tries the highest-priority branch first. In Play Mode, the custom evaluator also displays its current Value on the node.