Im try make a shooter with auto weapon so im make Fire() function that calculate firespeed when im call it and fire if can. The problem im use a SetupPlayerInputComponent as
PlayerInputComponent->BindAction(“Fire”, EInputEvent::IE_Pressed, this, &AMyCharacter::FireShot);
And EInputEvent don’t support key hold as I see. And only possible solution im found its add a bool variable that be true on button press and false when im released it and then check in Tick if(bool) fire. So its look a not ideal solution and a bad code.
So there any easy way to make a holdkey Event? Or im miss a some normal way to HoldKey?
Someone suggested Setting a looping timer on key press and cancelling it on release as an alternative to using tick in this thread
I’ve not tried an implementation though.
Thaks that works for me as
APlayerController* playerController = (APlayerController*)()->GetFirstPlayerController();
if (playerController->IsInputKeyDown(EKeys::LeftMouseButton))
{
FireShot();
}
The term used in programing for this state (And UE4 use it) is “key is down” and up if key is not pressed. There no input event for hold as it would be no diffrent from tick, so insted of using event, check the state of the key is down
you can also check how long it was pressed
But doing boolean way is not bad either, that boolean can be state indicator that player is firing and can be triggered by other ways then player input