I want to learn how to make a “hold to interact” system but all of the tutorials I seem to find run code after a button is held for x seconds, which is not exactly what I’m trying to do:
Essentially, I want the player to have to hold an “interact key” to run a looped animation and code while the player is holding that same key, and once the player stops holding it the interaction stops.
Example: The player can hold to interact with a cup of water. While holding the interact button, there is a drinking animation and your thirst stat goes up, and once you let go of the interact button, the code and the animation stops running, and the player places the cup back down.
Thanks in advance for any response, but please keep it simple since I’m only a beginner!
Would you mind sharing the blueprints you currently have so we can see where you would need to make any changes?
In the meantime, I would take a look at using a while loop and a variable that is only true when the “thirst meter” can increase and the player is holding the “interact key”. Here is an Unreal tutorial on basic implementation:
Hopefully the above points you in the direction you are looking for!
I have a bush that if the player gets close to, they’ll be able to interact with by clicking E, which will restore their hunger for every time that they hit the interact button by a value of 2 until the bush is depleted.
After this I added this code to my Player BP in order to check if the player is overlapping with the interaction area and if the actor has the interaction Interface.
I’m really clueless as to how to change my setup as to make it a “hold” thing instead of a “click” thing even after researching a little about the While Loops and the input releases…
I would try what revoverdrive recommended. Make a variable called interacting, on pressed you can have a timer to check for it being pressed for like 1 sec and then set interacting to true. On release clear and invalidate that timer by handle and set bool to false. Make it public and tie that into your anim bp.