Can I adjust input actions via c++?

I think there’s a few ways to do it, but here’s what I would do.

  1. Create 2 input actions: One for when the fire button is pressed, and one for when the the fire button is released.
  2. In the function called by the pressed delegate, do something repeatedly based on what you have equipped. You can use the tick function for this or the timer manager.
  3. When the released delegate is called, stop firing.

Here’s the general idea:

void AMyPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();
	auto enhancedInput = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(this->GetLocalPlayer());
	if (enhancedInput)
	{
		enhancedInput->AddMappingContext(playerInputContext, 0);
		auto enhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent);
		if (enhancedInputComponent)
		{
			enhancedInputComponent->BindAction(beginFireAction, ETriggerEvent::Triggered, this, &AMyPlayerController::OnBeginFireAction);
			enhancedInputComponent->BindAction(endFireAction, ETriggerEvent::Triggered, this, &AMyPlayerController::OnEndFireAction);
		}
	}
}

void AMyPlayerController::OnBeginFireAction(const FInputActionValue& value)
{
	if (IsUsingPistol())
	{
		fireRate = 5.f;
	}
	else if (IsUsingRailGun())
	{
		fireRate = 0.5f;
	}

	BeginFiring();
}

void AMyPlayerController::OnEndFireAction(const FInputActionValue& value)
{
	StopFiring();
}

beginFireAction InputAction:
BeginFire

endFireAction InputAction:
EndFire