FSMs vs Behaviour trees in gameplay programming?

This topic is 1280 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi all,

so I was just recently learning about Behavior trees and found them interesting so I decided to implement them. But what I don't understand is, are BTs a replacement for FSMs? in other words, can BTs do anything FSMs do?

I have asked the question here (no answers) with a concrete example that I would love to see how to represent it in a BT.

Your help is greatly appreciated, thanks!

Share on other sites

My understanding is that BTs are a supserset of FSMs. Specifically, you could plug a FSM anywhere in a behavior tree (i.e. it's just a node in a behavior tree).

Share on other sites

Thanks for your fast reply. Yes I also read that you could plug a FSM in a BT, but I'm wondering if a FSM can be represented as a BT - More specifically, I'm wondering if the tiger statue puzzle i mentioned in my original question can be somehow a BT instead of an FSM, does it make sense? or a FSM is more suited for these types of things? (in my game I have much more similar triggers to that one I mentioned, they change state - you interact with them once, they do A, interact with them in a different way they do B, etc. so I'm wondering if using a BT is better here than an FSM...) Thank you.

Share on other sites

BTs are not really a superset of FSM, because a tree does not contain any cycles. I'm sure, that you can implement the same or atleast similar logic in both representations, but it will most likely get more complex in one of the two representations.

BTs are very flexible and easy to expand, therefor you can integrate other AI logic as special nodes, therefor adding FSMs should not be a problem. Both, BT and FSM, have kind of memory (path in BTs and state in FSM), but the follup interaction is strongly defined in FSM (state transitions) whereas a BT have the option of interrupting running actions and initiating new actions (priority nodes).

My rule of thumb is to use BTs where you have more script like behavior, eg the approximation of the AI of a human being and to use FSM where you have more rule/state based behavior.

Share on other sites

A BT can do anything a FSM can do, but you kind of have to cheat. You can set states in the world that can be queried by the BT.

The way I think of a BT, it's simply a boolean expression in a language like C, where you use operators && and || (with short-circuit evaluation) to combine calls to functions with no arguments that return bool. In that interpretation of BTs, you can write something like this:

(state_s1_is_set() && show_text() && set_state_s2())
||
(state_s2_is_set() && ...

Share on other sites

Please note... don't confuse an architecture with a reasoner. Theoretically, no matter what you use to make a decision, an agent ends up in a state. BTs simply lift the transition logic out of the states themselves and put them into a highly organized reasoner that operates independent of the state.

Share on other sites

This topic is 1280 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628740
• Total Posts
2984472

• 12
• 25
• 11
• 10
• 16