1616namespace BT
1717{
1818FallbackNode::FallbackNode (const std::string& name) :
19- ControlNode::ControlNode (name, {}), current_child_idx_(0 )
19+ ControlNode::ControlNode (name, {}), current_child_idx_(0 ), all_skipped_( true )
2020{
2121 setRegistrationID (" Fallback" );
2222}
@@ -25,6 +25,13 @@ NodeStatus FallbackNode::tick()
2525{
2626 const size_t children_count = children_nodes_.size ();
2727
28+ if (status () == NodeStatus::IDLE)
29+ {
30+ all_skipped_ = true ;
31+ }
32+
33+ setStatus (NodeStatus::RUNNING);
34+
2835 while (current_child_idx_ < children_count)
2936 {
3037 TreeNode* current_child_node = children_nodes_[current_child_idx_];
@@ -33,10 +40,7 @@ NodeStatus FallbackNode::tick()
3340 const NodeStatus child_status = current_child_node->executeTick ();
3441
3542 // switch to RUNNING state as soon as you find an active child
36- if (child_status != NodeStatus::SKIPPED)
37- {
38- setStatus (NodeStatus::RUNNING);
39- }
43+ all_skipped_ &= (child_status == NodeStatus::SKIPPED);
4044
4145 switch (child_status)
4246 {
@@ -79,7 +83,7 @@ NodeStatus FallbackNode::tick()
7983 }
8084
8185 // Skip if ALL the nodes have been skipped
82- return status () == (NodeStatus::RUNNING) ? NodeStatus::FAILURE : NodeStatus::SKIPPED ;
86+ return all_skipped_ ? NodeStatus::SKIPPED : NodeStatus::FAILURE ;
8387}
8488
8589void FallbackNode::halt ()
0 commit comments