Closed NemesisMate closed 8 years ago
I believe that BehaviorTree has a setObject(T) method to set the instance of your BlackBoard. You generally would do something like the following;
public void updateAI()
{
for(GameObject obj: objects)
{
tree.reset();
tree.setObject(obj);
tree.step();
}
}
This way you can use the same tree for multiple objects. Does this achieve what you want? If not could you clarify?
Not exactly. If this is done and the AI's are executed on multiple threads this would lead to unexpected bugs.
Yes, setObject
does not allow you to share trees properly and that's not its purpose.
Sharing the tree model means that there's a shadow tree for the status of each execution of the model, so memory saving is not so big as you would expect. Also, this would involve huge API-breaking changes and I'm not sure they are worthwhile.
When using the same behavior tree in many objects is a waste of resources to have the tree instantiated for all of them. Instead, it could be great to have them updated like:
public void start(T object); public Status execute(T object);
where the object is the blackboard object being updated like:
tree.step(object);
This way, the same tree could be used for as many objects as they are needed. In lot of games it is normal to use the same ai tree for lot of entities instead of having a different one for every of them.
This is an easy enhancement that I think is very useful.