diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index 5e433f7..72d1736 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -51,6 +51,7 @@ void BTPlayer::_load_tree() { Node *scene_root = get_owner(); ERR_FAIL_NULL_MSG(scene_root, "BTPlayer: Initialization failed - can't get scene root (make sure the BTPlayer's owner property is set)."); bt_instance = behavior_tree->instantiate(agent, blackboard, this); + ERR_FAIL_COND_MSG(bt_instance.is_null(), "BTPlayer: Failed to instantiate behavior tree."); #ifdef DEBUG_ENABLED bt_instance->set_monitor_performance(monitor_performance); bt_instance->register_with_debugger(); @@ -118,7 +119,13 @@ void BTPlayer::update(double p_delta) { } if (active) { - bt_instance->update(p_delta); + BT::Status status = bt_instance->update(p_delta); + emit_signal(LW_NAME(updated), status); +#ifndef DISABLE_DEPRECATED + if (status == BTTask::SUCCESS || status == BTTask::FAILURE) { + emit_signal(LW_NAME(behavior_tree_finished), status); + } +#endif // DISABLE_DEPRECATED } } @@ -222,9 +229,12 @@ void BTPlayer::_bind_methods() { BIND_ENUM_CONSTANT(PHYSICS); BIND_ENUM_CONSTANT(MANUAL); - ADD_SIGNAL(MethodInfo("behavior_tree_finished", PropertyInfo(Variant::INT, "status"))); ADD_SIGNAL(MethodInfo("updated", PropertyInfo(Variant::INT, "status"))); +#ifndef DISABLE_DEPRECATED + ADD_SIGNAL(MethodInfo("behavior_tree_finished", PropertyInfo(Variant::INT, "status"))); +#endif + #ifdef DEBUG_ENABLED ClassDB::bind_method(D_METHOD("_set_monitor_performance", "enable"), &BTPlayer::_set_monitor_performance); ClassDB::bind_method(D_METHOD("_get_monitor_performance"), &BTPlayer::_get_monitor_performance); diff --git a/doc/source/classes/class_behaviortree.rst b/doc/source/classes/class_behaviortree.rst index 5b7a89e..f35f715 100644 --- a/doc/source/classes/class_behaviortree.rst +++ b/doc/source/classes/class_behaviortree.rst @@ -121,7 +121,7 @@ Stores and manages variables that will be used in constructing new :ref:`Blackbo - |void| **set_description**\ (\ value\: ``String``\ ) - ``String`` **get_description**\ (\ ) -User-provided description of the BehaviorTree. +User-provided description of the **BehaviorTree**. .. rst-class:: classref-section-separator @@ -174,11 +174,7 @@ Returns the root task of the BehaviorTree resource. :ref:`BTInstance` **instantiate**\ (\ agent\: ``Node``, blackboard\: :ref:`Blackboard`, instance_owner\: ``Node``\ ) |const| :ref:`🔗` -Instantiates the behavior tree and returns :ref:`BTInstance`. - -\ ``instance_owner`` should be the scene node that will own the behavior tree instance. - -This is typically a :ref:`BTPlayer`, :ref:`BTState`, or a custom player node that controls the behavior tree execution. +Instantiates the behavior tree and returns :ref:`BTInstance`. ``instance_owner`` should be the scene node that will own the behavior tree instance. This is typically a :ref:`BTPlayer`, :ref:`BTState`, or a custom player node that controls the behavior tree execution. .. rst-class:: classref-item-separator diff --git a/doc/source/classes/class_btinstance.rst b/doc/source/classes/class_btinstance.rst index 7b2e993..0a698f5 100644 --- a/doc/source/classes/class_btinstance.rst +++ b/doc/source/classes/class_btinstance.rst @@ -12,9 +12,14 @@ BTInstance **Inherits:** -.. container:: contribute +Represents a runtime instance of a :ref:`BehaviorTree` resource. - There is currently no description for this class. Please help us by :ref:`contributing one `! +.. rst-class:: classref-introduction-group + +Description +----------- + +Can be created using the :ref:`BehaviorTree.instantiate` method. .. rst-class:: classref-reftable-group @@ -178,11 +183,7 @@ Registers the behavior tree instance with the debugger. |void| **unregister_with_debugger**\ (\ ) :ref:`🔗` -Unregisters the behavior tree instance from the debugger. This is typically - -not necessary, as the debugger will automatically unregister the instance - -when it is freed. +Unregisters the behavior tree instance from the debugger. This is typically not necessary, as the debugger will automatically unregister the instance when it is freed. .. rst-class:: classref-item-separator diff --git a/doc/source/classes/class_btplayer.rst b/doc/source/classes/class_btplayer.rst index d92a25a..ed71cad 100644 --- a/doc/source/classes/class_btplayer.rst +++ b/doc/source/classes/class_btplayer.rst @@ -78,6 +78,8 @@ Signals **behavior_tree_finished**\ (\ status\: ``int``\ ) :ref:`🔗` +**Deprecated:** Use :ref:`updated` signal instead. + Emitted when the behavior tree has finished executing and returned ``SUCCESS`` or ``FAILURE``. Argument ``status`` holds the status returned by the behavior tree. See :ref:`Status`. diff --git a/doc_classes/BTPlayer.xml b/doc_classes/BTPlayer.xml index c8e8a39..5c0cb5c 100644 --- a/doc_classes/BTPlayer.xml +++ b/doc_classes/BTPlayer.xml @@ -54,7 +54,7 @@ - + Emitted when the behavior tree has finished executing and returned [code]SUCCESS[/code] or [code]FAILURE[/code].