Behaviour Trees: The Cornerstone of Modern Game AI | AI 101

  • Published on Jan 1, 2019
  • As the new series of AI 101 continues I take a look at behaviour trees - arguably the dominant AI technique in AAA games - and tell you how they work.

    If you're interested in learning more about behaviour trees here are some links to some resources you might find useful:

    Chris Simpson: "Behaviour Trees for AI - How They Work"

    Alex Champandard: "Understanding Behaviour Trees"

    Epic Games: "Behaviour Tree (Unreal Engine 4 Documentation)"


    AI and Games is series on research and applications of Artifical Intelligence in video games. It's is supported through and wouldn't be possible wthout the wonderful people who support it on Patreon.

    Get yourself an AI and Games t-shirt over on Teespring!

    You can follow AI and Games (and me) on Facebook, Twitter and Instagram:


    Games in this episode (in order of appearance):

    Halo 2
    Far Cry Primal
    Tom Clancy's The Division
    Halo 3
    Spec Ops: The Line
    Ghost Recon: Wildlands
    Batman: Arkham Asylum
    BioShock: Infinite
    Alien: Isolation


    Soundtrack for this episode is "Twilight Metropolis A" and "This is My City" by TeknoAxe under the terms of a Creative Commons 4.0 license.

  • GamingGaming

Comments • 109

  • AI and Games
    AI and Games  3 years ago +45

    AI 101 is back for 2019 with a new episode dedicated to Behaviour Trees: one of the most commonly adopted AI technologies in modern video game development. Long-term viewers of the show will have noticed how frequently Behaviour Trees have appeared - with them cropping up in Spec Ops: The Line, Far Cry, Halo and The Division last year alone. So let's take a moment to explain how they work and why developers and designers like to use them.

  • Nathanael Gazzard
    Nathanael Gazzard 2 years ago +23

    As an aspiring game developer, there are moments when I feel particularly excited and motivated to make games. For example, every time I listen to the silent hill 2 soundtrack. In this instance, it's new insights and knowledge from you that is driving that inspiration. Thanks Tommy😊

  • fireaza
    fireaza 3 years ago +361

    "Where it decides which child to execute based on some logic in the world"
    Man, this video got *dark* .

    • IgorTheLight
      IgorTheLight 7 months ago

      "Behavior Tree" must be banned for being some kind of Cult! :-)

    • Jack
      Jack 11 months ago +1

      @Xavier Never change, you beautiful wizard

    • Ploxxon
      Ploxxon Year ago

      it got biblical.... some abrahamic shit right there

    • Xavier
      Xavier Year ago +4

      @ArcangelZero7 execute Line 66 = Jedi;
      Padme.will_to_live = null;
      If(Anakin.Crispy ==(true))

      Star wars as told by C#.... I need a life lol

    • ArcangelZero7
      ArcangelZero7 Year ago +11

      Child Nodes: "Master Root Node! Some logical conditions have been met. What are we going to do?"

  • Jan B.
    Jan B. 3 years ago +18

    We use something similar in automation technologies to program the behaviour of machines. We have a special programming language for this, called "SFC" or "Sequential Function Chart".

  • Pedro Paternostro
    Pedro Paternostro 3 years ago +2

    This is monumental work, thank you for crafting these videos with so much care. The only issue in my opinion was in the comparison between the methods, you gave behaviour trees and FSMs so much attention but almost forgot GOAP :c

    • AI and Games
      AI and Games  3 years ago +3

      Thanks for watching. GOAP will be getting it's own episode at some point, alongside other planning approaches. Plenty more to cover to keep me busy.

  • Deaden
    Deaden Year ago +2

    I already know how BTs worked, but it's great to hear some of the reasons why you might use them over the alternatives. Your explanations are also fantastic, and I wish this video had been around when I was first learning them.

  • Sky Yurt
    Sky Yurt 3 years ago +4

    I'm currently developing an Tank AI using Behaviour Trees. I have found it to be very challenging to debug my AI as I work on it. My solution was to make a simple Debug leaf node, that would output custom text whenever the behaviour tree hit that point of the tree. What other techniques do you use to debug your behaviour trees?

    • Sky Yurt
      Sky Yurt 3 years ago +1

      ​@Aadit Doshi I'm using Unity as the game engine and writing the behaviour tree from scratch using C#, so I was looking for more of an idea of a solution, which I then could implement. Displaying the current chain of nodes sounds like an good idea. I imagine I could have each node return both their status and their identifier and then make the root node output the chain of identifiers to the user.

    • Aadit Doshi
      Aadit Doshi 3 years ago +1

      It really depends on what system ur using.
      Unreals behavior trees let u put break points on the nodes.
      U could display the behavior trees current chain of running nodes above the AI.

  • johngoatie
    johngoatie 3 years ago +5

    You should look into Utility AI for a future video, I haven't seen it mentioned here but from my own work it looks to be an incredibly powerful and scalable solution.

    • John Vanderbeck
      John Vanderbeck 3 years ago

      @AI and Games I too would love to see a video on utility systems.

    • johngoatie
      johngoatie 3 years ago +1

      @AI and Games Awesome and great content, I love what you're doing.

    • AI and Games
      AI and Games  3 years ago +3

      Definetely on my to-do list (somewhere).

  • Obi Ade Kanobi Gaming
    Obi Ade Kanobi Gaming 3 years ago +1

    Love your vids dude, came for the division, stayed for the informative AI explanations 👍👍

    • AI and Games
      AI and Games  3 years ago

      Heh heh, stick about. I have some good stuff lined up between now and March.

  • Moises Pirela
    Moises Pirela Year ago

    Thank God for this channel and THIS video. Thank you mate, helped me loads. I'm working on an immersive sim and wasn't sure which technique to use.

  • FarEast Armadildo
    FarEast Armadildo 2 years ago +1

    Since using Behavior Trees depends on the type of game and its scale, what is recommended to use in a simple tactical rpg? I have made a finite state machine but I think it's lacking and the code will get really complicated if I get into this, so are behaviour trees more appropriate?

  • Leonardo Ramos
    Leonardo Ramos Year ago

    Hi! Great video! I really like your content 👍🏽.
    I got a little confused with the Reusability part, couldn't it be that Finite State Machines reuse more general states? Why is it just available for Behavior Trees?

  • todd
    todd 11 months ago +1

    I would love to see games add outside forces that are like stats but instead of changing power, it would change how they approach scenarios. Let's say one enemy has high self preservation, but low bravery. They would usually stay under cover and run away when you get close. Or what about high bravery and low self preservation. This ai would rush you at low health and usually leave cover alot. This allows for a much more random experience with ai, but still somewhat predictable due to different enemy types keeping traits close to their purpose, like defense always having higher bravery but high self preservation, meaning they will stay under cover but sometimes move away from it. Obviously there would be more factors but this is just a basic idea.

  • Aaron Carter
    Aaron Carter 3 months ago

    Great overview of behavior trees. I may be taking a job working on complex behavior trees and I'm studying everything I can about it. Appreciate the video!

  • Akemi Homura
    Akemi Homura 3 years ago +26

    AIs are quite fascinating. without them we wouldn't have video games. i'm grateful for all the talented people through the years which have been responsible for creating such wonderful things.

    • CrimsonFnb
      CrimsonFnb 17 days ago +1

      @Awawawa CM you too :)

    • Awawawa CM
      Awawawa CM 17 days ago +1

      @CrimsonFnb Have a good year

    • CrimsonFnb
      CrimsonFnb 17 days ago

      @Awawawa CM Im here to post a comment a year later... I shall await for another comment In a year

    • DasAntiNaziBroetchen
      DasAntiNaziBroetchen Year ago

      @Awawawa CM Ok. Wtf is a rardo?

    • Awawawa CM
      Awawawa CM Year ago +2

      @DasAntiNaziBroetchen Your too late, he sadly died months ago from lack of attention

  • Arcade Assassin
    Arcade Assassin 2 years ago

    behavior trees could be good for a story driven game. because assuming each character has their own tree they could be programmed to behave in a fashion that is far more consistent with their character for example in a shooter game if a character needs reviving an character who doesn't know them very well will only attempt to revive them if their near by but someone who they are close friends with would immediately drop what they are doing and go out of their way to revive them.

  • Undisclosed Music
    Undisclosed Music 2 years ago

    Do they learn on the fly? Like you would train a decision tree algorithm using some optimization technique? Also, is there a concept of a "forest" of behaviour trees, like a random forest in decision trees?

    • AI and Games
      AI and Games  2 years ago

      No they're static. Behaviour Trees are hand-made by designers to solve very specific situations. What you're suggesting - dynamic optimisation of tree-structures for decision making - is more in-line with things like Monte Carlo Tree Search (MCTS) which is only now being used more frequently in video games.

  • sam_bread
    sam_bread Year ago

    I was looking for best practices for using Behavior trees but this is fun to watch too.

  • Sergiu Ferentz
    Sergiu Ferentz 6 months ago

    I was listening to this on 0.75x for some reason. Thought Tommy had one too many pints down at the pub before filming this video.

    Great content regardless of level of sobriety !

    • AI and Games
      AI and Games  6 months ago

      Just listened to it myself and yeah... sounds like I've had a little too much to drink. 😂

  • Ryan Scott
    Ryan Scott Year ago

    Love to have a couple examples before telling us how it works.

  • MrJaaaaake
    MrJaaaaake 2 years ago

    Can you explain why the AI in most video games is so bad when we've had such big improvements in every other area?

    • Barg Bargen
      Barg Bargen Year ago

      @Tratbag D I've heard this rebuttal many times before. It's not about an AI that can beat the player, it's about a believable AI. Such as not seeing the same behaviors every time, or the AI taking additional steps to stay alive, or use more tactics than rushing the enemy. There is so much potential, and no one is tapping into it.

    • Tratbag D
      Tratbag D Year ago

      At the moment, and especially for some games, it's not that difficult to implement an AI in a game that can't be beaten. However, this is a turnoff for gamers because it's not fun when you know you are going to lose everytime you play. Games are entertainment and people play them for fun.

  • Van Ivanov
    Van Ivanov 3 years ago

    I wish the graphs were more details, giving examples of the topics discussed.

  • Tabea Tamm
    Tabea Tamm Year ago +1

    I think your videos can be very informative, but I usually find myself not knowing what the hell you were talking about in the end because it is way too technical for me.

  • Daniel Karbach
    Daniel Karbach Year ago +10

    "Decide which child to execute" hmmm, trolley problem in AI?

  • Jamess ジ
    Jamess ジ 11 months ago +10

    All my brain picks up in this is “child execution” and “ child manipulation “

  • Bezerker21
    Bezerker21 Year ago

    So question, im trying to make a game, and im not new to coding but very very new to game design. Im trying to make an old school final fantasy style rpg, with 2d sprites and turn based combat. My question is, are behavior trees a good idea for the enemies in combat? I was gonna use a sort of rng to have enemies decide what attack to use, but if I wanted to give it more intelligence and have it react to the player's strategies and status effects on both sides, would it be a good idea to use a behavior tree or a different method instead?

  • pere moya serra
    pere moya serra 2 years ago

    One thing I didn't get the 4:11 caching thing . I am making a game where the enemy_director tells each instance of a particular enemy what to do each frame using a (small)behaviour tree. The thing is taht I am traversing the tree and making the pertinent checks every frame; how can I store data about the state in wich it was and still check wether it shoud choose an other path?

  • bleh blehson
    bleh blehson 3 years ago +15

    Oh good thanks! I am glad you made this video.

  • john snow
    john snow Year ago

    Man you guys are intelligent hope to be able to do this one day

  • Restart
    Restart 6 months ago

    Great video none of this works in unreal all of it is bought from the asset store ue4 is not setup to do very advance AI

  • Oldsiren
    Oldsiren 3 years ago +1

    Will you be at some point going over Utility AI(even though its really IA ;) )?

    • AI and Games
      AI and Games  3 years ago

      Yeah I think Utility is worth covering. It's not a particularly well understood subject.

  • Death Strike Gaming
    Death Strike Gaming 2 years ago

    You basically explained a simple AI neuron

  • Joanna Parungao
    Joanna Parungao Year ago +1

    best thing ever. thank you for this!

  • James Ostrander
    James Ostrander 4 months ago

    Any books or websites to check on how to construct a behavior tree using C#? I would love to do this for a game in Unity Engine.

  • Blorp
    Blorp 2 years ago

    Super helpful video. Thanks!!

  • Ye4rZero
    Ye4rZero 3 years ago +1

    What an awesome unique channel! +1 sub

  • numinousMonky
    numinousMonky 2 years ago +1

    He held my lecture today!

  • Sebastian Alvarez
    Sebastian Alvarez 3 years ago +1

    Not sure if it was explained but I wpuld like to kown how the AI aims to your bodypart in fps games.

    • Burhan Sancaklı
      Burhan Sancaklı Year ago

      @Sebastian Alvarez because developers want you to feel powerful, it would be boring if ai just headshot you all the day and didnt miss any of its shots

    • laseede17
      laseede17 3 years ago +2

      @Sebastian Alvarez maybe with probabilities. But good idea for a vid.

    • Sebastian Alvarez
      Sebastian Alvarez 3 years ago +1

      @Aadit Doshi he did say to comment what we would like to see in future videos. I was also wondering how the AI doesnt always go for a headshot, moving targets, how to miss, etc.

    • Aadit Doshi
      Aadit Doshi 3 years ago +1

      Umm, it has nothing to do with this video. BUT.
      You get the player mesh, get the bone of the body part you want it to SHOOT at. Get the bones position. Tell it to shoot at that position.

  • phobos2077
    phobos2077 2 years ago +1

    Nothing stopping you from using the same event-driven optimizations in state-driven system. So the whole "performance" argument is kinda wrong. The same about reusability - nothing stops from writing states and transitions in an isolated, reusable fashion. You are comparing the bare bones state machines with real optimized implementations of BT's which is just incorrect.

    • Rudolf Wickond
      Rudolf Wickond Year ago

      The reason to use them is more that non programmers can read and understand them more easily. How performant they run is always down to their implementation anyways.

  • Heitor Pedroso
    Heitor Pedroso 3 years ago +1

    You have way too low sub count. This channel needs more spotlight. Great job mate.

  • wolf rayet
    wolf rayet 3 years ago +4

    When this popped up on my feed and I saw the date. I was so happy for a new video!

    • AI and Games
      AI and Games  3 years ago

      Still gotta case study lined up for this month too. Currently there's at least two videos a month until April. Provided I get them finished! 😅

    IW_LEGENDARY_SAYaiN22 3 years ago +72

    @ 1:19 the background marine says “They killed the Chief! You bastards!”

    That’s gotta be a south park reference.

    • M
      M Year ago +12

      @pierre117 You realize people were asking? Or do you not understand how captain obvious works? Reminds me of how people use r/woosh, it isn't that complicated

    • pierre117
      pierre117 Year ago +1

      @M Thanks cpt obvious

    • M
      M Year ago +4

      For people wondering, this is in reference to the iconic ''They killed Kenny'' line

    • Sky Acania Dev
      Sky Acania Dev 2 years ago

      You mean chef?

    • Mf Tripz
      Mf Tripz 2 years ago

      ? I don't remember no line said like that from sp

  • CommieG
    CommieG 2 years ago +3

    Damn, this channel is so underrated

  • Xav Dest
    Xav Dest 3 years ago

    The root can also be a selector. It doesn't have to be Root->selector, it can be root(selector) where the root is an event in the world that has a selector inside it.

  • Vaaz Rodríguez
    Vaaz Rodríguez 3 years ago

    Not again dyslexia... I was expecting to see different trees in games...

  • Eduardo
    Eduardo 7 months ago

    We need Doctor Sung, to give us positronic brain ^^

  • Glockmog2007
    Glockmog2007 20 days ago

    In my opinion state machines are better if you want to make very in depth ai. Yes behavior trees are easier to follow and therefore simpler to debug but you cant have too many different branches before they become a complete mess if you want to add more functionality. State machines are much more scalable. And since I actually write the code rather than using visual tools theyre just as readable to me.

  • Thomas Nied
    Thomas Nied 2 years ago

    How's about the Director from the Left 4 Dead series?

  • pricelessair
    pricelessair Year ago

    Happy find!👍

  • dmdz
    dmdz 2 years ago

    Fix your playlist order before it's too late!

  • Darth Danksaber
    Darth Danksaber 3 years ago +2

    Is this a re-upload...?

  • Sanchay Joshi
    Sanchay Joshi Year ago +1

    Summarising: Selector is a question (is this condition satisfied) and sequence is a procedure( do this and that)....... AI is basically questions and procedures.

  • Base Reality
    Base Reality Year ago

    Excellent Video

  • vincentpol
    vincentpol 3 years ago +1

    I may be focusing on the wrong issue here, but wouldn't it make more sense to say Behavior Trees are the 'powerhouse' of modern game AI. Clearly the 'cornerstone' of modern game AI is the state machine, which is used to build said powerhouse.

    I can already sense I'm giving this way more thought that I should. Great video as always.

  • Clovis LFRC
    Clovis LFRC Year ago


  • Piotr R
    Piotr R 3 years ago +2

    pointless, it is still a FSM just not all transitions are explicitly coded. Easier to debug? surely.

  • Patttiat 2000
    Patttiat 2000 Year ago

    4 min only explaining how to read this tree???!!!
    do you think that i´m stupid???

  • Old Snake
    Old Snake 11 months ago

    The fact you put dumb Arkham henchman in the video 😂

  • pianoXsmile - Halo Clips


  • elektron117
    elektron117 3 years ago


  • Riley
    Riley 3 years ago


    PSHYCO 3 years ago


  • Aaron Van Meter
    Aaron Van Meter 3 years ago

    behavior trees are a narrativist abomination lmfao

  • Aaron Van Meter
    Aaron Van Meter 2 years ago

    this is a terrible idea!! why would this be the most popular method right now??