Aparently I completely missed Clem’s last post. I am really sorry about that!
Tick() should always be called after a graph is Started (regardless of whether or not the behaviour is repeated). StartBehaviour must be called since it is responsible for setting references as well as calling various callbacks in nodes like OnGraphStarted (which are essential for correct initialization).
If we want to manually Update a graph (or Tick a tree in case of BT), we need to call StartBehaviour with the autoUpdate argument set to false owner.StartBehaviour(false, null);.
In cases where we manually Tick the tree, leaving the “repeat” option enabled is desirable, since the point of the “repeat” option is to automatically Stop() the tree (disable it). Thus if we do not want any automation like that, we need to keep the “repeat” option enabled.
As such, to manually Tick() a tree correctly, all we have to do is leave the “repeat” option enabled and do something like this in code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
usingUnityEngine;
usingNodeCanvas.BehaviourTrees;
publicclassNewBehaviourScript:MonoBehaviour
{
publicBehaviourTreeOwner owner;
voidStart(){
//we need to start the behaviour with autoUpdate set to false
owner.StartBehaviour(false,null);
//leaving repeat to true will keep the tree alive and enabled
owner.repeat=true;
}
voidUpdate(){
//updates the tree once per frame. Tick also returns the root status.
owner.Tick();
}
}
I have just updated the documentation (which was missing the part that StartBehaviour needs to be called). I have also now added a warning if UpdateGraph is called without first having the graph started to avoid any confusion.
Please let me know if this works for you.
Join us on Discord: https://discord.gg/97q2Rjh
Login
Register
By registering on this website you agree to our Privacy Policy.