UE4 BindAxis doesnt work

Hi! I’m trying to setup my pawn movement but something tries to stop this process. I’ve tried to log the value and the result was value=0. I double checked the input settings but everything was ok. Here is my code:

void ASCharatcer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
    {
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis("MoveForward", this, &ASCharatcer::MoveForward);
	PlayerInputComponent->BindAxis("MoveRight", this, &ASCharatcer::MoveRight);
}

void ASCharatcer::MoveForward(float Value)
{
	AddMovementInput(GetActorForwardVector() * Value);
	UE_LOG(LogTemp, Warning, TEXT("Value %d"), Value)
}


void ASCharatcer::MoveRight(float Value)
{
	AddMovementInput(GetActorRightVector() * Value);
}

What device are you using to test ? Keyboards will only output -1, 0 and 1 while a thumbstick for example would give you a value between -1 and 1. it will call it with value 0 when the key isnt pressed.

I don’t see anything wrong with your code, are you sure youre pressing the right key? :slight_smile:

Further to what 92Rob has suggested, make sure you’ve correctly spelled your Input Axis Names in the Editor, so that MoveForward and MoveRight are 100% what is in the Editor (you’ve spelled Character incorrectly in your class name).

Also, check that you’ve set your Character class as the default pawn in the Game Mode, so that it’s the one used/spawned.
(I would suspect you have already done this, as you say it’s outputting the log!)

Maybe (happened to me) I wanted to add/change behaviour in C++ and something else was already done in a Blueprint. Took me a while to notice that the event node is consuming the input and the binding functions are not executed in this case.

So you might check your blueprint input actions, if you have some.

243897-consumpeinput.png

2 Likes

Log value result is 0, because UE_LOG(LogTemp, Warning, TEXT("Value %d"), Value).
Try using UE_LOG(LogTemp, Warning, TEXT(“Value %f”), Value) instead.

Thanks man!

I can’t believe this, lol