I picked up behavior designer the other day for my work project. and to see if it'll work well, I did a prototype today. everything works really well and I'm very happy with it, in the editor. but when I go to run the built version the Agent doesn't behave correctly and this error is spammed constantly in the log.
I really am not sure why this is happening, I tried a few different things to fix it, any help would be greatly appreciated.
(Filename: C:/Users/me/Desktop/Adventures in Evolution/Assets/Scripts/Creature.cs Line: 96)
NullReferenceException: Object reference not set to an instance of an object
at Creature.Consume (UnityEngine.GameObject food) [0x00023] in C:\Users\me\Desktop\Adventures in Evolution\Assets\Scripts\Creature.cs:96
at BehaviorDesigner.Runtime.Tasks.Eat.OnUpdate () [0x00001] in C:\Users\me\Desktop\Adventures in Evolution\Assets\Scripts\Tasks\Eat.cs:23
at BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) [0x00194] in <cf5dc968a0264c9f89a51575f59f24d0>:0
at BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree) [0x001c2] in <cf5dc968a0264c9f89a51575f59f24d0>:0
at BehaviorDesigner.Runtime.BehaviorManager.Tick () [0x00014] in <cf5dc968a0264c9f89a51575f59f24d0>:0
at BehaviorDesigner.Runtime.BehaviorManager.Update () [0x00000] in <cf5dc968a0264c9f89a51575f59f24d0>:0
NullReferenceException: Object reference not set to an instance of an object
at Creature.Consume (UnityEngine.GameObject food) [0x00023] in C:\Users\me\Desktop\Adventures in Evolution\Assets\Scripts\Creature.cs:96
at BehaviorDesigner.Runtime.Tasks.Eat.OnUpdate () [0x00001] in C:\Users\me\Desktop\Adventures in Evolution\Assets\Scripts\Tasks\Eat.cs:23
at BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) [0x00194] in <cf5dc968a0264c9f89a51575f59f24d0>:0
at BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree) [0x001c2] in <cf5dc968a0264c9f89a51575f59f24d0>:0
at BehaviorDesigner.Runtime.BehaviorManager.Tick () [0x00014] in <cf5dc968a0264c9f89a51575f59f24d0>:0
at BehaviorDesigner.Runtime.BehaviorManager.Update () [0x00000] in <cf5dc968a0264c9f89a51575f59f24d0>:0
C#:
public void Consume(GameObject food)
{
if (food != null)
{
var newEnergy = (SharedFloat)behaviorTree.GetVariable("Energy");
newEnergy.Value += food.GetComponent<Plant>().energy; //Line 96
WorldGenerator.worldGen.currentFood.Remove(food);
Destroy(food);
}
}
C#:
public override TaskStatus OnUpdate()
{
self.Value.Consume(target.Value); // Line 23
return TaskStatus.Success;
}
I really am not sure why this is happening, I tried a few different things to fix it, any help would be greatly appreciated.