: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` **Inherited By:** :ref:`BTAction`, :ref:`BTComment`, :ref:`BTComposite`, :ref:`BTCondition`, :ref:`BTDecorator` Base class for all :ref:`BehaviorTree` tasks. .. rst-class:: classref-introduction-group Description ----------- Base class for all :ref:`BehaviorTree` tasks. A task is a basic building block in a :ref:`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`, :ref:`BTCondition`, :ref:`BTDecorator`, :ref:`BTComposite`. Tasks perform their work and return their status using the :ref:`_tick` method. Status values are defined in :ref:`Status`. Tasks can be initialized using the :ref:`_setup` method. See also :ref:`_enter` & :ref:`_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` | | +-------------------------------------+---------------------------------------------------------+--------+ | :ref:`Blackboard` | :ref:`blackboard` | | +-------------------------------------+---------------------------------------------------------+--------+ | String | :ref:`custom_name` | ``""`` | +-------------------------------------+---------------------------------------------------------+--------+ | float | :ref:`elapsed_time` | | +-------------------------------------+---------------------------------------------------------+--------+ | Node | :ref:`scene_root` | | +-------------------------------------+---------------------------------------------------------+--------+ | :ref:`Status` | :ref:`status` | | +-------------------------------------+---------------------------------------------------------+--------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_enter` **(** **)** |virtual| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_exit` **(** **)** |virtual| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | String | :ref:`_generate_name` **(** **)** |virtual| |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | PackedStringArray | :ref:`_get_configuration_warnings` **(** **)** |virtual| |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_setup` **(** **)** |virtual| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Status` | :ref:`_tick` **(** float delta **)** |virtual| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`abort` **(** **)** | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_child` **(** :ref:`BTTask` task **)** | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_child_at_index` **(** :ref:`BTTask` task, int idx **)** | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`BTTask` | :ref:`clone` **(** **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Status` | :ref:`execute` **(** float delta **)** | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`BTTask` | :ref:`get_child` **(** int idx **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | int | :ref:`get_child_count` **(** **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | int | :ref:`get_child_count_excluding_comments` **(** **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | int | :ref:`get_index` **(** **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`BTTask` | :ref:`get_parent` **(** **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`BTTask` | :ref:`get_root` **(** **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | String | :ref:`get_task_name` **(** **)** | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`has_child` **(** :ref:`BTTask` task **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`initialize` **(** Node agent, :ref:`Blackboard` blackboard, Node scene_root **)** | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`is_descendant_of` **(** :ref:`BTTask` task **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`is_root` **(** **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`BTTask` | :ref:`next_sibling` **(** **)** |const| | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`print_tree` **(** int initial_tabs=0 **)** | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_child` **(** :ref:`BTTask` task **)** | +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_child_at_index` **(** int 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 the contextual object for the :ref:`BehaviorTree` instance. This is usually the parent of the :ref:`BTPlayer` node that utilizes the :ref:`BehaviorTree` resource. .. rst-class:: classref-item-separator ---- .. _class_BTTask_property_blackboard: .. rst-class:: classref-property :ref:`Blackboard` **blackboard** .. rst-class:: classref-property-setget - :ref:`Blackboard` **get_blackboard** **(** **)** Provides access to the :ref:`Blackboard`. Blackboard is used to share data among tasks of the associated :ref:`BehaviorTree`. See :ref:`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`. .. 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`. Returns ``0`` when task is not ``RUNNING``. .. rst-class:: classref-item-separator ---- .. _class_BTTask_property_scene_root: .. rst-class:: classref-property Node **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` 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` **status** .. rst-class:: classref-property-setget - :ref:`Status` **get_status** **(** **)** Last execution :ref:`Status` returned by :ref:`_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`. It is called before :ref:`_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`. .. 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` returns ``SUCCESS`` or ``FAILURE`` status. See also :ref:`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` is set. See :ref:`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` **_tick** **(** float delta **)** |virtual| Called when task is "ticked", i.e. executed by :ref:`BTPlayer` or :ref:`BTState` during an update. Returns execution status as defined in :ref:`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` task **)** 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** **(** :ref:`BTTask` task, int idx **)** 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` **clone** **(** **)** |const| Duplicates the task and its children, copying the exported members. Sub-resources are shared for efficiency, except for :ref:`BBParam` subtypes, which are always copied. Used by the editor to instantiate :ref:`BehaviorTree` and copy-paste tasks. .. rst-class:: classref-item-separator ---- .. _class_BTTask_method_execute: .. rst-class:: classref-method :ref:`Status` **execute** **(** float delta **)** Performs task's execution. The execution follows a specific sequence: - If task's current :ref:`status` is not ``RUNNING``, the :ref:`_enter` method is called first. - Next, the :ref:`_tick` method is called next to perform the task's work. - If the :ref:`_tick` method returns ``SUCCESS`` or ``FAILURE`` status, the :ref:`_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` **get_child** **(** int 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` 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` **get_parent** **(** **)** |const| Returns the task's parent. .. rst-class:: classref-item-separator ---- .. _class_BTTask_method_get_root: .. rst-class:: classref-method :ref:`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` is called to generate a display name for the task unless :ref:`custom_name` is set. .. rst-class:: classref-item-separator ---- .. _class_BTTask_method_has_child: .. rst-class:: classref-method bool **has_child** **(** :ref:`BTTask` task **)** |const| 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** **(** Node agent, :ref:`Blackboard` blackboard, Node scene_root **)** Initilizes the task. Assigns :ref:`agent` and :ref:`blackboard`, and calls :ref:`_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** **(** :ref:`BTTask` task **)** |const| 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| 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` **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 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` task **)** 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** **(** int 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.)`