How do I detect if a Gameplay behavior from a Smart Object has been aborted ?

Hello :waving_hand:

I’m trying to detect within a gameplay behaviour if it has been aborted

For context, I have an IA that can interact with a bed that is a smart object. This smart object has a slot that triggers a gameplay behaviour which triggers a looped timer by function name so the sleep meter increase gradually. My problem is that whenever, this gameplay behaviour is aborted, I can’t find a way to detect from within it that it has been aborted and therefore, I can’t stop the timer.


Here I can correctly stop the gameplay behaviour but the timer continues going

I tried using “Event OnFinished”, but it doesn’t trigger despite the AI doing something else. Here, the print string doesn’t even trigger.

edit : I’m now realizing that the End Task only stops the “Move to and use smart object” node, not the gameplay behavior itself. Is there a way to also stops the gameplay behavior when the task is aborted, or are they completely independant ? I’m confused

Not sure how its setup as a whole, still can you try using “clear and invalidate timer” ?

Clearing the timer works fine, If the AI finishes all the sleep cycles it stops as intended. the problem is just that I can’t trigger it from within the gameplay behavior if it’s aborted before it finishes.
Sorry for the confusion.

OK so :slight_smile: just let me know if I am talking BS :slight_smile:

AI uses SO
SO creates a task (sleepmeter)
Abort command comes in
SO stops being used
Task is not ended.
However AI BT is continued doing its job.

imo there is multiple ways to solve that.

  • On task itself you can create an additonal event to cancel out if owner SO not in use.
  • You can check a tag always on the timer loop if owner SO in use or has a tag. (since you said its looped)
  • According to End Task | Unreal Engine 5.5 Documentation | Epic Developer Community this say you can use on completed delegate to complete the behaviour in tree. Since Note:: you need to call EndTask before sending out any “on completed” delegates. If you don’t the task will still be in an “active” state while the event receivers may assume it’s already “finished”

I’m not sure this is exactly that. I’m going to try to be more precise.
I’ve followed the SO quick start and I’m basically doing it the same way here:

  1. A behavior tree triggers a task that search for compatible SO (here it depends on the AI needs) which returns a Claim Handle
  2. Then, the BT triggers a Task That use the Claim handle to trigger the node "Move to and use smart object with gameplay behavior
  3. This makes my AI use a gameplay behavior that contains a looped timer to gradually increase the sleep meter.
  4. Somtimes the BT cancel tasks so I need to manually cancel the “Move to and use…” node.

My problem is that it doesn’t stop the timer on the gameplay behavior and I can’t seem to get a reference to it from the “Async Task” variable. I though “Event On Finished” from the gameplay behabior would be triggered but it only does when The Gameplay behavior ends by itself.

Ok so i ended up creating a child class of gameplay behavior where I handled cancelling by binding custom event to an event dispatcher in my AI_controller. Kind of convoluted but i works fine. If anyone needs more detail, let me know.

2 Likes