# How do I make the AI choose another attack if it picks an attack already on Cooldown

**URL:** <https://forums.unrealengine.com/t/how-do-i-make-the-ai-choose-another-attack-if-it-picks-an-attack-already-on-cooldown/445934>\
**Category:** AI\
**Tags:** Behavior-Tree, decorator, unreal-engine, UE4, Blueprint, question\
**Created:** [March 25, 2019, 7:26am UTC](https://forums.unrealengine.com/t/how-do-i-make-the-ai-choose-another-attack-if-it-picks-an-attack-already-on-cooldown/445934 "2019-03-25T07:26:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slazy101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slazy101](https://forums.unrealengine.com/u/Slazy101)\
**Post date:** [March 25, 2019, 7:26am UTC](https://forums.unrealengine.com/t/how-do-i-make-the-ai-choose-another-attack-if-it-picks-an-attack-already-on-cooldown/445934/1 "2019-03-25T07:26:41Z")

</div>

Hello

I am having an issue with my AI’s behaviours. When he gets to a mid range of the player, he will choose between 6 different behaviours at random as seen below. From left to right its: DodgeLeft, DodgeRight, DodgeForward (Forgot to fix that), StrafeRight, StrafeLeft, and LaunchAttack.

 ![272273-aimidattackbehaviours.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/f/e3faffc651fe1d5613090aaa0c2f860fbffc3e3e.jpeg)

I want to use cooldowns on the 6 different behaviours so that I can make it that the AI doesn’t spam certain behaviours too quickly or make him use other behaviours more frequently.

I’ve tried using the premade Cooldown Decorator but if a behaviour that is on cooldown gets chosen again, the character just freezes in place.

What I would like, is making it so that once a behaviour goes on cooldown, it will instead immediatly pick another midrange behaviour that is not on cooldown. Does anyone know how to achieve this?

This is my service node for randomizing the attacks.

 ![272274-randommidrangeattackservicenode.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/8/a/88a7373837c931d268093028d98e8b0fa9bdf992.jpeg)

Thank you.  
Feel free to ask for anymore clarification.

---

<div class="post-metadata">

**Author:** ![MrMcKvarz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrMcKvarz](https://forums.unrealengine.com/u/MrMcKvarz)\
**Post date:** [March 25, 2019, 9:39am UTC](https://forums.unrealengine.com/t/how-do-i-make-the-ai-choose-another-attack-if-it-picks-an-attack-already-on-cooldown/445934/2 "2019-03-25T09:39:19Z")

</div>

You’ll need to create a custom decorator on each task that should go into cooldown. It should internally save its state and reset values using timers. You might have all moves go to cooldown with your enemy doing nothing.

---

<div class="post-metadata">

**Author:** ![Slazy101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slazy101](https://forums.unrealengine.com/u/Slazy101)\
**Post date:** [March 25, 2019, 10:53am UTC](https://forums.unrealengine.com/t/how-do-i-make-the-ai-choose-another-attack-if-it-picks-an-attack-already-on-cooldown/445934/3 "2019-03-25T10:53:30Z")

</div>

How would you go about setting timers? Would you use “Set Timer by Function/Event” or using delays with int variables?

---

<div class="post-metadata">

**Author:** ![MrMcKvarz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrMcKvarz](https://forums.unrealengine.com/u/MrMcKvarz)\
**Post date:** [March 25, 2019, 3:09pm UTC](https://forums.unrealengine.com/t/how-do-i-make-the-ai-choose-another-attack-if-it-picks-an-attack-already-on-cooldown/445934/4 "2019-03-25T15:09:05Z")

</div>

Set Timer by Function/Event is the only choice since decorator is called every frame and delay won’t work.

---

<div class="post-metadata">

**Author:** ![Slazy101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slazy101](https://forums.unrealengine.com/u/Slazy101)\
**Post date:** [March 26, 2019, 11:20am UTC](https://forums.unrealengine.com/t/how-do-i-make-the-ai-choose-another-attack-if-it-picks-an-attack-already-on-cooldown/445934/5 "2019-03-26T11:20:27Z")

</div>

I think I have something working. I used a blackboard boolean that gets changed within the service node by using Set Timer by Function so that I can create cooldown timers. It seems to work for now. Though not sure of the implications for later on. Thank you though!!

---

<div class="post-metadata">

**Author:** ![UE4\_PotatoClips](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UE4\_PotatoClips](https://forums.unrealengine.com/u/UE4_PotatoClips)\
**Post date:** [October 10, 2019, 6:19pm UTC](https://forums.unrealengine.com/t/how-do-i-make-the-ai-choose-another-attack-if-it-picks-an-attack-already-on-cooldown/445934/6 "2019-10-10T18:19:54Z")

</div>

Hello. It seems like you can add a bool check “isReady” key or make a list of available attack indexes that it checks against in the receive activation BP. You also dont need the switch as you can just plug the generated int into the Set Blackboard int input. Cleaning everything up helps me to visualize the next steps.
