BehaviorTree Implementation

Hello! I am working on a BehaviorTree (https://en.wikipedia.org/wiki/Behavior_tree_(artificial_intelligence,_robotics_and_control)) implementation. I need the BehaviorTree to be serializable so that it can be saved and loaded, as such I am trying to figure out how to store the leaf nodes or Tasks. My initial thought was to have a public class in my namespace that just held a bunch of static methods. Each method corresponding to a Task. A leaf node would hold the string of the method name and invoke the method via the System.Reflection library.
I then thought about a second method of using OOP to create a base class of BehaviorTreeTask and then derive new classes for each type of Task, each one overriding a base PerformTask method. I have been spinning my wheels over which implementation to go with. I could use some help in discussing the pro/cons or even talking about another method of achieving the same result.
Behavior tree (artificial intelligence, robotics and control)
A behavior tree is a mathematical model of plan execution used in computer science, robotics, control systems and video games. They describe switchings between a finite set of tasks in a modular fashion. Their strength comes from their ability to create very complex tasks composed of simple tasks, without worrying how the simple tasks are implem...
1 Reply
Full Spectrum Wulfenite
I am relying on Unity's serialization, so basic types and things derived from the base UnityEngine.Object are all serialized. It is basically a special case Nary Tree Leaf nodes contain references to functions to perform specific tasks. Unity doesn't support the serialization of delegates so I am storing the method name as a way to obtain the method later at runtime using the System.Reflection library. Yeah, I heard it was slow, but it was the first solution I found to getting around the fact that Unity doesn't serialize delegates.

Did you find this page helpful?