O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Behavior Tree in Unreal engine 4

5.145 visualizações

Publicada em

Behavior Tree in Unreal Engine 4
with practice(airplane dogfighting)

Publicada em: Software
  • Seja o primeiro a comentar

Behavior Tree in Unreal engine 4

  1. 1. Behavior Tree in Unreal Engine 4 jaewan.huey.Park@gmail.com 1
  2. 2. Contents ● What and Why? ● Theory ● Practice ● Q & A ● Reference 2
  3. 3. What? 3
  4. 4. What? ● Commonly used way to direct behaviors for AI in a game. ● They can be used for any decision- making(in systems that aren’t just AI) 4
  5. 5. Why? 5
  6. 6. Why? ● Offer a good balance of supporting goal-oriented(like a*) behaviors and reactivity(like flocking). 6
  7. 7. Why? ● Offer a good balance of supporting goal-oriented(like a*) behaviors and reactivity(like flocking). 7
  8. 8. Why? ● Offer a good balance of supporting goal-oriented(like a*) behaviors and reactivity(like flocking). 8
  9. 9. Why not other solutions? 9
  10. 10. Why not use other solutions? ● There are innumerable ways to implement AI or other decision making systems. ● Not necessarily always best, but they are frequently great for games. (LOL, Uncharted 2, ...) 10
  11. 11. Why not use other solutions? State Machine? ● While state machines are reasonably intuitive for simple cases, as they become more complex they are hard to keep goal- oriented. As the number of states increases, the transitions between states become exponentially complex. Hierarchical state machines help a little, but many of the same issues remain. 11
  12. 12. 10 Reasons the Age of Finite State Machines is Over 12
  13. 13. #1 They’re Unorthodox Problem : Building a FSM is a very different process from any other form of software engineering. Sure, the concept is “designer friendly” but a surprisingly small amount of mainstream programming knowledge applies to FSMs. 13
  14. 14. #1 They’re Unorthodox Reason : FSMs require each state to be wired with an explicit transition to the next state. No programming language requires this; everything is done implicitly on the semantics of the language itself. 14
  15. 15. #2 They’re Low-Level Problem : The process of editing the logic of a FSM is very low-level and quite mechanical. You often find rebuilding the similar behaviors over and over from scratch - which takes a lot of time. 15
  16. 16. #2 They’re Low-Level Reason : All you can do is edit transitions from a state to another. There’s no way to capture higher-level patterns that reoccur frequently like sequences or conditionals. Meta- programming doesn’t exist in the world of finite state machines. 16
  17. 17. #3 Their Logic is Limited Problem : Finite state machines, as they are defined formally, are computationally limited. This means you can’t do things like counting by default. 17
  18. 18. #3 Their Logic is Limited Reason : If you consider events as symbols, you can only recognize regular grammars with a finite state automaton. Likewise, finite state machines can only act as transducers for regular language. 18
  19. 19. #4 They Require Custom Extensions Problem : Game developers often use extensions to make FSMs useful in practice. However, these hacks aren’t always easy to understand and aren’t so well documented either — unlike the academic foundations of FSMs. 19
  20. 20. #4 They Require Custom Extensions Reason : Because FSMs are theoretically limited, developers must add functionality externally to implement certain features. This means leveraging the underlying programming language to implement things like counters, timers, or any form of memory. 20
  21. 21. #5 They Are Hard to Standardize Problem : Unlike planners (HTN) or search algorithms (A*) which are implemented in relatively common ways, FSMs are very difficult to reuse across multiple games or in different parts of the engine. 21
  22. 22. #5 They Are Hard to Standardize Reason : Since FSMs aren’t turing complete, FSMs need customizing to be able to deal with the special cases of each problem. This makes them very narrowly applicable, unlike scripting languages which can easily be repackaged. 22
  23. 23. #6 They Are Not Deliberative Problem : It takes a lot of work to use a FSMs to create goal-directed behaviors. This is an issue as most purposeful AI will require dealing with long-term goals. 23
  24. 24. #6 They Are Not Deliberative Reason : FSMs operate in a reactive mode, only dealing with events and triggering transitions. They are not capable of searching ahead, so you have to edit the transitions for dealing with all the different goals manually. 24
  25. 25. #7 They Have Concurrency Nightmares Problem : FSMs just don’t like concurrency. When running multiple state machines in parallel, you either end up with deadlocks or you have edit them all in a way they are compatible. 25
  26. 26. #7 They Have Concurrency Nightmares Reason : FSMs have as much trouble dealing with external resource conflicts as they do storing information. Solutions to make state machines concurrent are typically external to the FSM itself. 26
  27. 27. #8 They Scale Poorly Problem : Finite state machines, even hierarchical ones, don’t scale very well. They often end up being edited as a large block of logic, instead of behaviors edited modularly. 27
  28. 28. #8 They Scale Poorly Reason : FSMs are not built with the many mechanisms of programming languages that help them scale up to solve large problems, in particular indirection. Also, FSMs provide no easy way to synchronize multiple modular behaviors together. 28
  29. 29. #9 They Are Labor Intensive Problem : It takes a lot of work to wire up a FSM to implement any design. Certain problems occur only because of the state machine itself! 29
  30. 30. #9 They Are Labor Intensive Reason : Dealing with all the challenges mentioned previously takes a lot of time by the designers, and this ultimately becomes a source of bugs in the behaviors. 30
  31. 31. #10 Industry is Moving On Fact : Experienced game developers are using finite state machines less and less, switching to alternatives like behavior trees. 31
  32. 32. #10 Industry is Moving On Fact : Middleware vendors for game AI are focusing their development efforts mainly on planners, and 2008 should see more of these becoming available off the shelf. 32
  33. 33. Theory 33
  34. 34. Theory 34 Sense ThinkAct
  35. 35. Theory ● Generally rely on physics engine ● Usually very expensive ● Use infrequently 35 Sense ThinkAct
  36. 36. Theory ● Decision Logic ● Generally quite simple ● Design intensive 36 Sense ThinkAct
  37. 37. Theory ● Action execution ● Often long running ● Can fail to complete 37 Sense ThinkAct
  38. 38. Behavior Tree Theory 38 Sense ThinkAct Memory
  39. 39. Unreal Engine 4 Behavior Tree 39
  40. 40. Behavior Tree Unreal Engine 4 Behavior Tree 40 Service DecoratorTask Black board
  41. 41. Unreal Engine 4 Behavior Tree 41
  42. 42. Unreal Engine 4 Behavior Tree Root Composite Service Decorator Task 42
  43. 43. Unreal Engine 4 Behavior Tree Root ● The starting execution node for the Behavior Tree. ● Every Behavior Tree has one. ● You cannot attach Decorators or Services to it. 43
  44. 44. Unreal Engine 4 Behavior Tree Composite ● These are nodes that define the root of a branch and define the base rules for how that branch is executed. ● Sequence, Selector, Simple Parallel 44
  45. 45. Unreal Engine 4 Behavior Tree Composite : Sequence 45
  46. 46. Unreal Engine 4 Behavior Tree Composite : Sequence ● Sequence Node execute their children from left to right, and will stop executing its children when one of their children Fails. If a child fails, then the Sequence fails. 46
  47. 47. Unreal Engine 4 Behavior Tree Composite : Selector 47
  48. 48. Unreal Engine 4 Behavior Tree Composite : Selector ● Selector Nodes execute their children from left to right, and will stop executing its children when one of their children Succeeds. If a Selector’s child succeed, the Selector succeeds. 48
  49. 49. Unreal Engine 4 Behavior Tree Composite : Simple Parallel 49
  50. 50. Unreal Engine 4 Behavior Tree Composite : Simple Parallel ● The Simple Parallel node allows a single main task node to be executed along side of a full tree. When the main task finishes, the setting in Finish Mode dictates the secondary tree. 50
  51. 51. Unreal Engine 4 Behavior Tree Service 51
  52. 52. Unreal Engine 4 Behavior Tree Service ● These attach to Composite nodes, and will execute at their defined frequency. These are often used to make checks and to update the Blackboard. These take the place of traditional Parallel nodes. 52
  53. 53. Unreal Engine 4 Behavior Tree Decorator 53
  54. 54. Unreal Engine 4 Behavior Tree Decorator ● Also known as conditionals. These attach to another node and make decisions on whether or not a branch in the tree, or even single node, can be executed. 54
  55. 55. Unreal Engine 4 Behavior Tree Task 55
  56. 56. Unreal Engine 4 Behavior Tree Task ● Theres are leaves of the tree, the nodes that “do” things. 56
  57. 57. Unreal Engine 4 Behavior Tree Blackboard 57
  58. 58. Unreal Engine 4 Behavior Tree Blackboard ● A blackboard is a simple place where data can be written and read for decision making purposes. ● A blackboard can be used by a single AI pawn, shared by squad. 58
  59. 59. Unreal Engine 4 Behavior Tree Blackboard : Why use? ● To make efficient event-driven behaviors ● To cache calculations ● As a scratch-pad for behaviors ● To centralize data 59
  60. 60. Unreal Engine 4 Behavior Tree Blackboard : Notice ● Don’t clutter the blackboard with lots of super-specific-case data. ● If only one node needs to know something, it can potentially fetch the value itself rather than adding every bit of tree. 60
  61. 61. Unreal Engine 4 Behavior Tree Blackboard : Notice ● If you fail to copy data to the blackboard properly, it may cause you some debugging nightmare! ● If very frequently updated and copied to the blackboard, that could be bad for performance. 61
  62. 62. Practice 62
  63. 63. 63
  64. 64. Airplane Dogfighting State ● When I track ● When I get tracking ● When I can’t find target ● When I suddenly encountered an obstacle 64
  65. 65. Airplane Dogfighting Task ● Move to target ● Evasion maneuver ● Cobra maneuver ● Emergency evasion ● Throttle control 65
  66. 66. Airplane Dogfighting Service ● Search airplane ● Emergency evasion check 66
  67. 67. Airplane Dogfighting Decorator ● Blackboard Based Condition ● Time Limit ● Emergency Evasion Check ● In View 67
  68. 68. 68
  69. 69. 69
  70. 70. Airplane Dogfighting https://github.com/HueyPark/Open-Fire 70
  71. 71. Q & A 71
  72. 72. References ● AiGameDev.com ● Behavior Trees What and Why : Unreal Engine Forum ● 10 Reasons the Age of Finite State Machines is Over ● Blackboard Documentation : Unreal Engine Forum ● zoombapup : AI Tutorial youtube playlist ● 길안에서 묻다 : 네이버 블로그 72

×