I have some small Blueprint here which is calling function Throw. Throw function comes from C++ and takes one parameter Power, and Power how I want it to work is to be based on the amount of time that key is being held (the longer key is pressed, the bigger value of Power). To achieve that I used Get Input Key Time Down, but it does not work. Helper function Print always prints 0. Does someone knows why?
Thanks. I just checked your 2nd solution, unfortunately it does not work for me. I still get 0s. Also, even the simples Blueprint prints out 0s no matter how long i hold the key:
I suspect the logic from my first post in general is ok, and all these Gates etc. are working correctly. Only problem seems to be with Get Input Key Time Down, which for some reason doesnât work. I suspect it might be related to the issue from last part (starts at 2:30) of this video:
However, my case is different (I do not have any BP logic in the level and I donât know how to set up my Player Controller correctly).
Hey @szwarc9311, how do you find this approach? It uses Timers to get how long something happened here! So every second the Timer fires off the âIncrementHoldTimeâ Event which +1 the HoldTime Variable. On release, it gets the elapsed time since the last loop and adds that float to the Holdtime, ends the Timer and does something, here, it PrintStrings the Holdtime for prove.
To clarify whatâs happening, I think the reason youâre getting âTime down = 0â is because youâre triggering on release, and at that point the key is not held down at all, itâs released, so time down will be 0.
I think the simplest modification to your setup would be to just store âcurrent game time in secondsâ when you press down the button, and when you release the button subtract âcurrent game time in secondsâ from that saved time.
I tested @herb64 solution and it works, that may help you, you donât need to setup a custom player controller, just the basic class in your game mode will work.
hi @szwarc9311 , for some reason there was no notification about your answer.
The code snippet you pasted does not process any âPressedâ key event at all. So this will definitely print 0.0 - because when getting time on âReleasedâ this of course returns 0. The important part in my second variant is to enable ticking and keep value stored in a variable at times, while the key is pressed and just disable when releasing the key.
The relevant part in Matthew Wadsteins video you mention is about receiving input.
The only important part is of course, that you can receive input - but you already did setup this in your original blueprint with your input events - so the code I showed you should work if you paste it in there.
Hey @szwarc9311 , Why did you choose this option with the Tick Enabled over my solution? Did it bring you better performance? I would rather Not Tick this Everytime Because I expect you to not throw all the time tbhâŚ
To be honest I just used the solution that i could almost literally copy/paste into my project. Your solution for example has Custom Event created, which I do not know how should look like in my case. I will try to get back to this problem later, after getting more experience with the engine.
Iâve been trying to use this same node without having to use Tick and I just found an amazing solution in this video tutorial. Maybe it will help you all.
You could also setup your Input Keys to activate Events and Functions this way. You would have to create specific Booleans for each Key. I hope you all find this helpful.