A single BehaviourTreeOwner is needed regardless of the number of BehaviourTrees you are going to run with it.
Think of it like the Animation component from which you can run any number of different AnimationClips.
The BehaviourTreeOwner has a SwitchBehaviour method to switch between different BehaviourTrees at runtime.
Here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
usingUnityEngine;
usingNodeCanvas.BehaviourTrees;
publicclassExample:MonoBehaviour{
publicBehaviourTree idleBehaviour;
publicBehaviourTree fleeBehaviour;
publicBehaviourTree attackBehaviour;
privateBehaviourTreeOwner agent;
voidStart(){
agent=GetComponent<BehaviourTreeOwner>();
agent.StartBehaviour(idleBehaviour);
}
voidUpdate(){
if(Input.GetKeyDown(KeyCode.Alpha1))
agent.SwitchBehaviour(idleBehaviour);
if(Input.GetKeyDown(KeyCode.Alpha2))
agent.SwitchBehaviour(fleeBehaviour);
if(Input.GetKeyDown(KeyCode.Alpha3))
agent.SwithBehaviour(attackBehaviour);
}
}
Let me know if that’s what you are after 🙂
Join us on Discord: https://discord.gg/97q2Rjh
Login
Register
By registering on this website you agree to our Privacy Policy.