limboai/doc/source/classes/class_bttask.rst

591 lines
28 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/BTTask.xml.
.. _class_BTTask:
BTTask
======
**Inherits:** :ref:`BT<class_BT>`
**Inherited By:** :ref:`BTAction<class_BTAction>`, :ref:`BTComment<class_BTComment>`, :ref:`BTComposite<class_BTComposite>`, :ref:`BTCondition<class_BTCondition>`, :ref:`BTDecorator<class_BTDecorator>`
Base class for all :ref:`BehaviorTree<class_BehaviorTree>` tasks.
.. rst-class:: classref-introduction-group
Description
-----------
Base class for all :ref:`BehaviorTree<class_BehaviorTree>` tasks. A task is a basic building block in a :ref:`BehaviorTree<class_BehaviorTree>` that represents a specific behavior or control flow. Tasks are used to create complex behaviors by combining and nesting them in a hierarchy.
A task can be one of the following types: action, condition, composite, or decorator. Each type of task has its own corresponding subclass: :ref:`BTAction<class_BTAction>`, :ref:`BTCondition<class_BTCondition>`, :ref:`BTDecorator<class_BTDecorator>`, :ref:`BTComposite<class_BTComposite>`.
Tasks perform their work and return their status using the :ref:`_tick<class_BTTask_private_method__tick>` method. Status values are defined in :ref:`Status<enum_BT_Status>`. Tasks can be initialized using the :ref:`_setup<class_BTTask_private_method__setup>` method. See also :ref:`_enter<class_BTTask_private_method__enter>` & :ref:`_exit<class_BTTask_private_method__exit>`.
\ **Note:** Do not extend **BTTask** directly for your own tasks. Instead, extend one of the subtypes mentioned above.
.. rst-class:: classref-reftable-group
Properties
----------
.. table::
:widths: auto
+-------------------------------------+---------------------------------------------------------+--------+
| ``Node`` | :ref:`agent<class_BTTask_property_agent>` | |
+-------------------------------------+---------------------------------------------------------+--------+
| :ref:`Blackboard<class_Blackboard>` | :ref:`blackboard<class_BTTask_property_blackboard>` | |
+-------------------------------------+---------------------------------------------------------+--------+
| ``String`` | :ref:`custom_name<class_BTTask_property_custom_name>` | ``""`` |
+-------------------------------------+---------------------------------------------------------+--------+
| ``float`` | :ref:`elapsed_time<class_BTTask_property_elapsed_time>` | |
+-------------------------------------+---------------------------------------------------------+--------+
| ``Node`` | :ref:`scene_root<class_BTTask_property_scene_root>` | |
+-------------------------------------+---------------------------------------------------------+--------+
| :ref:`Status<enum_BT_Status>` | :ref:`status<class_BTTask_property_status>` | |
+-------------------------------------+---------------------------------------------------------+--------+
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`_enter<class_BTTask_private_method__enter>`\ (\ ) |virtual| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`_exit<class_BTTask_private_method__exit>`\ (\ ) |virtual| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``String`` | :ref:`_generate_name<class_BTTask_private_method__generate_name>`\ (\ ) |virtual| |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``PackedStringArray`` | :ref:`_get_configuration_warnings<class_BTTask_private_method__get_configuration_warnings>`\ (\ ) |virtual| |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`_setup<class_BTTask_private_method__setup>`\ (\ ) |virtual| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Status<enum_BT_Status>` | :ref:`_tick<class_BTTask_private_method__tick>`\ (\ delta\: ``float``\ ) |virtual| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`abort<class_BTTask_method_abort>`\ (\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`add_child<class_BTTask_method_add_child>`\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`add_child_at_index<class_BTTask_method_add_child_at_index>`\ (\ task\: :ref:`BTTask<class_BTTask>`, idx\: ``int``\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTTask<class_BTTask>` | :ref:`clone<class_BTTask_method_clone>`\ (\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BehaviorTree<class_BehaviorTree>` | :ref:`editor_get_behavior_tree<class_BTTask_method_editor_get_behavior_tree>`\ (\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Status<enum_BT_Status>` | :ref:`execute<class_BTTask_method_execute>`\ (\ delta\: ``float``\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTTask<class_BTTask>` | :ref:`get_child<class_BTTask_method_get_child>`\ (\ idx\: ``int``\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``int`` | :ref:`get_child_count<class_BTTask_method_get_child_count>`\ (\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``int`` | :ref:`get_child_count_excluding_comments<class_BTTask_method_get_child_count_excluding_comments>`\ (\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``int`` | :ref:`get_index<class_BTTask_method_get_index>`\ (\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTTask<class_BTTask>` | :ref:`get_parent<class_BTTask_method_get_parent>`\ (\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTTask<class_BTTask>` | :ref:`get_root<class_BTTask_method_get_root>`\ (\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``String`` | :ref:`get_task_name<class_BTTask_method_get_task_name>`\ (\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``bool`` | :ref:`has_child<class_BTTask_method_has_child>`\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`initialize<class_BTTask_method_initialize>`\ (\ agent\: ``Node``, blackboard\: :ref:`Blackboard<class_Blackboard>`, scene_root\: ``Node``\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``bool`` | :ref:`is_descendant_of<class_BTTask_method_is_descendant_of>`\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``bool`` | :ref:`is_root<class_BTTask_method_is_root>`\ (\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTTask<class_BTTask>` | :ref:`next_sibling<class_BTTask_method_next_sibling>`\ (\ ) |const| |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`print_tree<class_BTTask_method_print_tree>`\ (\ initial_tabs\: ``int`` = 0\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`remove_child<class_BTTask_method_remove_child>`\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`remove_child_at_index<class_BTTask_method_remove_child_at_index>`\ (\ idx\: ``int``\ ) |
+-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_BTTask_property_agent:
.. rst-class:: classref-property
``Node`` **agent** :ref:`🔗<class_BTTask_property_agent>`
.. rst-class:: classref-property-setget
- |void| **set_agent**\ (\ value\: ``Node``\ )
- ``Node`` **get_agent**\ (\ )
The agent is the contextual object for the :ref:`BehaviorTree<class_BehaviorTree>` instance. This is usually the parent of the :ref:`BTPlayer<class_BTPlayer>` node that utilizes the :ref:`BehaviorTree<class_BehaviorTree>` resource.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_property_blackboard:
.. rst-class:: classref-property
:ref:`Blackboard<class_Blackboard>` **blackboard** :ref:`🔗<class_BTTask_property_blackboard>`
.. rst-class:: classref-property-setget
- :ref:`Blackboard<class_Blackboard>` **get_blackboard**\ (\ )
Provides access to the :ref:`Blackboard<class_Blackboard>`. Blackboard is used to share data among tasks of the associated :ref:`BehaviorTree<class_BehaviorTree>`.
See :ref:`Blackboard<class_Blackboard>` for additional info.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_property_custom_name:
.. rst-class:: classref-property
``String`` **custom_name** = ``""`` :ref:`🔗<class_BTTask_property_custom_name>`
.. rst-class:: classref-property-setget
- |void| **set_custom_name**\ (\ value\: ``String``\ )
- ``String`` **get_custom_name**\ (\ )
User-provided name for the task. If not empty, it is used by the editor to represent the task. See :ref:`get_task_name<class_BTTask_method_get_task_name>`.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_property_elapsed_time:
.. rst-class:: classref-property
``float`` **elapsed_time** :ref:`🔗<class_BTTask_property_elapsed_time>`
.. rst-class:: classref-property-setget
- ``float`` **get_elapsed_time**\ (\ )
Elapsed time since the task was "entered". See :ref:`_enter<class_BTTask_private_method__enter>`.
Returns ``0`` when task is not ``RUNNING``.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_property_scene_root:
.. rst-class:: classref-property
``Node`` **scene_root** :ref:`🔗<class_BTTask_property_scene_root>`
.. rst-class:: classref-property-setget
- ``Node`` **get_scene_root**\ (\ )
Root node of the scene the behavior tree is used in (e.g., the owner of the :ref:`BTPlayer<class_BTPlayer>` node). Can be uses to retrieve ``NodePath`` references.
\ **Example:**\
::
extends BTAction
@export var node_path: NodePath
func _setup():
var node: Node = scene_root.get_node(node_path)
.. rst-class:: classref-item-separator
----
.. _class_BTTask_property_status:
.. rst-class:: classref-property
:ref:`Status<enum_BT_Status>` **status** :ref:`🔗<class_BTTask_property_status>`
.. rst-class:: classref-property-setget
- :ref:`Status<enum_BT_Status>` **get_status**\ (\ )
Last execution :ref:`Status<enum_BT_Status>` returned by :ref:`_tick<class_BTTask_private_method__tick>`.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_BTTask_private_method__enter:
.. rst-class:: classref-method
|void| **_enter**\ (\ ) |virtual| :ref:`🔗<class_BTTask_private_method__enter>`
Called when task is "entered", i.e. when task is executed while not having a ``RUNNING`` :ref:`status<class_BTTask_property_status>`.
It is called before :ref:`_tick<class_BTTask_private_method__tick>` in the execution order. This method is used when preparation is needed before main work begins, usually when it takes more than one tick to finish the task. See also :ref:`execute<class_BTTask_method_execute>`.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_private_method__exit:
.. rst-class:: classref-method
|void| **_exit**\ (\ ) |virtual| :ref:`🔗<class_BTTask_private_method__exit>`
Called when task is "exited", i.e. after :ref:`_tick<class_BTTask_private_method__tick>` returns ``SUCCESS`` or ``FAILURE`` status. See also :ref:`execute<class_BTTask_method_execute>`.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_private_method__generate_name:
.. rst-class:: classref-method
``String`` **_generate_name**\ (\ ) |virtual| |const| :ref:`🔗<class_BTTask_private_method__generate_name>`
Called to generate a display name for the task unless :ref:`custom_name<class_BTTask_property_custom_name>` is set. See :ref:`get_task_name<class_BTTask_method_get_task_name>`.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_private_method__get_configuration_warnings:
.. rst-class:: classref-method
``PackedStringArray`` **_get_configuration_warnings**\ (\ ) |virtual| |const| :ref:`🔗<class_BTTask_private_method__get_configuration_warnings>`
The string returned by this method is shown as a warning message in the behavior tree editor. Any task script that overrides this method must include ``@tool`` annotation at the top of the file.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_private_method__setup:
.. rst-class:: classref-method
|void| **_setup**\ (\ ) |virtual| :ref:`🔗<class_BTTask_private_method__setup>`
Called to initialize a task during initialization step. It is called only once before the task's first execution tick. This method allows you to set up any necessary state or configurations for the task before it begins executing.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_private_method__tick:
.. rst-class:: classref-method
:ref:`Status<enum_BT_Status>` **_tick**\ (\ delta\: ``float``\ ) |virtual| :ref:`🔗<class_BTTask_private_method__tick>`
Called when task is "ticked", i.e. executed by :ref:`BTPlayer<class_BTPlayer>` or :ref:`BTState<class_BTState>` during an update.
Returns execution status as defined in :ref:`Status<enum_BT_Status>`.
\ **Note:** Tasks perform their main function by implementing this method.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_abort:
.. rst-class:: classref-method
|void| **abort**\ (\ ) :ref:`🔗<class_BTTask_method_abort>`
Resets the task and its children recursively. If a task is in the ``RUNNING`` state, it is exited and its status is reset to ``FRESH``.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_add_child:
.. rst-class:: classref-method
|void| **add_child**\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) :ref:`🔗<class_BTTask_method_add_child>`
Adds a child task. The ``task`` is placed at the end of the children list.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_add_child_at_index:
.. rst-class:: classref-method
|void| **add_child_at_index**\ (\ task\: :ref:`BTTask<class_BTTask>`, idx\: ``int``\ ) :ref:`🔗<class_BTTask_method_add_child_at_index>`
Adds a child task. The ``task`` is placed at ``idx`` position in the children list.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_clone:
.. rst-class:: classref-method
:ref:`BTTask<class_BTTask>` **clone**\ (\ ) |const| :ref:`🔗<class_BTTask_method_clone>`
Duplicates the task and its children, copying the exported members. Sub-resources are shared for efficiency, except for :ref:`BBParam<class_BBParam>` subtypes, which are always copied. Used by the editor to instantiate :ref:`BehaviorTree<class_BehaviorTree>` and copy-paste tasks.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_editor_get_behavior_tree:
.. rst-class:: classref-method
:ref:`BehaviorTree<class_BehaviorTree>` **editor_get_behavior_tree**\ (\ ) :ref:`🔗<class_BTTask_method_editor_get_behavior_tree>`
Returns the behavior tree that owns this task. This is only available in the editor.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_execute:
.. rst-class:: classref-method
:ref:`Status<enum_BT_Status>` **execute**\ (\ delta\: ``float``\ ) :ref:`🔗<class_BTTask_method_execute>`
Performs task's execution. The execution follows a specific sequence:
- If task's current :ref:`status<class_BTTask_property_status>` is not ``RUNNING``, the :ref:`_enter<class_BTTask_private_method__enter>` method is called first.
- Next, the :ref:`_tick<class_BTTask_private_method__tick>` method is called next to perform the task's work.
- If the :ref:`_tick<class_BTTask_private_method__tick>` method returns ``SUCCESS`` or ``FAILURE`` status, the :ref:`_exit<class_BTTask_private_method__exit>` method will be called next as part of the execution cleanup.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_get_child:
.. rst-class:: classref-method
:ref:`BTTask<class_BTTask>` **get_child**\ (\ idx\: ``int``\ ) |const| :ref:`🔗<class_BTTask_method_get_child>`
Returns a child task by specifying its index.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_get_child_count:
.. rst-class:: classref-method
``int`` **get_child_count**\ (\ ) |const| :ref:`🔗<class_BTTask_method_get_child_count>`
Returns the number of child tasks.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_get_child_count_excluding_comments:
.. rst-class:: classref-method
``int`` **get_child_count_excluding_comments**\ (\ ) |const| :ref:`🔗<class_BTTask_method_get_child_count_excluding_comments>`
Returns the number of child tasks not counting :ref:`BTComment<class_BTComment>` tasks.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_get_index:
.. rst-class:: classref-method
``int`` **get_index**\ (\ ) |const| :ref:`🔗<class_BTTask_method_get_index>`
Returns the task's position in the behavior tree branch. Returns ``-1`` if the task doesn't belong to a task tree, i.e. doesn't have a parent.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_get_parent:
.. rst-class:: classref-method
:ref:`BTTask<class_BTTask>` **get_parent**\ (\ ) |const| :ref:`🔗<class_BTTask_method_get_parent>`
Returns the task's parent.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_get_root:
.. rst-class:: classref-method
:ref:`BTTask<class_BTTask>` **get_root**\ (\ ) |const| :ref:`🔗<class_BTTask_method_get_root>`
Returns the root task of the behavior tree.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_get_task_name:
.. rst-class:: classref-method
``String`` **get_task_name**\ (\ ) :ref:`🔗<class_BTTask_method_get_task_name>`
The string returned by this method is used to represent the task in the editor.
Method :ref:`_generate_name<class_BTTask_private_method__generate_name>` is called to generate a display name for the task unless :ref:`custom_name<class_BTTask_property_custom_name>` is set.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_has_child:
.. rst-class:: classref-method
``bool`` **has_child**\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) |const| :ref:`🔗<class_BTTask_method_has_child>`
Returns ``true`` if ``task`` is a child of this task.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_initialize:
.. rst-class:: classref-method
|void| **initialize**\ (\ agent\: ``Node``, blackboard\: :ref:`Blackboard<class_Blackboard>`, scene_root\: ``Node``\ ) :ref:`🔗<class_BTTask_method_initialize>`
Initilizes the task. Assigns :ref:`agent<class_BTTask_property_agent>` and :ref:`blackboard<class_BTTask_property_blackboard>`, and calls :ref:`_setup<class_BTTask_private_method__setup>` for the task and its children.
The method is called recursively for each child task. ``scene_root`` should be the root node of the scene the behavior tree is used in (e.g., the owner of the node that contains the behavior tree).
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_is_descendant_of:
.. rst-class:: classref-method
``bool`` **is_descendant_of**\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) |const| :ref:`🔗<class_BTTask_method_is_descendant_of>`
Returns ``true`` if this task is a descendant of ``task``. In other words, this task must be a child of ``task`` or one of its children or grandchildren.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_is_root:
.. rst-class:: classref-method
``bool`` **is_root**\ (\ ) |const| :ref:`🔗<class_BTTask_method_is_root>`
Returns ``true`` if this task is the root task of its behavior tree. A behavior tree can have only one root task.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_next_sibling:
.. rst-class:: classref-method
:ref:`BTTask<class_BTTask>` **next_sibling**\ (\ ) |const| :ref:`🔗<class_BTTask_method_next_sibling>`
Returns the next task after this task in the parent's children list.
Returns ``null`` if this task has no parent or it is the last child in the parent's children list.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_print_tree:
.. rst-class:: classref-method
|void| **print_tree**\ (\ initial_tabs\: ``int`` = 0\ ) :ref:`🔗<class_BTTask_method_print_tree>`
Prints the subtree that starts with this task to the console.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_remove_child:
.. rst-class:: classref-method
|void| **remove_child**\ (\ task\: :ref:`BTTask<class_BTTask>`\ ) :ref:`🔗<class_BTTask_method_remove_child>`
Removes ``task`` from children.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_remove_child_at_index:
.. rst-class:: classref-method
|void| **remove_child_at_index**\ (\ idx\: ``int``\ ) :ref:`🔗<class_BTTask_method_remove_child_at_index>`
Removes a child task at a specified index from children.
.. |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.)`