limboai/doc/source/classes/class_behaviortree.rst

201 lines
11 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/4.3/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/4.3/modules/limboai/doc_classes/BehaviorTree.xml.
.. _class_BehaviorTree:
BehaviorTree
============
**Inherits:**
Contains Behavior Tree data.
.. rst-class:: classref-introduction-group
Description
-----------
Behavior Trees are hierarchical structures used to model and control the behavior of agents in a game (e.g., characters, enemies, entities). They are designed to make it easier to create complex and highly modular behaviors for your games.
Behavior Trees are composed of tasks that represent specific actions or decision-making rules. Tasks can be broadly categorized into two main types: control tasks and leaf tasks. Control tasks determine the execution flow within the tree. They include :ref:`BTSequence<class_BTSequence>`, :ref:`BTSelector<class_BTSelector>`, and :ref:`BTInvert<class_BTInvert>`. Leaf tasks represent specific actions to perform, like moving or attacking, or conditions that need to be checked. The :ref:`BTTask<class_BTTask>` class provides the foundation for various building blocks of the Behavior Trees. BT tasks can share data with the help of :ref:`Blackboard<class_Blackboard>`. See :ref:`BTTask.blackboard<class_BTTask_property_blackboard>` and :ref:`Blackboard<class_Blackboard>`.
\ **Note:** To create your own actions, extend the :ref:`BTAction<class_BTAction>` class.
The BehaviorTree is executed from the root task and follows the rules specified by the control tasks, all the way down to the leaf tasks, which represent the actual actions that the agent should perform or conditions that should be checked. Each task returns a status when it is executed. It can be ``SUCCESS``, ``RUNNING``, or ``FAILURE``. These statuses determine how the tree progresses. They are defined in :ref:`Status<enum_BT_Status>`.
Behavior Trees handle conditional logic using condition tasks. These tasks check for specific conditions and return either ``SUCCESS`` or ``FAILURE`` based on the state of the agent or its environment (e.g., "IsLowOnHealth", "IsTargetInSight"). Conditions can be used together with :ref:`BTSequence<class_BTSequence>` and :ref:`BTSelector<class_BTSelector>` to craft your decision-making logic.
\ **Note**: To create your own conditions, extend the :ref:`BTCondition<class_BTCondition>` class.
Check out the :ref:`BTTask<class_BTTask>` class, which provides the foundation for various building blocks of Behavior Trees.
.. rst-class:: classref-reftable-group
Properties
----------
.. table::
:widths: auto
+---------------------------------------------+---------------------------------------------------------------------+--------+
| :ref:`BlackboardPlan<class_BlackboardPlan>` | :ref:`blackboard_plan<class_BehaviorTree_property_blackboard_plan>` | |
+---------------------------------------------+---------------------------------------------------------------------+--------+
| ``String`` | :ref:`description<class_BehaviorTree_property_description>` | ``""`` |
+---------------------------------------------+---------------------------------------------------------------------+--------+
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+-----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BehaviorTree<class_BehaviorTree>` | :ref:`clone<class_BehaviorTree_method_clone>`\ (\ ) |const| |
+-----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`copy_other<class_BehaviorTree_method_copy_other>`\ (\ other\: :ref:`BehaviorTree<class_BehaviorTree>`\ ) |
+-----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTTask<class_BTTask>` | :ref:`get_root_task<class_BehaviorTree_method_get_root_task>`\ (\ ) |const| |
+-----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTInstance<class_BTInstance>` | :ref:`instantiate<class_BehaviorTree_method_instantiate>`\ (\ agent\: ``Node``, blackboard\: :ref:`Blackboard<class_Blackboard>`, instance_owner\: ``Node``, custom_scene_root\: ``Node`` = null\ ) |const| |
+-----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_root_task<class_BehaviorTree_method_set_root_task>`\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) |
+-----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Signals
-------
.. _class_BehaviorTree_signal_plan_changed:
.. rst-class:: classref-signal
**plan_changed**\ (\ ) :ref:`🔗<class_BehaviorTree_signal_plan_changed>`
Emitted when the :ref:`BlackboardPlan<class_BlackboardPlan>` changes.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_BehaviorTree_property_blackboard_plan:
.. rst-class:: classref-property
:ref:`BlackboardPlan<class_BlackboardPlan>` **blackboard_plan** :ref:`🔗<class_BehaviorTree_property_blackboard_plan>`
.. rst-class:: classref-property-setget
- |void| **set_blackboard_plan**\ (\ value\: :ref:`BlackboardPlan<class_BlackboardPlan>`\ )
- :ref:`BlackboardPlan<class_BlackboardPlan>` **get_blackboard_plan**\ (\ )
Stores and manages variables that will be used in constructing new :ref:`Blackboard<class_Blackboard>` instances.
.. rst-class:: classref-item-separator
----
.. _class_BehaviorTree_property_description:
.. rst-class:: classref-property
``String`` **description** = ``""`` :ref:`🔗<class_BehaviorTree_property_description>`
.. rst-class:: classref-property-setget
- |void| **set_description**\ (\ value\: ``String``\ )
- ``String`` **get_description**\ (\ )
User-provided description of the **BehaviorTree**.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_BehaviorTree_method_clone:
.. rst-class:: classref-method
:ref:`BehaviorTree<class_BehaviorTree>` **clone**\ (\ ) |const| :ref:`🔗<class_BehaviorTree_method_clone>`
Makes a copy of the BehaviorTree resource.
.. rst-class:: classref-item-separator
----
.. _class_BehaviorTree_method_copy_other:
.. rst-class:: classref-method
|void| **copy_other**\ (\ other\: :ref:`BehaviorTree<class_BehaviorTree>`\ ) :ref:`🔗<class_BehaviorTree_method_copy_other>`
Become a copy of another behavior tree.
.. rst-class:: classref-item-separator
----
.. _class_BehaviorTree_method_get_root_task:
.. rst-class:: classref-method
:ref:`BTTask<class_BTTask>` **get_root_task**\ (\ ) |const| :ref:`🔗<class_BehaviorTree_method_get_root_task>`
Returns the root task of the BehaviorTree resource.
.. rst-class:: classref-item-separator
----
.. _class_BehaviorTree_method_instantiate:
.. rst-class:: classref-method
:ref:`BTInstance<class_BTInstance>` **instantiate**\ (\ agent\: ``Node``, blackboard\: :ref:`Blackboard<class_Blackboard>`, instance_owner\: ``Node``, custom_scene_root\: ``Node`` = null\ ) |const| :ref:`🔗<class_BehaviorTree_method_instantiate>`
Instantiates the behavior tree and returns :ref:`BTInstance<class_BTInstance>`. ``instance_owner`` should be the scene node that will own the behavior tree instance. This is typically a :ref:`BTPlayer<class_BTPlayer>`, :ref:`BTState<class_BTState>`, or a custom player node that controls the behavior tree execution. Make sure to pass a :ref:`Blackboard<class_Blackboard>` with values populated from :ref:`blackboard_plan<class_BehaviorTree_property_blackboard_plan>`. See also :ref:`BlackboardPlan.populate_blackboard<class_BlackboardPlan_method_populate_blackboard>` & :ref:`BlackboardPlan.create_blackboard<class_BlackboardPlan_method_create_blackboard>`.
If ``custom_scene_root`` is not ``null``, it will be used as the scene root for the newly instantiated behavior tree; otherwise, the scene root will be set to ``instance_owner.owner``. Scene root is essential for :ref:`BBNode<class_BBNode>` instances to work properly.
.. rst-class:: classref-item-separator
----
.. _class_BehaviorTree_method_set_root_task:
.. rst-class:: classref-method
|void| **set_root_task**\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) :ref:`🔗<class_BehaviorTree_method_set_root_task>`
Assigns a new root task to the **BehaviorTree** resource.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
.. |void| replace:: :abbr:`void (No return value.)`