# State Tree Delay Task not working

**URL:** <https://forums.unrealengine.com/t/state-tree-delay-task-not-working/1369359>\
**Category:** AI\
**Tags:** task, unreal-engine, state-machines, bug-report, Blueprint, question\
**Created:** [November 6, 2023, 9:59pm UTC](https://forums.unrealengine.com/t/state-tree-delay-task-not-working/1369359 "2023-11-06T21:59:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuisMini](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LuisMini](https://forums.unrealengine.com/u/LuisMini)\
**Post date:** [November 6, 2023, 9:59pm UTC](https://forums.unrealengine.com/t/state-tree-delay-task-not-working/1369359/1 "2023-11-06T21:59:24Z")

</div>

Hello, I’ve recently started messing around with State Trees, I was trying to implement a common example I’ve done many times with BTs which consists in:

- Agent Finds random position
- Agent moves to the found position
- Agent Waits X seconds

However I’ve come across two different situations in State Trees where the placement of the “Wait State” that runs the “Delay Task” seems to change the execution of the delay task.

In the following image, the behavior works as expected, the agent waits, finds a position and moves to that position.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/c/0/fc0b3e7e602fc0db5084af4e32b2a102f93832d6.png)

However, if I place the “Wait Delay” state, below the “Find Position” state, which contains a task, it no longer works.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/c/4/3c4997b04c4dfac91eb3479d5c8aa39964654cf3.png)

I created my own Wait task to see what was happening, my task blueprint simply executed a delay node. I replaced the default Delay Task with my custom one, but the behavior remained was the same.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/b/4/5b4aa03b113bee52863f046d19cfc3a91784ce5c.png)

When the “Wait Delay” was placed below the “Find Position” State, it would just spam the output log with the first print on my custom task, never actually finishing the delay and breaking the State Tree.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/7/a770c1ba61aad216e56d5ac501ace033b355c2ac.png)

I’ve read the State Tree Overview Documentation many times at this point and didn’t read anything that would cause this issue.  
The documentation actually shows a similar setup with smart objects, and explains the following:  
" StateTree comes with the **Next** Transition, which simplifies creating and arranging a sequence of States.

In the example above, when the **Reach** State is selected, the **Find SO Target** , **Move to SO** , and **Look** Tasks are executed. Once the Tasks are completed, the **Next** Transition moves execution to the **Use** State below, where its Tasks can begin executing."

So I guess my question is, is this Intended? Have I encountered a bug? I’m failing to understand why this could be the intended behavior, any insight would be appreciated.

---

<div class="post-metadata">

**Author:** ![J0hnC0nn0r](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@J0hnC0nn0r](https://forums.unrealengine.com/u/J0hnC0nn0r)\
**Post date:** [March 18, 2024, 8:48pm UTC](https://forums.unrealengine.com/t/state-tree-delay-task-not-working/1369359/2 "2024-03-18T20:48:31Z")

</div>

I’m having Verbatim the exact issue and it happens when you try to use ‘Try Enter’ to force a Parent State to Run a Task…this inevitably forces you to also specifically tell it where you want to transition…which seems to be completely breaking the State Tree. I reported this as a bug and I hope to get some answer…I would really like to see staff respond to this…

---

<div class="post-metadata">

**Author:** ![J0hnC0nn0r](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@J0hnC0nn0r](https://forums.unrealengine.com/u/J0hnC0nn0r)\
**Post date:** [March 18, 2024, 10:11pm UTC](https://forums.unrealengine.com/t/state-tree-delay-task-not-working/1369359/3 "2024-03-18T22:11:29Z")

</div>

I thought I would inform you that I did find a way around this but it requires you to not run tasks and try enter states with children. I’m not sure if that is supposed to be a feature or if it’s just that people are misunderstanding State Trees and doing it like that but it doesn’t seem to be a safe way to set things up.

Btw I did run this in a Source Build of UE5.4 and it did the same thing so I think it may be safe to assume this will still be a problem when 5.4 is officially released.

---

<div class="post-metadata">

**Author:** ![6to9Games](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@6to9Games](https://forums.unrealengine.com/u/6to9Games)\
**Post date:** [May 14, 2024, 4:23pm UTC](https://forums.unrealengine.com/t/state-tree-delay-task-not-working/1369359/4 "2024-05-14T16:23:05Z")

</div>

So, this is **what I think** is happening.

I have recreated the setup you have with a short task (called **Shortus** ), a long task (called **Longus** ) and a very short task (called **Cat** ). Don’t judge me please. 😛

![st v1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/a/afad89c45d40d660f0aa03ba50a18bf4193dae74.jpeg)

- State Selection is happening
  - Selector states (states with children or “leaf states”) cant be selected directly
  - _Leaf 1_ can be selected, so it is selected

- Active states: _Leaf 1_ and _Selector_
- **ALL** tasks of _Leaf 1_ and _Selector_ start running **concurrently**
- Cat task is very quick, Longus takes a while.
- When _Cat_ finishes, the transition is triggered. The transition for _Cat_ is to go to _Leaf 1_
- For SOME reason _Cat_ is not run again, but keeps triggering the transition to _Leaf 1_ over and over again

You can “solve” this by not executinga Finish Task Node on _Cat_. Then the the _Leaf 1_ is run, then _Leaf 2_, and it repeats the tree, but for some reason never runs _Cat_ again.

If you instead remove the transition from the _Selector_, it will start _Cat_ over and over again.

Yeah, I tried to figure it out for like an hour now, with no success.
