diff --git a/bt/behavior_tree.cpp b/bt/behavior_tree.cpp index 5bd2a69..817b8a6 100644 --- a/bt/behavior_tree.cpp +++ b/bt/behavior_tree.cpp @@ -73,6 +73,8 @@ void BehaviorTree::copy_other(const Ref &p_other) { Ref BehaviorTree::instantiate(Node *p_agent, const Ref &p_blackboard, Node *p_scene_root) const { ERR_FAIL_COND_V_MSG(root_task == nullptr, memnew(BTTask), "Trying to instance a behavior tree with no valid root task."); + ERR_FAIL_NULL_V_MSG(p_agent, memnew(BTTask), "Trying to instance a behavior tree with no valid agent."); + ERR_FAIL_NULL_V_MSG(p_scene_root, memnew(BTTask), "Trying to instance a behavior tree with no valid scene root."); Ref inst = root_task->clone(); inst->initialize(p_agent, p_blackboard, p_scene_root); return inst; diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index e491ec8..5a5ea0e 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -55,7 +55,7 @@ void BTPlayer::_load_tree() { Node *agent = GET_NODE(this, agent_node); ERR_FAIL_NULL_MSG(agent, vformat("BTPlayer: Initialization failed - can't get agent with path '%s'.", agent_node)); Node *scene_root = get_owner(); - ERR_FAIL_NULL_MSG(scene_root, "BTPlayer: Initialization failed - can't get scene root (make sure the BTPlayer.owner is set)."); + ERR_FAIL_NULL_MSG(scene_root, "BTPlayer: Initialization failed - can't get scene root (make sure the BTPlayer's owner property is set)."); tree_instance = behavior_tree->instantiate(agent, blackboard, scene_root); #ifdef DEBUG_ENABLED if (IS_DEBUGGER_ACTIVE()) { diff --git a/bt/bt_state.cpp b/bt/bt_state.cpp index 08c40a6..1a29f03 100644 --- a/bt/bt_state.cpp +++ b/bt/bt_state.cpp @@ -52,7 +52,9 @@ void BTState::_update_blackboard_plan() { void BTState::_setup() { LimboState::_setup(); ERR_FAIL_COND_MSG(behavior_tree.is_null(), "BTState: BehaviorTree is not assigned."); - tree_instance = behavior_tree->instantiate(get_agent(), get_blackboard(), get_owner()); + Node *scene_root = get_owner(); + ERR_FAIL_NULL_MSG(scene_root, "BTState: Initialization failed - can't get scene root (make sure the BTState's owner property is set)."); + tree_instance = behavior_tree->instantiate(get_agent(), get_blackboard(), scene_root); #ifdef DEBUG_ENABLED if (tree_instance.is_valid() && IS_DEBUGGER_ACTIVE()) {