limboai/doc/source/classes/class_bttask.rst

547 lines
23 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/4.2/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>` | |
+-------------------------------------+---------------------------------------------------------+--------+
| :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>` **(** float p_delta **)** |virtual| |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`abort<class_BTTask_method_abort>` **(** **)** |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`add_child<class_BTTask_method_add_child>` **(** :ref:`BTTask<class_BTTask>` p_child **)** |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`add_child_at_index<class_BTTask_method_add_child_at_index>` **(** :ref:`BTTask<class_BTTask>` p_child, int p_idx **)** |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTTask<class_BTTask>` | :ref:`clone<class_BTTask_method_clone>` **(** **)** |const| |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Status<enum_BT_Status>` | :ref:`execute<class_BTTask_method_execute>` **(** float p_delta **)** |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BTTask<class_BTTask>` | :ref:`get_child<class_BTTask_method_get_child>` **(** int p_idx **)** |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>` **(** :ref:`BTTask<class_BTTask>` p_child **)** |const| |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`initialize<class_BTTask_method_initialize>` **(** Node p_agent, :ref:`Blackboard<class_Blackboard>` p_blackboard **)** |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| bool | :ref:`is_descendant_of<class_BTTask_method_is_descendant_of>` **(** :ref:`BTTask<class_BTTask>` p_task **)** |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>` **(** int p_initial_tabs=0 **)** |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`remove_child<class_BTTask_method_remove_child>` **(** :ref:`BTTask<class_BTTask>` p_child **)** |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`remove_child_at_index<class_BTTask_method_remove_child_at_index>` **(** int p_idx **)** |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_BTTask_property_agent:
.. rst-class:: classref-property
Node **agent**
.. rst-class:: classref-property-setget
- void **set_agent** **(** Node value **)**
- Node **get_agent** **(** **)**
The agent is a contextual object for the task's :ref:`BehaviorTree<class_BehaviorTree>` instance. Usually, agent is the owner of the :ref:`BTPlayer<class_BTPlayer>` node containing the :ref:`BehaviorTree<class_BehaviorTree>` resource.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_property_blackboard:
.. rst-class:: classref-property
:ref:`Blackboard<class_Blackboard>` **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** = ``""``
.. rst-class:: classref-property-setget
- void **set_custom_name** **(** String value **)**
- 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**
.. 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_status:
.. rst-class:: classref-property
:ref:`Status<enum_BT_Status>` **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|
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|
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|
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|
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|
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** **(** float p_delta **)** |virtual|
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** **(** **)**
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** **(** :ref:`BTTask<class_BTTask>` p_child **)**
Adds a child task. The ``p_child`` 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** **(** :ref:`BTTask<class_BTTask>` p_child, int p_idx **)**
Adds a child task. The ``p_child`` is placed at ``p_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|
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_execute:
.. rst-class:: classref-method
:ref:`Status<enum_BT_Status>` **execute** **(** float p_delta **)**
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** **(** int p_idx **)** |const|
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|
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|
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|
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|
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|
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** **(** **)**
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** **(** :ref:`BTTask<class_BTTask>` p_child **)** |const|
Returns ``true`` if ``p_child`` is a child of this task.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_initialize:
.. rst-class:: classref-method
void **initialize** **(** Node p_agent, :ref:`Blackboard<class_Blackboard>` p_blackboard **)**
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.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_is_descendant_of:
.. rst-class:: classref-method
bool **is_descendant_of** **(** :ref:`BTTask<class_BTTask>` p_task **)** |const|
Returns ``true`` if this task is a descendant of ``p_task``. In other words, this task must be a child of ``p_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|
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|
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** **(** int p_initial_tabs=0 **)**
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** **(** :ref:`BTTask<class_BTTask>` p_child **)**
Removes ``p_child`` task from children.
.. rst-class:: classref-item-separator
----
.. _class_BTTask_method_remove_child_at_index:
.. rst-class:: classref-method
void **remove_child_at_index** **(** int p_idx **)**
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.)`