From 80d23f2f2337a863c9cc3afbf944b25e3911db8c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kat=20March=C3=A1n?= <kzm@zkat.tech>
Date: Fri, 23 Apr 2021 19:16:19 -0700
Subject: [PATCH] fix(thinker): launch a new action when the current action is
 in an end state

---
 src/thinker.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/thinker.rs b/src/thinker.rs
index aa5de2f..8bdaad6 100644
--- a/src/thinker.rs
+++ b/src/thinker.rs
@@ -304,11 +304,14 @@ fn exec_picked_action(
     // oscillation protection so we're not just bouncing back and
     // forth between the same couple of actions.
     if let Some((action_ent, ActionBuilderWrapper(current_id, _))) = &mut thinker.current_action {
-        if !Arc::ptr_eq(current_id, &picked_action.0) {
+        let mut curr_action_state = states.get_mut(action_ent.0).expect("Couldn't find a component corresponding to the current action. This is definitely a bug.");
+        if !Arc::ptr_eq(current_id, &picked_action.0)
+            || matches!(*curr_action_state, ActionState::Success)
+            || matches!(*curr_action_state, ActionState::Failure)
+        {
             // So we've picked a different action than we were
             // currently executing. Just like before, we grab the
             // actual Action component (and we assume it exists).
-            let mut curr_action_state = states.get_mut(action_ent.0).expect("Couldn't find a component corresponding to the current action. This is definitely a bug.");
             // If the action is executing, or was requested, we
             // need to cancel it to make sure it stops.
             match *curr_action_state {
@@ -331,7 +334,6 @@ fn exec_picked_action(
             // it as Requested if for some reason it had finished
             // but the Action System hasn't gotten around to
             // cleaning it up.
-            let mut curr_action_state = states.get_mut(action_ent.0).expect("Couldn't find a component corresponding to the current action. This is definitely a bug.");
             if *curr_action_state == ActionState::Init {
                 *curr_action_state = ActionState::Requested;
             }
-- 
GitLab