Hello all. For input events, I see that there are outputs for Pressed and Released. How about when, say the left mouse button, is held down and having it continue to activate the output? If there is a way to detect that, is there a setting for the delay between each time the event is fired while it is held down, or would I need to use a delay?
maybe a while loop and have a bool set to true when pressed, and set false when released?
Sounds like that should work. Thanks
I’m surprised that there isn’t an output for it. Kismet Input Events had it and would be really useful.
From the Get Player Controller node, you can use the Get Input Key Time Down node:
The the input you are checking against is set with the Key input and the return value is 0 if the key is up or the cumulative time the key has been held otherwise. You can set up comparison that returns a boolean and use that to power a Branch or WhileLoop, which ever you want to use.
Hope that helps out!
I went with the while loop approach, but the editor seems to hang indefinitely when ever the bool for the while loop is set to true. Any ideas what is going on?
I apologize, this is actually a bad setup to actually use with a WhileLoop, didn’t mean to direct you to use it in this case–the WhileLoop expects that the exit condition to kick out of loop rests somewhere inside of the Loop Body, which won’t be the case in your scenario. Here’s one way you can setup what you’re wanting to do:
Pressing or Releasing F will toggle the IsCharging boolean to true or false. Event Tick fires off every frame and checks to see if you are holding down the F key (represented by the Branch checking the IsCharging boolean). If you are still holding the key down, it sets the Hold Time value to be the time you’ve been holding down the F key (from the same function I mentioned above). If you release the F key, it then prints out the final Hold time.
Sorry for the confusion!
No worries! Thanks so much for the setup. Much appreciated.
edit: Just tried it and it worked perfectly!
Added a better screenshot, last one was hard to read.
Can we do this with an InputAction rather than a key? Not sure if I’m missing something but I don’t see a Get Input Action Time Down
There currently isn’t any way to do such a query. The reason being that unlike a key that has a direct relationship to the hardware, actions are dependent on what input components are on the stack.
Thinking out loud about it a bit we could make that function look at the context’s input component and track the press start time on the action binding similarly to how the axis value is stored on the action binding. I’ll put in a task to look in to doing this.
In the mean time your best bet is probably to make a variable and on pressed open a gate or something similar such that you increment it by delta time in each tick. On released set the variable to 0 and close the gate.
Hey just checking on this post to see if there has/will be any progress with a Held option for the input alongside the pressed/released options. I’m happy there are ways that we can do something similar atm, but it just seems like a lot of extra work/mess. Especially when it could be as simple as you suggested
Marc touched on this in his post where he mentioned axis binding. Beware that if you follow the approach I’m about to explain, you will end up with an event that is fired every frame, not just when the key is being held down! If you go under Edit/Project Settings/Engine/Input you should see a category called “Bindings”. You can add your own axis mappings to the list by clicking on the plus sign next to it, and then specifying an input source (for instance, the ‘F’ key). You can also give it a name and a scale.
When you’ve mapped all your keys, save the project settings by clicking on “Set as Default”, then open your blueprint. When you right-click in the graph view, you’ll be able to find your new events under Input/Axis Events:
Ah that worked! Never thought of doing it that way lol. Thanks for the help
Can anybody help me create a similar action but i’m currently not having much luck with.
I want to create a charge effect when a key is held down, the longer its held for the greater the charge force is although I do want to clamp a maximum force say at 3 seconds you can’t go beyond that strength.
For example you have simple box simulating physics, when you press space bar it adds force upwards and jumps. The longer you hold space the higher it jumps but when you reach 3 seconds you can’t get any more charge.
Using Steve Alison’s blueprint above, I’d say you’d **get **the hold time variable, **clamp **it between 0 and 3, and multiply it by your base amount of impulse/force, then **set **a new variable for the force_applied to the cube. OnReleased you’d **get **that force_applied variable for the impulse amount.
Disclaimer: I am an amateur at blueprinting/coding
Going to have a go tomoz been tied up with the day job recently, cheers for the input
Use a timeline for this. start the timeline on pressed, fire when released or finished. Can set the curve along the way to be your value for either vector or float, etc. Set the timeline to end at 3 seconds, which will cause the finished output to fire. That way you can get values all the way along the curve, and they are easily adjusted as needed.
Pre make the curve as a content browser asset and reuse it in numerous locations if needed.
Ah I like the sound of this, seems like a much more elegant solution
You can also use Retriggerable Delay loop back and control when the value is read. See pic: