Files
flame/packages/flame_behavior_tree
Lukas Klingsbo bd4ed9e6fb chore(release): Publish Flame v1.27.0 et. al (#3546)
The following 25 packages will be updated:
```
Package Name           Current Version   Updated Version   Update Reason
jenny                  1.3.2             1.3.3             manual versioning
flame                  1.26.1            1.27.0            updated with minor changes
flame_3d               0.1.0-dev.8       0.1.0-dev.9       updated with minor changes
flame_forge2d          0.18.3            0.18.3+1          updated with patch changes
flame_isolate          0.6.2+8           0.6.2+9           updated with patch changes
flame_lint             1.2.3             1.3.0             updated with minor changes
flame_rive             1.10.11           1.10.12           updated with patch changes
flame_texturepacker    4.1.8             4.1.9             updated with patch changes
flame_tiled            2.0.3             3.0.0             updated with major changes
flame_behavior_tree    0.1.3+8           0.1.3+9           dependency was updated
flame_test             1.18.2            1.18.3            dependency was updated
flame_oxygen           0.2.3+8           0.2.3+9           dependency was updated
flame_sprite_fusion    0.1.3+8           0.1.3+9           dependency was updated
flame_fire_atlas       1.8.3             1.8.4             dependency was updated
flame_audio            2.11.2            2.11.3            dependency was updated
flame_spine            0.2.2+8           0.2.2+9           dependency was updated
flame_bloc             1.12.9            1.12.10           dependency was updated
flame_kenney_xml       0.1.1+8           0.1.1+9           dependency was updated
flame_lottie           0.4.2+8           0.4.2+9           dependency was updated
flame_markdown         0.2.4+1           0.2.4+2           dependency was updated
flame_console          0.1.2+4           0.1.2+5           dependency was updated
flame_noise            0.3.2+8           0.3.2+9           dependency was updated
flame_riverpod         5.4.11            5.4.12            dependency was updated
flame_svg              1.11.8            1.11.9            dependency was updated
flame_network_assets   0.3.3+8           0.3.3+9           dependency was updated
```
2025-04-02 08:52:25 -03:00
..

flame

This is a bridge package that integrates the behavior_tree dart package with Flame engine.


Features

This package provides a HasBehaviorTree mixin for Flame Components. It can be added to any Component and it takes care of ticking the behavior tree along with the component's update.

Getting started

Add this package to your Flutter project using:

flutter pub add flame_behavior_tree

Usage

  • Add the HasBehaviorTree mixin to the component that wants to follow a certain AI behavior.

    class MyComponent extends Position with HasBehaviorTree {
    
    }
    
  • Set-up a behavior tree and set its root as the treeRoot of the HasBehaviorTree.

class MyComponent extends PositionComponent with HasBehaviorTree {
  Future<void> onLoad() async {
    treeRoot = Selector(
      children: [
        Sequence(children: [task1, condition, task2]),
        Sequence(...),
      ]
    );
    super.onLoad();
  }
}
  • Increase the tickInterval to make the tree tick less frequently.
class MyComponent extends PositionComponent with HasBehaviorTree {
  Future<void> onLoad() async {
    treeRoot = Selector(...);
    tickInterval = 4;
    super.onLoad();
  }
}

Additional information

When working with behavior trees, keep in mind that

  • nodes of a behavior tree do not necessarily update on every frame.
  • avoid storing data in nodes as much as possible because it can go out of sync with rest of the game as nodes are not ticked on every frame.