I’m writing an AI toolset for Unity Asset Store and want to support NC.
I would like to be able to ‘start’ (by enabling it?) a BTO and let the user stop it with an action inside NC and notify my script.
This action should be written by me and not some user assembled complicated flow of actions. Just some kind of ‘Reset BTO, disable it and notify my script that it is done.
Use case is to branch to a BTO to calculate a decision, store the outcome (this part is already done), reset and disable BTO and notify my script that it has finished the calculation.
The enabling part is simple, but i don’t see the way how to code the DisableResetNotify Action.
Also I’m not that sure if it makes sense at all to use NC this way…
Considering I understood correctly, this is actually pretty easy to do 🙂
The BehaviourTreeOwner (or any GraphOwner for that matter), has a “StartBehaviour” overload that takes a System.Action<bool> argument as a callback. As such, when (for any reason, even by the included ControlGraphOwner action task) the behaviour is stopped, the callback will be called. For example:
1
2
3
4
5
6
7
8
9
10
voidExample(){
varowner=GetComponent<BehaviourTreeOwner>();
owner.StartBehaviour(OnStop);
}
voidOnStop(boolsuccess){
Debug.Log("The behaviour has stopped");
}
Thus the “trick” here, is simply to provide a callback when the behaviour starts. Ending the behaviour can be done in any way and the callback will still be called.