# Is there a way to store commands entered to be performed in that order?

**URL:** <https://forums.unrealengine.com/t/is-there-a-way-to-store-commands-entered-to-be-performed-in-that-order/331367>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE4, CPP, Blueprint, question\
**Created:** [September 7, 2015, 7:12pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-store-commands-entered-to-be-performed-in-that-order/331367 "2015-09-07T19:12:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_e19b70ae1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e19b70ae1](https://forums.unrealengine.com/u/anonymous_user_e19b70ae1)\
**Post date:** [September 7, 2015, 7:12pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-store-commands-entered-to-be-performed-in-that-order/331367/1 "2015-09-07T19:12:45Z")

</div>

For example if I jump and I hit the crouch button - I want him to crouch as soon as he lands OR

If like in Dark Souls - when you press the attack button before you finish your 1st attack animation - he will attack with a 2nd combo move

Either blueprint or C++

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [September 7, 2015, 9:47pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-store-commands-entered-to-be-performed-in-that-order/331367/2 "2015-09-07T21:47:52Z")

</div>

I don’t think there’s a direct way to store key presses up for later. If there is, I’d be glad to learn about it. 🙂

There a couple of ways to work around that, though.

The first idea that jumps to mind is to “convert” a key press into something more easible storable (like an enum value) and push it into an array of “queued” commands if a command cannot be executed right away. Then when the current action ends, you could get and remove the first element of the array (if it’s non-empty) and, depending on its value (for example using a Switch node), trigger the function the command would have triggered if it had been possible at the time.

If you only have a few highly specific situations where a given action might not be possible at the time but needs to happen later, you could also use _Gate nodes_. In response to the key press, add a Branch. If the action is possible right now, do that. Otherwise if the action will be possible later, _open_ a Gate. When the current action preventing the execution of the command ends, attempt to _enter_ the Gate. This will only execute if the player had pressed the other key earlier. After triggering the action, make sure to _close_ the gate again. You can also _close_ the Gate if the player does something else in the meantime invalidating the second key press.

[https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/FlowControl/index.html#gate](https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/FlowControl/index.html#gate)

For combo moves, you could also check out _Animation Montages_. Use _Branch Points_ to handle switching between different animations and _Anim Notifies_ to trigger specific effects depending on which animation is playing (like different amount of damage dealt, stunning the target or knocking the opponent a specified distance).

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

> **[Animation Montage](https://docs.unrealengine.com/5.1/en-US/animation-montage-in-unreal-engine/)**
>
> Animation Montages are animation assets that enable you to combine animations in a single asset and control playback using Blueprints.

These are just some ideas off the top of my head. Which one works best really depends on the circumstances of your game. You might end up using a combination of all three or come up with something entirely different.

Good luck!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e19b70ae1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e19b70ae1](https://forums.unrealengine.com/u/anonymous_user_e19b70ae1)\
**Post date:** [September 7, 2015, 10:15pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-store-commands-entered-to-be-performed-in-that-order/331367/3 "2015-09-07T22:15:57Z")

</div>

Hey 🙂 Thanks for the quick reply, I will give this a try - I’m still trying to wrap my head around enums and how they work - pretty good idea

---

<div class="post-metadata">

**Author:** ![mamoniem](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mamoniem/32/1194698_2.png) [@mamoniem](https://forums.unrealengine.com/u/mamoniem)\
**Post date:** [September 8, 2015, 1:56am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-store-commands-entered-to-be-performed-in-that-order/331367/4 "2015-09-08T01:56:22Z")

</div>

The best part of gameplay engineering, is the how!

So, don’t make things complex, that takes time and probably going to reproduce more bugs.

If I were you, I would do save game into a \*.sav file for any input sequence. At your case for example, with any key pressed, i’ll:

1. Check if the character on ground or on air.
2. If on ground, then I’ll process the action.
3. If on air, I’ll save to file (lets say the jump is0, the crouch is1, the punch is3), then you save a sequence of numbers as string.
4. Once the player on ground, I load the string using LoadFromSLot
5. Finally apply actions sequence based on the string and using if/else if.

-m

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e19b70ae1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e19b70ae1](https://forums.unrealengine.com/u/anonymous_user_e19b70ae1)\
**Post date:** [September 8, 2015, 2:49pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-store-commands-entered-to-be-performed-in-that-order/331367/5 "2015-09-08T14:49:16Z")

</div>

![57719-test.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/3/1/13195449edc48aefa711eb56387b95fc9a9d3fe2.jpeg)

This is how I have it set up currently -

When I press jump button - he jumps - turns on the bool Character is in air - When landed that bool is turned off  
When Pressing crouch - “if character is in the air” - if it’s not in the air - then I can crouch…

The problem is that If I do press the crouch button while the character is in the air - and hold it down…when he lands…he doesn’t crouch…because at the time of the button press - the bool was that he was in the air

- And when he does jump - my character put’s his legs in the air and since it’s not root motion - the root capsule lands 1st and then his legs come down…- but that’s a whole other problem I’m trying to solve

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e19b70ae1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e19b70ae1](https://forums.unrealengine.com/u/anonymous_user_e19b70ae1)\
**Post date:** [September 8, 2015, 2:49pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-store-commands-entered-to-be-performed-in-that-order/331367/6 "2015-09-08T14:49:42Z")

</div>

![57719-test.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/3/1/13195449edc48aefa711eb56387b95fc9a9d3fe2.jpeg)

This is how I have it set up currently -

When I press jump button - he jumps - turns on the bool Character is in air - When landed that bool is turned off  
When Pressing crouch - “if character is in the air” - if it’s not in the air - then I can crouch…

The problem is that If I do press the crouch button while the character is in the air - and hold it down…when he lands…he doesn’t crouch…because at the time of the button press - the bool was that he was in the air

- And when he does jump - my character put’s his legs in the air and since it’s not root motion - the root capsule lands 1st and then his legs come down…- but that’s a whole other problem I’m trying to solve
