How to make player hold lever 3 times (with delay and overlap) using Enhanced Input in UE5

Hello! I’m pretty new to Unreal Engine 5, and I’m having trouble with my lever interaction.
Right now, when I hold the lever, the lever instantly completes all 3 stages and says done.

What I want instead is:
The lever should activate only once per proper hold
Then wait 4 seconds
And the player should have to hold the lever again
Repeat this 3 times total to complete the sequence

How can I set it up so it doesn’t instantly count all 3 stages from a single long hold?
I’m using IMC for the hold action.

Thanks in advance!

Hey @MrSyntNetNio how are you?

To avoid completing the three steps by holding the input only one time, you can create a boolean variable and name it something like “bIsBeingPulled” and default it to false. Then, when you start pulling the lever, if that variable is false, set it true and execute the code. But if it is true, do nothing. When you release the input, you need to set the variable back to false.

This way, you will need to release the input to be able to pull the lever again, completely avoiding the issue!

Hope this helps you! Let me know if you need more help!

1 Like

Get access to FInputActionInstance from your BP and read property ElapsedProcessedTime/ElapsedTriggeredTime, then make stages logic based on elapsed time.

2 Likes

Hi @BRGJuanCruzMK I’m good, thanks for asking — how about you?
Thank you very much for your answer! I have one problem though — when I followed your advice, I couldn’t understand how to make the condition for the branch false.
If I just use Get Boolean, it only gets the current value of the condition. Could you please help me with this if possible?

1 Like

Hey @MrSyntNetNio , I’m doing great, thanks!

Of course I can help you!

There are two ways to make it false:

  1. Make it false as default: to set it up False as default, you need to create the variable, compile, then click on the variable on the Variables list and go to “Details” tab. Thre you will have a “Default Value” section with the name of your variable and a check box. If you keep that check box empty, the variable will be false as default. If you click on that check box, it will be true as defaul!

  2. Set it false in your blueprint graph: to make it false in your blueprint, you only need to drag the variable from your Variables list to your graph, drop it there and choose “Set” instead of get.


    You will see a node like the one in the next picture. And, again, leave the check box empty to make it false, click on it to make it true.

Let me know if you need more help, and I’ll be glad to lend you a hand :smiley:

1 Like

Hi @BRGJuanCruzMK, I am glad to hear that!
Thank you for this!
I tried to do what you suggested to make the signal pass through only when it’s false and I created this setup for the branch, but it doesn’t work and gives me an error. Could you please help me with this too? Thank you again!

Hey @MrSyntNetNio !

The problem you have there is that you are using the “Sequence” node. That node executes in sequence, as its name suggests, which means that you are executing the branch node before casting to the character and setting ints variable.

What you need to do is to go from “Event Interact Hold” to the cast node, then to the set node, and from there to the branch.

But that will lead you to another problem: as you are setting the variable to false there, that branch will ALWAYS execute the “false” exec pin. You need to use a get there instead of a set.

Remember too, that you want to execute code when that variable is false, and skip the code when it is true, as I explained in my first post.

Hi @BRGJuanCruzMK!
Thank you again for your answer. It might sound a bit silly, but I thought it was executed at the same time :sweat_smile: . I have one more question: if I use Get Boolean, won’t it just take whatever value is currently inside (true or false) and then execute the branch?
I was trying to figure out how to make the condition execute only when it’s false. Could you please explain how to do that?
Thank you again!

Hey!

Ok, first of all, I recommend you to move that “Being Pulled” variable from your character to your lever actor. If you have more than one lever in your level and you put that variable in your actor, you could have issues while trying to use different levers.

The responsibility of know if can be pulled is on the levers side, not the player. So, remove that variable from the player bp and add it to the lever bp.

Then you need to know that the Branch node output is determined by the boolean you use as an input. What I’m trying to say is that if your variable is true, the branch will execute the true pin. If your variable is false, your Branch node will execute the false pin.

Knowing this, your blueprint should look something like this:

So, if the variable is true, nothing will happen. But if the variable is false, it will execute your lever code normaly.

Additionally, as you are using a “set” node to change the value of your variable to true, the next time the code try to execute, it will execute the “true” part of the branch, which is nothing in this case.

Then, when you release the lever, you set the variable back to false, allowing you to interact again with the lever!

1 Like

Hi @BRGJuanCruzMK !
After some testing and with your help, I finally got it working. Thank you so much for answering all my questions, I really mean it!!!