🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Question about composite nodes in behavior trees

Started by
15 comments, last by IADaveMark 7 years, 5 months ago

Hey devs,

I've been learning a lot about behavior trees, but one thing is a bit confusing to me.

On one hand, the behavior tree starts from the root every tick, and re-checks all the conditions, so it can adjust to changes.

On the other hand, a sequence can be used to group perform several actions one after the other.

Now, if the sequence finished performing the first action, it will start the second action, but in the next tick, won't it try to evaluate the first action once again?

For example, assume a root node sequence, that has 3 children: Walk to door, open door, walk to bed.

So at first it will perform walk to door, and continue performing it (because the walk to door node will return "running" state) until the ai reaches the door.

Then the walk to door node will return success, because the character is already at the door, and the open door node will execute until the door is open.

Next, both the walk to door and open door nodes return success, it will move on to the walk to bed node. After a tick of walking to bed, the ai is no longer near the door, so next time the "walk to door" node is ticked, instead of returning success, it will walk the AI back towards the door and return "running", until it is back at the door.

So the way I understand, it will be stuck walking one step from the door to the bed and back, over and over.

What am I not getting here?

Advertisement

The AI shouldn't be starting at the root of the behavior tree until it's finished with its current node.

This is a pretty good article on the topic ->http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php

Happy coding!

- Psypher -A chao is one unit of chaos.
[DISCLAIMER: I haven't used BTs, and honestly I don't get what their appeal is; to me they look like an extremely limited scripting language.]

You can modify your operations slightly to avoid your problem, even if you start from the root of the tree every time: Walk to door if you are outside the room, open door if door is closed, walk to bed.

Just make sure "Walk to door if you are outside the room" returns success if you are at the door or inside the room.

It seems that you are missing something. I don't use those BTs (<- disclaimer here), but I can imagine that not every tree should check every parent up to the first node to continue a sequence of actions. In fact, I can even imagine a node making jumps all over the tree (which is strange, but it would even give more creative freedom). BTs are all about juggling with hierarchies and enter/exit leaf nodes. Maybe somebody can give you a more specific answer, are you using an existing tool? Is there anything like a "standard BT"? It's just a tree.

The AI shouldn't be starting at the root of the behavior tree until it's finished with its current node.

This is a pretty good article on the topic ->http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php

Happy coding!

Thanks, but then it wouldn't support reaction to state changes. For example, if an agent is walking somewhere, and suddenly an enemy comes near, I expect him to stop the walking and defend himself. (I read the article btw, he doesn't really explain this although he mentions it)

[DISCLAIMER: I haven't used BTs, and honestly I don't get what their appeal is; to me they look like an extremely limited scripting language.]

You can modify your operations slightly to avoid your problem, even if you start from the root of the tree every time: Walk to door if you are outside the room, open door if door is closed, walk to bed.

Just make sure "Walk to door if you are outside the room" returns success if you are at the door or inside the room.

I'm not trying to find a solution for a problem, I'm trying to understand how the "common" design for behavior tree works, and wasn't able to figure this part out from anything that I've read.


It seems that you are missing something. I don't use those BTs (<- disclaimer here), but I can imagine that not every tree should check every parent up to the first node to continue a sequence of actions. In fact, I can even imagine a node making jumps all over the tree (which is strange, but it would even give more creative freedom). BTs are all about juggling with hierarchies and enter/exit leaf nodes. Maybe somebody can give you a more specific answer, are you using an existing tool? Is there anything like a "standard BT"? It's just a tree.

As I said, I'm trying to figure out how "common" BTs should work. I'm sure I'll make my own tweaks and adjustments as necessary, but my question includes two cases which I consider to be fundamental, and from what I've read behavior trees should be able to handle such a problem easily, I'm just not clear on the details of how.

Not using any tool in particular, still investigating the subject in order to decide which tool is best for me (or writing my own of course)


When nodes are entered they are handled considering whether or not they are already running. A sequence node, for example, would not restart if it is running. I think that would do the trick.

However, the found issues are not new: When I once read about BTs they first sound to be a wonderful tool. Later on during studying existing implementations I saw 2 major drawbacks (where the 2nd one is not inherent to BTs by themselves):

a) BTs need crutches to get them work (halfway?) as expected, especially w.r.t. reaction. For example I saw "interruptable" nodes.

b) The same BT is used to do everything from decision making down to directly controlling the animation and placement of models. That's mixing of responsibilities, like once done with the nowadays overpowered scene graphs.

The conclusion I drew from this is once again: There is no tool to rule them all; instead, use the tool that is appropriate for solving the given single task. In detail:

a) The strict left-to-right execution is not a good thing for decision making. In other words, decision making should be done by using another tool (currently I favor utility based AI for this thing).

b) BTs are good for executing (more or less) canned behaviors.

These are just my 2 Cents.

a) The strict left-to-right execution is not a good thing for decision making. In other words, decision making should be done by using another tool (currently I favor utility based AI for this thing).

That raises another question: Designer tools (BTs, Planning, Utility, FSMs, etc.) VS Computer Simulations (Montecarlo, minimax, gametree searches) VS Blackboxes (the sky's the limit).

That raises another question: Designer tools (BTs, Planning, Utility, FSMs, etc.) VS Computer Simulations (Montecarlo, minimax, gametree searches) VS Blackboxes (the sky's the limit).

and your question is? ....

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

That raises another question: Designer tools (BTs, Planning, Utility, FSMs, etc.) VS Computer Simulations (Montecarlo, minimax, gametree searches) VS Blackboxes (the sky's the limit).

and your question is? ....

It seems like a strange idiomatical issue. I think the "what to use in which circumstance"/"what to use" could be assumed because of context.

b) The same BT is used to do everything from decision making down to directly controlling the animation and placement of models. That's mixing of responsibilities, like once done with the nowadays overpowered scene graphs.

AI and Animation should be segregated to their own places. The animations belong to the animators. AI belong to AI programmers until we take over animation too (but we would separate into components... I HOPE).

This topic is closed to new replies.

Advertisement