### Patrol Node Setup Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/event-nodes-example.md Use the Patrol node to define an agent's movement along a series of waypoints. This node is typically connected to a 'Run In Parallel' node to manage concurrent behaviors. ```csharp Add a Patrol node, for example, to move along waypoints. Join the Patrol node to the Run In Parallel node. ``` -------------------------------- ### Corrected YAML type reference Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/serialize-ref-troubleshoot.md Example of how to correct a YAML type entry for a Behavior asset. Replace the invalid 'type:' entry with the correct class name, namespace, and assembly. ```yaml # Before (invalid reference) type: {class: 'TypedVariableModel`1[[MyEventChannel, Assembly-CSharp]]', ns: Unity.Behavior, asm: Unity.Behavior} # After (corrected reference) type: {class: 'TypedVariableModel`1[[MigratedEventChannel, Assembly-CSharp]]', ns: Unity.Behavior, asm: Unity.Behavior} ``` -------------------------------- ### Accessing Blackboard Variables in C# Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Authoring/GenerativeAI/Assets/Prompts/ActionPrompt.txt Demonstrates how to declare and access values from Blackboard variables within a Unity Behavior Tree node. Use the .Value property to get or set the variable's data. ```csharp // Declare a blackboard variable BlackboardVariable MyVariable; // Access its value int currentValue = MyVariable.Value; ``` -------------------------------- ### Check Collisions in Radius Node Setup Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/event-nodes-example.md Utilize the 'Check Collisions in Radius' node to detect any GameObjects within a specified radius around the agent. This is often used in conjunction with a 'Conditional Guard' to filter detected objects. ```csharp Add a Check Collisions in Radius node: Join the Check Collisions in Radius node to the On Start node. Assign Self for the Agent field and Sight for the Radius field. ``` -------------------------------- ### C# Behavior Tree Node Template Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Authoring/GenerativeAI/Assets/Prompts/ActionPrompt.txt This is the base template for creating a custom behavior tree node. You need to fill in the OnStart, OnUpdate, and OnEnd methods to define the node's logic. Use BlackboardVariable for accessing and modifying node data. ```csharp using System; using Unity.Behavior; public class CustomNode : Action { // Declare blackboard variables here // Example: BlackboardVariable MyVariable; protected override void OnStart() { // Code to run when the node starts } protected override void OnUpdate() { // Code to run when the node updates // Return Status.Running, Status.Success, or Status.Failure } protected override void OnEnd() { // Code to run when the node ends } } ``` -------------------------------- ### Mark Private Members for Serialization Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/serialization.md Use the `[CreateProperty]` attribute for private non-BlackboardVariable members that need to be serialized. This ensures their state is saved and restored. ```csharp [CreateProperty] private float m_Progress = 0.0f; ``` -------------------------------- ### Advanced Serialization for Node References Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/serialization.md For serializing non-BlackboardVariable fields like node references to the graph asset at runtime, use `[CreateProperty]` and `[DontGenerateProperty]` to avoid runtime reflection performance issues. ```csharp [CreateProperty] public Node Child => m_Child; [SerializeReference, DontCreateProperty] private Node m_Child; ``` -------------------------------- ### Create a new custom condition script Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/conditional-node.md Generates a C# script to define a new custom condition for Conditional Branch nodes. Ensure the script includes necessary Unity Behavior framework elements. ```csharp using UnityEngine; using Unity.Behavior; public class NewCondition : Condition { public override bool Evaluate() { // Implement your condition logic here return true; } } ``` -------------------------------- ### Enable Serialization for Custom Nodes Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/serialization.md Add these attributes to your custom node classes to make them serializable and generate property bags. ```csharp [Serializable, Unity.Properties.GeneratePropertyBag] ``` -------------------------------- ### Wait for Enemy Spotted Event Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/event-nodes-example.md Configure a 'Wait for Event Message' node to listen for a specific event, such as 'Enemy Detected'. This node is crucial for enabling reactive behaviors in the agent. ```csharp Add a Wait for Event Message node. Join the Wait for Event Message node to the Run In Parallel node. Select the Event Channel link icon in the Wait for Event Message node to link it to the Enemy Detected event channel. Add a Log Message node and group it with the Wait For Event Message node. Set the message to "I've spotted the enemy! Alert!" in the Inspector. ``` -------------------------------- ### Conditional Guard for Enemy Detection Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/event-nodes-example.md Implement a 'Conditional Guard' node with 'Variable Comparison' to ensure that only specific types of objects (e.g., enemies) trigger subsequent actions. This node links the detected object to a predefined 'Enemy' variable. ```csharp Group the Conditional Guard node with the Check Collisions in Radius node. In the Inspector, select Assign Condition > Variable Conditions > Variable Comparision. Select the link icon in the Variable field to link it with the FoundObject variable. Select the link icon in the Comparison Value field to link it with the Enemy variable. ``` -------------------------------- ### Bind to BehaviorGraphAgent Instance in C# Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/bind-c.md Subscribe to BlackboardVariable changes or event channels directly from a BehaviorGraphAgent instance. Ensure the BehaviorGraphAgent is assigned in the inspector. ```csharp using UnityEngine; using Unity.Behavior; public class BehaviorGraphInteraction : MonoBehaviour { [SerializeField] private BehaviorGraphAgent m_Agent; // Agent state has changed to [value] (where value is of type StateExample) private BlackboardVariable m_stateEventChannelBBV; private BlackboardVariable m_stateBBV; private void OnEnable() { if (m_Agent.GetVariable("StateEventChannel", out m_stateEventChannelBBV)) m_stateEventChannelBBV.Value.Event += OnStateEvent; if (m_Agent.GetVariable("StateToReact", out m_stateBBV)) m_stateBBV.OnValueChanged += OnStateValueChanged; } private void OnDisable() { if (m_stateEventChannelBBV != null) m_stateEventChannelBBV.Value.Event -= OnStateEvent; if (m_stateBBV != null) m_stateBBV.OnValueChanged -= OnStateValueChanged; } private void Update() { // your custom logic // Send event to the event channel of the referenced agent. // Only this instance of agent will receive it (except if the BlackboardVariable is 'Shared'). m_stateEventChannelBBV.Value.SendEventMessage(StateExample.Alert); } private void OnStateEvent(StateExample value) { // React to event } private void OnStateValueChanged() { // React to state change } } ``` -------------------------------- ### Generate Property Bags for Assembly Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/serialization.md Add this attribute to your AssemblyInfo.cs file to generate property bags for all serializable types within the assembly. Consider using separate assembly definitions for custom nodes to improve compilation efficiency. ```csharp [assembly:GeneratePropertyBagsForAssembly] ``` -------------------------------- ### Bind to Event Channel Asset in C# Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/bind-c.md Listen to or send messages globally using an Event Channel asset. Assign the Event Channel asset in the inspector. This is useful for cross-system communication. ```csharp using UnityEngine; using Unity.Behavior; public class EventChannelInteraction : MonoBehaviour { [SerializeField] private StateEventChannel m_EventChannel; private void OnEnable() { m_EventChannel.Event += OnStateEvent; } private void OnDisable() { m_EventChannel.Event -= OnStateEvent; } private void Update() { // your custom logic // Send event to the event channel instance. // All graphs and C# systems on that same event channel instance will receive it. m_EventChannel.SendEventMessage(StateExample.Alert); } private void OnStateEvent(StateExample value) { // React to event } } ``` -------------------------------- ### Send Event Message for Enemy Detection Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Documentation~/event-nodes-example.md Use the 'Send Event Message' node to broadcast an event, such as 'Enemy Detected', when an enemy is identified. This node facilitates communication between different parts of the behavior tree or other game systems. ```csharp Group the Send Event Message node with the previous nodes. On the Send Event Message node, select the link icon in the Event Channel field to link it with the Enemy Detected event channel variable. Select the link icon in the Agent field to link it with a variable on the Blackboard and select Self. Select the link icon in the Enemy field to link it with the Enemy variable. ``` -------------------------------- ### Unity Behavior Tree Status Enum Source: https://github.com/needle-mirror/com.unity.behavior/blob/master/Authoring/GenerativeAI/Assets/Prompts/ActionPrompt.txt Reference for the Status enum used to report the state of a behavior tree node. This enum is crucial for controlling the flow of the behavior tree. ```csharp internal enum Status { Uninitialized, Running, Success, Failure, Waiting } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.