: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/BTProbabilitySelector.xml.

.. _class_BTProbabilitySelector:

BTProbabilitySelector
=====================

**Inherits:** :ref:`BTComposite<class_BTComposite>` **<** :ref:`BTTask<class_BTTask>` **<** :ref:`BT<class_BT>`

BT composite that chooses a child task to execute based on attached probabilities.

.. rst-class:: classref-introduction-group

Description
-----------

BTProbabilitySelector chooses a child task to execute based on attached probabilities. It is typically used for decision-making purposes. Probability distribution is calculated based on weights assigned to each child task.

Returns ``SUCCESS`` when a child task results in ``SUCCESS``.

Returns ``RUNNING`` when a child task results in ``RUNNING``.

The behavior of BTProbabilitySelector when a child task results in ``FAILURE`` depends on the :ref:`abort_on_failure<class_BTProbabilitySelector_property_abort_on_failure>` value:

- If :ref:`abort_on_failure<class_BTProbabilitySelector_property_abort_on_failure>` is ``false``, when a child task results in ``FAILURE``, BTProbabilitySelector will normalize the probability distribution over the remaining children and choose a new child task to be executed. If all child tasks fail, the composite will return ``FAILURE``.

- If :ref:`abort_on_failure<class_BTProbabilitySelector_property_abort_on_failure>` is ``true``, when a child task results in ``FAILURE``, BTProbabilitySelector will not choose another child task to be executed and will immediately return ``FAILURE``.

.. rst-class:: classref-reftable-group

Properties
----------

.. table::
   :widths: auto

   +----------+--------------------------------------------------------------------------------+-----------+
   | ``bool`` | :ref:`abort_on_failure<class_BTProbabilitySelector_property_abort_on_failure>` | ``false`` |
   +----------+--------------------------------------------------------------------------------+-----------+

.. rst-class:: classref-reftable-group

Methods
-------

.. table::
   :widths: auto

   +-----------+--------------------------------------------------------------------------------------------------------------------------------+
   | ``float`` | :ref:`get_probability<class_BTProbabilitySelector_method_get_probability>`\ (\ child_idx\: ``int``\ ) |const|                  |
   +-----------+--------------------------------------------------------------------------------------------------------------------------------+
   | ``float`` | :ref:`get_total_weight<class_BTProbabilitySelector_method_get_total_weight>`\ (\ ) |const|                                     |
   +-----------+--------------------------------------------------------------------------------------------------------------------------------+
   | ``float`` | :ref:`get_weight<class_BTProbabilitySelector_method_get_weight>`\ (\ child_idx\: ``int``\ ) |const|                            |
   +-----------+--------------------------------------------------------------------------------------------------------------------------------+
   | ``bool``  | :ref:`has_probability<class_BTProbabilitySelector_method_has_probability>`\ (\ child_idx\: ``int``\ ) |const|                  |
   +-----------+--------------------------------------------------------------------------------------------------------------------------------+
   | |void|    | :ref:`set_probability<class_BTProbabilitySelector_method_set_probability>`\ (\ child_idx\: ``int``, probability\: ``float``\ ) |
   +-----------+--------------------------------------------------------------------------------------------------------------------------------+
   | |void|    | :ref:`set_weight<class_BTProbabilitySelector_method_set_weight>`\ (\ child_idx\: ``int``, weight\: ``float``\ )                |
   +-----------+--------------------------------------------------------------------------------------------------------------------------------+

.. rst-class:: classref-section-separator

----

.. rst-class:: classref-descriptions-group

Property Descriptions
---------------------

.. _class_BTProbabilitySelector_property_abort_on_failure:

.. rst-class:: classref-property

``bool`` **abort_on_failure** = ``false`` :ref:`🔗<class_BTProbabilitySelector_property_abort_on_failure>`

.. rst-class:: classref-property-setget

- |void| **set_abort_on_failure**\ (\ value\: ``bool``\ )
- ``bool`` **get_abort_on_failure**\ (\ )

If ``true``, BTProbabilitySelector will not choose another child to execute and will return ``FAILURE`` when a child task results in ``FAILURE``.

.. rst-class:: classref-section-separator

----

.. rst-class:: classref-descriptions-group

Method Descriptions
-------------------

.. _class_BTProbabilitySelector_method_get_probability:

.. rst-class:: classref-method

``float`` **get_probability**\ (\ child_idx\: ``int``\ ) |const| :ref:`🔗<class_BTProbabilitySelector_method_get_probability>`

Returns the child task's selection probability.

.. rst-class:: classref-item-separator

----

.. _class_BTProbabilitySelector_method_get_total_weight:

.. rst-class:: classref-method

``float`` **get_total_weight**\ (\ ) |const| :ref:`🔗<class_BTProbabilitySelector_method_get_total_weight>`

Returns the total weight of all child tasks.

.. rst-class:: classref-item-separator

----

.. _class_BTProbabilitySelector_method_get_weight:

.. rst-class:: classref-method

``float`` **get_weight**\ (\ child_idx\: ``int``\ ) |const| :ref:`🔗<class_BTProbabilitySelector_method_get_weight>`

Returns the child task's weight within the weighted probability selection algorithm.

.. rst-class:: classref-item-separator

----

.. _class_BTProbabilitySelector_method_has_probability:

.. rst-class:: classref-method

``bool`` **has_probability**\ (\ child_idx\: ``int``\ ) |const| :ref:`🔗<class_BTProbabilitySelector_method_has_probability>`

Returns whether the child task at index ``child_idx`` participates within the weighted probability selection algorithm and has a probability assigned to it. Returns ``false`` for :ref:`BTComment<class_BTComment>` tasks.

.. rst-class:: classref-item-separator

----

.. _class_BTProbabilitySelector_method_set_probability:

.. rst-class:: classref-method

|void| **set_probability**\ (\ child_idx\: ``int``, probability\: ``float``\ ) :ref:`🔗<class_BTProbabilitySelector_method_set_probability>`

Sets the child task's weight calculated based on the desired probability.

.. rst-class:: classref-item-separator

----

.. _class_BTProbabilitySelector_method_set_weight:

.. rst-class:: classref-method

|void| **set_weight**\ (\ child_idx\: ``int``, weight\: ``float``\ ) :ref:`🔗<class_BTProbabilitySelector_method_set_weight>`

Sets the child task's weight for the weighted probability selection algorithm.

.. |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.)`
