Class BehaviorGraphAgent
Behavior agent component.
Implements
Inherited Members
Namespace: Unity.Behavior
Assembly: Unity.Behavior.dll
Syntax
[AddComponentMenu("AI/Behavior Agent")]
public class BehaviorGraphAgent : MonoBehaviour, ISerializationCallbackReceiver
Properties
BlackboardReference
The blackboard associated with the agent's graph.
Declaration
public BlackboardReference BlackboardReference { get; }
Property Value
Type | Description |
---|---|
BlackboardReference |
Graph
The graph of behaviours to be executed by the agent.
Declaration
public BehaviorGraph Graph { get; set; }
Property Value
Type | Description |
---|---|
BehaviorGraph |
Methods
Deserialize<TSerializedFormat>(TSerializedFormat, IBehaviorSerializer<TSerializedFormat>, IUnityObjectResolver<string>)
Deserializes data on to the associated BehaviorGraph.
Declaration
public void Deserialize<TSerializedFormat>(TSerializedFormat serialized, RuntimeSerializationUtility.IBehaviorSerializer<TSerializedFormat> serializer, RuntimeSerializationUtility.IUnityObjectResolver<string> resolver)
Parameters
Type | Name | Description |
---|---|---|
TSerializedFormat | serialized | Serialized data. |
RuntimeSerializationUtility.IBehaviorSerializer<TSerializedFormat> | serializer | Serializer to use. |
RuntimeSerializationUtility.IUnityObjectResolver<string> | resolver | Object resolver to use. |
Type Parameters
Name | Description |
---|---|
TSerializedFormat | Type of serialized data. |
End()
Ends the execution of the agent's behavior graph.
Declaration
public void End()
GetVariable(string, out BlackboardVariable)
Gets the variable associated with the specified name.
Declaration
public bool GetVariable(string variableName, out BlackboardVariable variable)
Parameters
Type | Name | Description |
---|---|---|
string | variableName | The name of the variable |
BlackboardVariable | variable | Contains the value associated with the specified name, if the named variable is found; otherwise, the default value is assigned. |
Returns
Type | Description |
---|---|
bool | Returns true if a variable matching the name and type is found. Returns false otherwise. |
GetVariable(SerializableGUID, out BlackboardVariable)
Gets a variable associated with the specified GUID.
Declaration
public bool GetVariable(SerializableGUID guid, out BlackboardVariable variable)
Parameters
Type | Name | Description |
---|---|---|
SerializableGUID | guid | The GUID of the variable to get |
BlackboardVariable | variable | The variable associated with the specified GUID. |
Returns
Type | Description |
---|---|
bool | Returns true if a variable with a matching GUID was found and false otherwise. |
GetVariableID(string, out SerializableGUID)
Gets the ID of the variable associated with the specified name.
Declaration
public bool GetVariableID(string variableName, out SerializableGUID id)
Parameters
Type | Name | Description |
---|---|---|
string | variableName | |
SerializableGUID | id | Contains the ID associated with the specified name, if the named variable is found; otherwise, the default value is assigned. |
Returns
Type | Description |
---|---|
bool | Returns true if a variable matching the name and type is found. Returns false otherwise. |
GetVariable<TValue>(string, out BlackboardVariable<TValue>)
Gets a variable associated with the specified name and value type. For values of type subclassed from UnityEngine.Object, use the non-generic method.
Declaration
public bool GetVariable<TValue>(string variableName, out BlackboardVariable<TValue> variable)
Parameters
Type | Name | Description |
---|---|---|
string | variableName | The name of the variable |
BlackboardVariable<TValue> | variable | The blackboard variable matching the name and value type |
Returns
Type | Description |
---|---|
bool | Returns true if a variable matching the name and type is found. Returns false otherwise. |
Type Parameters
Name | Description |
---|---|
TValue | The type of value stored by the variable |
GetVariable<TValue>(SerializableGUID, out BlackboardVariable<TValue>)
Gets a variable associated with the specified GUID and value type.
Declaration
public bool GetVariable<TValue>(SerializableGUID guid, out BlackboardVariable<TValue> variable)
Parameters
Type | Name | Description |
---|---|---|
SerializableGUID | guid | The GUID of the variable to get |
BlackboardVariable<TValue> | variable | The variable associated with the specified GUID. |
Returns
Type | Description |
---|---|
bool | Returns true if a variable with a matching GUID and type was found and false otherwise. |
Type Parameters
Name | Description |
---|---|
TValue | The value type of the variable |
Init()
Initializes a new instance of the agent's behavior graph.
Declaration
public void Init()
OnAfterDeserialize()
Declaration
public void OnAfterDeserialize()
OnBeforeSerialize()
Declaration
public void OnBeforeSerialize()
Restart()
Restarts the execution of the agent's behavior graph.
Declaration
public void Restart()
Serialize<TSerializedFormat>(IBehaviorSerializer<TSerializedFormat>, IUnityObjectResolver<string>)
Serializes the associated BehaviorGraph to data of TSerializedFormat type.
Declaration
public TSerializedFormat Serialize<TSerializedFormat>(RuntimeSerializationUtility.IBehaviorSerializer<TSerializedFormat> serializer, RuntimeSerializationUtility.IUnityObjectResolver<string> resolver)
Parameters
Type | Name | Description |
---|---|---|
RuntimeSerializationUtility.IBehaviorSerializer<TSerializedFormat> | serializer | Serializer to use. |
RuntimeSerializationUtility.IUnityObjectResolver<string> | resolver | Object resolver to use. |
Returns
Type | Description |
---|---|
TSerializedFormat | Serialized data. |
Type Parameters
Name | Description |
---|---|
TSerializedFormat | Type of serialized output. |
SetVariableValue<TValue>(string, TValue)
Sets the value of a blackboard variable matching the specified name and value type.
Declaration
public bool SetVariableValue<TValue>(string variableName, TValue value)
Parameters
Type | Name | Description |
---|---|---|
string | variableName | The name of the variable |
TValue | value | The value to assign to the variable |
Returns
Type | Description |
---|---|
bool | Returns true if a variable matching the name and type is found and set. Returns false otherwise. |
Type Parameters
Name | Description |
---|---|
TValue | The type of value stored by the variable |
SetVariableValue<TValue>(SerializableGUID, TValue)
Sets the value of the variable associated with the specified GUID.
Declaration
public bool SetVariableValue<TValue>(SerializableGUID guid, TValue value)
Parameters
Type | Name | Description |
---|---|---|
SerializableGUID | guid | The guid associated with the variable |
TValue | value | The value to assign to the variable |
Returns
Type | Description |
---|---|
bool | Returns true if the value was set successfully and false otherwise. |
Type Parameters
Name | Description |
---|---|
TValue | The value type of the variable |
Start()
Begins execution of the agent's behavior graph.
Declaration
public void Start()
Update()
Ticks the agent's behavior graph and initializes and starts the graph if necessary.
Declaration
public void Update()