Beginner stuggling with a simple tree

Verpous

New member
So I've just started using this plugin. I watched all the tutorial vids and downloaded the sample projects and then I tried to start with a simple tree which is attached to a car. The car moves forward at all times, and all this tree is supposed to do is make it so when the car is behind the player, its speed is set to be faster than the player. Once the car is no longer behind the player, its speed is set to be slower than the player. The catch is that I need the car's state (whether it's behind the player) to be constantly reevaluated. That is, once the car gets ahead of the player, if it later gets behind him again, it should speed up again. If it then gets ahead of him again, it should slow down again. The following picture is one of the many attempts I've tried at this:

1626094088396.png

What happens here is that the car starts behind the player, sets the speed to be faster than the player, and then passes him but doesn't slow down. This is despite the sequence being set to "lower priority", which I thought was supposed to make IsBehind constantly get reevaluated. I've tried many things, including setting the selector to "low priority" on top or instead of the sequence, adding an idle node at the end of each state, reading the documentation again and again, replacing the Set Field Value tasks with ones that set the speed every frame and are always running, and mimicking the following tree from the sample CTF game which I *think* does what I want (it can go to seek, then to defend, then back to seek, and so on):

1626093126815.png

The only thing that worked was putting the entire tree under a repeater. I'm new to this plugin so I can be wrong, but my understanding is that that is a very inefficient and terrible idea and it will probably cause me many troubles later when I start expanding this tree with more complex behaviors. I'm under the impression that conditional aborts are supposed to solve my problem.

I think my problem here is that I don't understand how the control flow works in Behavior Designer. All the documentation says is that it goes "top to bottom, left to right". But like, do trees run once to completion and then totally exit or do they run forever? If a condition returns success once, then changes to failure, then back to success, will it issue an abort? If it does and you go back to a branch that you were already on before, does it start from the beginning again, or where you left off?

Some help with my little beginner tree and an explanation of how Behavior Designer decides which task to run at any given time other than "top to bottom, left to right" would be appreciated. Thanks.
 
do trees run once to completion and then totally exit or do they run forever?
They run to completion unless you have "Restart when complete" enabled on the behavior manager. You can also attach a repeater at the top or a task which always returns running (such as idle or patrol) on the far right in order to keep it running. I do this for the Deathmatch AI Kit:


If a condition returns success once, then changes to failure, then back to success, will it issue an abort?
Yes, as long as the task is being reevaluated (indicated by a check or X with a circle around it on the task)

If it does and you go back to a branch that you were already on before, does it start from the beginning again, or where you left off?
From the beginning.


From the trees that you posted it does look like they are ending on the first tick so the tree will not continue to execute. Conditional aborts will not work unless the tree is active.
 
From the trees that you posted it does look like they are ending on the first tick so the tree will not continue to execute. Conditional aborts will not work unless the tree is active.
Thanks for answering. I tried converting my tree into this:

1626179087721.png

Now the tree is always active, but it still goes into the IsBehind state's idle and stays there forever. I made IsBehind print something to the console every time its OnUpdate is called and it only prints once, indicating that it isn't being reevaluated at all. How come?
 
IsBehind isn't being reevaluated when the leftmost idle is active because you are using a lower priority abort. If you want it to reevaluate you should use a both abort type.
 
Top