[Solved]MouseWheelUp and MouseWheelDown in C++ not calling delegates

Ok, firstly, I apologize for the title. I’ve found numerous similar posts about blueprints, but none that seem to answer my issue.

I am trying to create the ability for a user to use the mouse wheel to change how fast they’re walking. Scrolling up should increase, scrolling down should decrease. This is what I have:

In the character.h:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Speed Variables")
	float MinimumSpeed;

	UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = "Speed Variables")
	float MaximumSpeed;

private:
	
	UPROPERTY(VisibleAnywhere, Category = "Speed Variables")
	bool bIncreasingSpeed;

	UPROPERTY(VisibleAnywhere, Category = "Speed Variables")
	bool bDecreasingSpeed;

	float MovementSpeed;

	UPROPERTY(VisibleAnywhere, Category = "Speed Variables")
	float VariableSpeed;

	FVector MovementInput;

	UCameraComponent* Camera;

	void MoveForward(float AxisInput);
	void MoveRight(float AxisInput);

	void IncreaseSpeed();
	void DecreaseSpeed();

The above is the declarations of my variables and methods. MinimunSpeed and MaximumSpeed are set in th editor so I can find the right speeds for my goal once this is working.

In the character.cpp:

void AStealthCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	Super::SetupPlayerInputComponent(InputComponent);

	InputComponent->BindAxis("MoveForward", this, &AStealthCharacter::MoveForward);
	InputComponent->BindAxis("MoveRight", this, &AStealthCharacter::MoveRight);
	InputComponent->BindAxis("MouseTurn", this, &AStealthCharacter::AddControllerYawInput);
	InputComponent->BindAxis("MouseLook", this, &AStealthCharacter::AddControllerPitchInput);

	InputComponent->BindAction("IncreaseSpeed", IE_Pressed, this, &AStealthCharacter::IncreaseSpeed);
	InputComponent->BindAction("DecreaseSpeed", IE_Pressed, this, &AStealthCharacter::DecreaseSpeed);
}

void AStealthCharacter::IncreaseSpeed()
{
	if (!(VariableSpeed >= MaximumSpeed))
	{
		bIncreasingSpeed = true;
	}
}

void AStealthCharacter::DecreaseSpeed()
{
	if (VariableSpeed > MinimumSpeed)
	{
		bDecreasingSpeed = true;
	}
}

void AStealthCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (!MovementInput.IsZero())
	{
		MovementInput = MovementInput.GetSafeNormal() * 100.0f;
		FVector NewLocation = GetActorLocation();
		NewLocation += GetActorForwardVector() * MovementInput.X * DeltaTime;
		NewLocation += GetActorRightVector() * MovementInput.Y * DeltaTime;
		SetActorLocation(NewLocation);
	}

	if (bIncreasingSpeed)
	{
		VariableSpeed += MinimumSpeed + MinimumSpeed;
		MovementSpeed = VariableSpeed;
		bIncreasingSpeed = false;
	}

	if (bDecreasingSpeed)
	{
		VariableSpeed -= MinimumSpeed + MinimumSpeed;
		MovementSpeed = VariableSpeed;
		bDecreasingSpeed = false;
	}
}

I’m setting the bools to true and if they’re true, in the tick they should increase/decrease the speed and then set the appropriate bool back to false. I tried this as a workaround after having the logic in the delegate wasn’t working. This isn’t working either. I made all of the values visible in the editor, and as far as I can tell, between that and setting breakpoints, my delegates don’t get called on scrolling and I can’t figure out why.

Hi Morgrhim,

I haven’t tried this myself, but I am assuming the answer is because MouseWheel is not a button action. It would be an axis. So you would have to associate it with axis event like you have done the MoveForward event. So you would have

void IncreaseSpeed(float ScrollAmt); // 0 for nothing, > 0 for upward scrolling and < 0 for downward, ofcourse depending on inverted axis.

InputComponent->BindAxis("IncreaseSpeed", this, &AStealthCharacter::IncreaseSpeed);

Hopefully that works for you mate!

Kishore

Nope. I tried it that way. In every question I’ve found for blueprints referring to something similar, Unreal staff has stated that Mouse Wheel Up and Mouse Wheel Down have to be bound as actions, as they read as button presses in the engine. Something about the tick not catching the scroll properly. Don’t get me wrong, I agree it should be an axis, but it isn’t.

It turns out I was using the wrong input. Mouse Wheel Up and Mouse Wheel Down refer to the actual button press of the MMB. There’s a mouse function called Mouse Wheel Axis for what I was doing.