Error: no matching member for function call to 'BindAxis'

I am trying to create a MoveForward input which is coded in C++. Here is my code. It gives the error Error: no matching member for function call to ‘BindAxis’ for InputComponent->BindAxis(“MoveForward”, IE_Pressed, this, &AMainCharacter::movePlayerForward);

Header file:

 // Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Character.h"
#include "MainCharacter.generated.h"

UCLASS()
class TESTPROJ_API AMainCharacter : public ACharacter
{
GENERATED_BODY()

    public:
// Sets default values for this character's properties
AMainCharacter();

// Called when the game starts or when spawned
virtual void BeginPlay() override;

// Called every frame
virtual void Tick( float DeltaSeconds ) override;

// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;



virtual void movePlayerForward();

FVector CurrentVelocity;


};

CPP file:

// Fill out your copyright notice in the Description page of Project Settings.

#include "TestProj.h"
#include "MainCharacter.h"

// Sets default values
AMainCharacter::AMainCharacter()
{
// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

}

 // Called when the game starts or when spawned
void AMainCharacter::BeginPlay()
{
  Super::BeginPlay();

}

// Called every frame
void AMainCharacter::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );

}

 // Called to bind functionality to input
 void AMainCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
 {
Super::SetupPlayerInputComponent(InputComponent);
 check(InputComponent);
InputComponent->BindAxis("MoveForward", IE_Pressed, this, &AMainCharacter::movePlayerForward);

}

 void AMainCharacter::movePlayerForward(){
CurrentVelocity.X = FMath::Clamp(1.0f, -1.0f, 1.0f) * 100.0f;
 }

I have also set a Bind Axis in the project settings called MoveForward with the key P. Here is an image of the BindAxis setting.

Hello @anipandu, your problem is on the 2nd argument; an “Axis” doesnt need a state for Released / Pressed; use instead the “BindAction” if you want to use a button, that should fix your problem :wink:

//if you want to use a Button press you dont need parameters for MoveForward
 InputComponent->BindAction("MoveForward", IE_Pressed, this, &AMainCharacter::MoveForward);
 
 
 //if you want to use an axis remove the IE_Pressed AND 
 //**Make sure that MoveForward in this case receives a float**-> void MoveForward(float)
 InputComponent->BindAxis("MoveForward", this, &AMainCharacter::MoveForward);

 //implementation of MoveForward
 void AMainCharacter::MoveForward(float axisValue) { 
     CurrentVelocity.X = FMath::Clamp<float>(axisValue, -1.0f, 1.0f); 
 }

Should I just remove IE_Pressed then?

Yes, if you want to use axis, now if you want to use an “Action” as in a button pressed then no; I have added some code to the answer for easiness