Start a branch from an event

Event Nodes are at the root of the branch and start the branch based on a condition. The most common event branch task is the Start task which automatically gets added when a task is added to the behavior tree.

A Start event node connects to the first logic task in a behavior tree branch.

Create an Event Node

Event nodes implement the EventNode base class. After implementing this base class, start the branch by calling StartBranch on the Behavior Tree component. This Event Node starts after the specified number of seconds:

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

/// <summary>
/// Starts the branch after the specified amount of time.
/// </summary>
[AllowMultipleTypes]
public class StartBranchDelay : EventNode
{
    [Tooltip("Specifies when the brnach should start.")]
    [SerializeField] protected SharedVariable<float> m_StartDelay;

    /// <summary>
    /// Initializes the node to the specified graph.
    /// </summary>
    /// <param name="graph">The graph that is initializing the task.</param>
    public override void Initialize(IGraph graph)
    {
        base.Initialize(graph);

        m_BehaviorTree.Invoke("StartBranch", m_StartDelay.Value);
    }

    /// <summary>
    /// Starts the branch.
    /// </summary>
    private void StartBranch()
    {
        m_BehaviorTree.StartBranch(this);
    }
}

Allow more than one event of the same type

Shared Variables can be used in the same way as regular behavior tree tasks. The [AllowMultipleTypes] attribute allows more than one instance of the Event Node to be added to the graph.