Hello everyone,
Since several days, I try to find the best approach to do that and I don't succeed to find a proper solution that works as I would like.
The idea is that I want to create a new task that act like the BehaviorTreeReference but is able to perform logic before and after its execution. Sadly, we never enter into OnStart/OnUpdate/OnEnd of a BehaviorReference, this type is only used bu the BehaviorManager to "import" the reference external behavior tree(s) into the current tree.
So I had to find another solution. What I tried to do is to create a small behavior that contain a sequence of action that will contain a behavior tree reference (BTR) between 2 actions that will be executed no matter what is the result of the BTR but still return the result of the BTR at the end (thanks to a custom "Complete Sequence" composite inspired by the classic Sequence but execute all children).
So from that I created a new task inherited from BehaviorReference and overrided the GetExternalBehaviors by that:
But it doesn't work because, the behavior tree reference is not replaced, probably because the externalBehaviorTree returned corresponds to the asset so my modification are not taken into account.
What I should do is to reproduce what is done in the BehaviorManager to duplicate the tasks from the sub BTR like in the method AddToTaskList, but it doesn't seem as simple as it sounds.
Do you know how I could achieve what I want?
I have another question that could solve my problem: Is it possible to start a behavior tree to a specific task? And can we get the next task from the current one?
Thanks a lot for your answer and have a nice day!
Since several days, I try to find the best approach to do that and I don't succeed to find a proper solution that works as I would like.
The idea is that I want to create a new task that act like the BehaviorTreeReference but is able to perform logic before and after its execution. Sadly, we never enter into OnStart/OnUpdate/OnEnd of a BehaviorReference, this type is only used bu the BehaviorManager to "import" the reference external behavior tree(s) into the current tree.
So I had to find another solution. What I tried to do is to create a small behavior that contain a sequence of action that will contain a behavior tree reference (BTR) between 2 actions that will be executed no matter what is the result of the BTR but still return the result of the BTR at the end (thanks to a custom "Complete Sequence" composite inspired by the classic Sequence but execute all children).
So from that I created a new task inherited from BehaviorReference and overrided the GetExternalBehaviors by that:
C#:
[SerializeField]
private ExternalBehavior _behavior;
public override ExternalBehavior[] GetExternalBehaviors()
{
var externalBehaviorTree = Addressables.LoadAssetAsync<ExternalBehaviorTree>("THE_TREE_ADDRESS").WaitForCompletion();
var reference = externalBehaviorTree.FindTask<BehaviorTreeReference>();
reference.variables = variables;
reference.externalBehaviors = new ExternalBehavior[] { _behavior };
return new ExternalBehavior[] { externalBehaviorTree };
}
return null;
}
But it doesn't work because, the behavior tree reference is not replaced, probably because the externalBehaviorTree returned corresponds to the asset so my modification are not taken into account.
What I should do is to reproduce what is done in the BehaviorManager to duplicate the tasks from the sub BTR like in the method AddToTaskList, but it doesn't seem as simple as it sounds.
Do you know how I could achieve what I want?
I have another question that could solve my problem: Is it possible to start a behavior tree to a specific task? And can we get the next task from the current one?
Thanks a lot for your answer and have a nice day!