Tuerer
(Tuerer)
May 2, 2023, 2:50pm
1
Enhanced Input offers the possibility to trigger key presses after holding them down for some time, but is there a way to get the elapsed/remaining hold time?
If I want to show the hold-down indication, I still have to create several variables and use tick to count the hold time, but I feel like there should be a way to extract this value from the Enhanced Input system. Is there?
Thank you!
3dRaven
(3dRaven)
May 2, 2023, 6:09pm
2
Tuerer:
Enhanced
You can try using the Quartz clock subsystem
1 Like
Tuerer
(Tuerer)
May 5, 2023, 10:49am
3
Okay, there is an “elapsed time” variable, but it’s inside the FInputActionInstance struct. There is a constructor that allows creating an FInputActionInstance from UInputAction
FInputActionInstance(const UInputAction* InSourceAction);
but when I try doing that, the elapsed time value is always 0.
What is the correct way to create an input instance in c++ to get hold of these values, like it’s done in this blueprint node?
1 Like
3dRaven
(3dRaven)
May 5, 2023, 2:44pm
4
Tuerer:
FInputActionInstance
Ok go inside your input action and under Triggers add “Hold”.
You will get elapsed seconds added to your input event
If you print out Elapsed seconds from the Ongoing exec pin you get the elapsed time shown on screen.
To do it in c++ I’d guess inside of SetupPlayerInputComponent
UInputTriggerHold* HoldTrigger = NewObject<UInputTriggerHold>();
YourAction->Triggers.Add(HoldTrigger);
where YourAction is a pointer UInputAction
After pressing play I can confirm it does add hold to the input action button triggers via code.
Edit:
Ok so to get the elapsed time in c++ I tried an example with jump where AtppCharacter is my character class
the bind inside SetupPlayerInputComponent
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Ongoing, this, &AtppCharacter::IsJumping);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
the function to display the elapsed time
void AtppCharacter::IsJumping(const FInputActionInstance& Instance) {
GEngine->AddOnScreenDebugMessage(1, 1, FColor::Cyan, "IS JUMPING " + FString::SanitizeFloat(Instance.GetElapsedTime()));
}
function def in header
UFUNCTION()
void IsJumping(const FInputActionInstance& Instance);
8 Likes
Tuerer
(Tuerer)
May 6, 2023, 12:12pm
5
Yes, this works, thank you.
I didn’t know you could pass the instance as a function parameter here.
I can’t see where I can mark this as resolved =(
1 Like
3dRaven
(3dRaven)
May 6, 2023, 1:30pm
6
Can’t help you there. Never made a question myself, I just try to answer them
Maybe the mods will pick this thread up with time and mark it as resolved.
1 Like