I am trying to set some variables such as sharedSpeed for an external tree that is on an prefab.
When my prefab is created (at runtime), I have this which pulls the stats from my scriptable, sets the values and then maps them to the behavior tree component on this entity:
I have a BehaviorTreeExtensions.cs file that contains the SetPropertyMapping method:
The sharedSpeed variable is being updated in the behavior tree inspector but an error is being thrown:
ArgumentException: Type cannot be null.
BehaviorDesigner.Runtime.SharedVariable
Now, it looks to be because the variable is on the external tree and the variable it is trying to map to must be on the behavior tree component itself. How do I map to the external tree variable that is on my objects behavior tree component?
When my prefab is created (at runtime), I have this which pulls the stats from my scriptable, sets the values and then maps them to the behavior tree component on this entity:
Code:
public ScriptableUnitBase UnitData; // Reference to ScriptableUnitBase
private void Awake()
{
// Initialise unit stats
SetStats(UnitData.BaseStats);
// set stat values here
UnitData.UpdateBaseIntStat(Stats.StatType.Health, 150);
UnitData.UpdateBaseFloatStat(Stats.StatType.Speed, 100);
//Debug.Log(Stats.health);
var gameObject = this.gameObject;
var behaviorTree = GetComponent<BehaviorTree>();
behaviorTree.SetPropertyMapping("sharedSpeed", UnitData.BaseStats.speed.ToString(), gameObject);
behaviorTree.EnableBehavior();
}
I have a BehaviorTreeExtensions.cs file that contains the SetPropertyMapping method:
Code:
using UnityEngine;
using BehaviorDesigner.Runtime;
public static class BehaviorTreeExtensions
{
public static void SetPropertyMapping(this BehaviorTree tree, string treeVariableName, string mapping, GameObject owner)
{
var sharedVariable = tree.GetVariable(treeVariableName);
sharedVariable.PropertyMapping = mapping;
sharedVariable.PropertyMappingOwner = owner;
sharedVariable.InitializePropertyMapping(tree.GetBehaviorSource());
}
}
The sharedSpeed variable is being updated in the behavior tree inspector but an error is being thrown:
ArgumentException: Type cannot be null.
BehaviorDesigner.Runtime.SharedVariable
Now, it looks to be because the variable is on the external tree and the variable it is trying to map to must be on the behavior tree component itself. How do I map to the external tree variable that is on my objects behavior tree component?
Last edited: