BehaviorTree/BehaviorTree.CPP

[4.x] How to Pause and resume the tree?

HBing110 opened this issue · 4 comments

What is the best way to implement pause and resume the tree in the 4.x version of the program? Can you provide an example,thx

You are planning to pause/resume the tree from a higher level application, right? Why not creating a State Machine in higher level so you just tick the tree on Running state, while in Pause you will wait the user to click/request Start/Continue again.

You are planning to pause/resume the tree from a higher level application, right? Why not creating a State Machine in higher level so you just tick the tree on Running state, while in Pause you will wait the user to click/request Start/Continue again.

Sorry, I still didn't understand what you meant. Can you give a simple example?Thank you very much

so, the tree has the following method called tickOnce, let's the user to tick the tree only once when they want to. So, if you create an object that has the tree as a member variable and it has a run or update method so it can run synchronously (every X ms), you can double check within that run method whether anyone requested any Pause or Resume and tick the tree the accordingly. Roughly,

Update() {

if(userRequestedPause()){
    pause();
} else{
    tree.tickOnce();
}

}

so, the tree has the following method called tickOnce, let's the user to tick the tree only once when they want to. So, if you create an object that has the tree as a member variable and it has a run or update method so it can run synchronously (every X ms), you can double check within that run method whether anyone requested any Pause or Resume and tick the tree the accordingly. Roughly,

Update() {

if(userRequestedPause()){
    pause();
} else{
    tree.tickOnce();
}

}

Thank you for your patient answer. I understand now