Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to correctly pool behavior trees (and tasks)? #114

Open
Quillraven opened this issue Apr 25, 2021 · 0 comments
Open

How to correctly pool behavior trees (and tasks)? #114

Quillraven opened this issue Apr 25, 2021 · 0 comments

Comments

@Quillraven
Copy link

Quillraven commented Apr 25, 2021

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 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:

blackboardPool.free(behaviorTree.`object`)
bTreeManager.disposeBehaviorTree(treeFilePath, behaviorTree)

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant