Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Apache License 2.0
1.18k
stars
241
forks
source link
How to correctly pool behavior trees (and tasks)? #114
I am wondering how to correctly implement pooling with behavior trees and their tasks. I couldn't find an example anywhere.
From the documentation you should set the PooledBehaviorTreeLibrary to your manager. It also mentions that you should call disposeBehaviorTree to free the tree. Finally, it mentions something about a TASK_CLONER where I am not sure how that should be used.
What I got so far:
// create manager
private val bTreeManager: BehaviorTreeLibraryManager = BehaviorTreeLibraryManager.getInstance()
// set the pooled library
bTreeManager.library = PooledBehaviorTreeLibrary()
// create a tree instance with a custom blackboard which gets also pooled
bTreeManager.createBehaviorTree(treeFilePath, blackboardPool.obtain())
The code above is working when getting called for the first time. The second time it throws an exception because the tree's root task is null after calling following code as a cleanup to the first call:
The reason is, that the reset method of a BehaviorTree simply sets it root to null. When making now a second call to createBehaviorTree it returns the previous instance but doesn't initialize the root correctly in my opinion.
Is this intended?
Also, from my understanding any tasks created by createBehaviorTree are not managed by a Pool and I don't see any logic in BehaviorTree which would reset or free its tasks. How is it inteded to be used?
Hi,
I am wondering how to correctly implement pooling with behavior trees and their tasks. I couldn't find an example anywhere.
From the documentation you should set the
PooledBehaviorTreeLibrary
to your manager. It also mentions that you should calldisposeBehaviorTree
to free the tree. Finally, it mentions something about aTASK_CLONER
where I am not sure how that should be used.What I got so far:
The code above is working when getting called for the first time. The second time it throws an exception because the tree's root task is null after calling following code as a cleanup to the first call:
The reason is, that the
reset
method of aBehaviorTree
simply sets it root to null. When making now a second call tocreateBehaviorTree
it returns the previous instance but doesn't initialize the root correctly in my opinion.Is this intended?
Also, from my understanding any tasks created by
createBehaviorTree
are not managed by aPool
and I don't see any logic inBehaviorTree
which wouldreset
orfree
its tasks. How is it inteded to be used?