BindAxis Delagate Argument

I’m pretty new to C++/UE4, and I am trying to call a void method through the BindAxis function.
But in the documentation, it says that I need to create a delegate. I have no idea how to do this. The most I’ve done was creating delegates in C# back in the day.

So my aims are:

  • To have a working BindAxis function
  • To have a method that listens to that function, and fires off each time the engine receives input from the axis keybind
  • And eventually, to change the X/Y/Z position of an actor.

My current codes:

//Snippet of part of MyPawn.cpp

// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	Super::SetupPlayerInputComponent(InputComponent);

	InputComponent->BindAxis("MoveForward", this, &AMyPawn::MoveForward);

}

void AMyPawn::MoveForward()
{
	
}

//MyPawn.h
UCLASS()
class MYPROJECT3_API AMyPawn : public APawn
{
GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	AMyPawn();

	// 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 MoveForward();
};

Thank you and have a wonderful day :slight_smile:

change

virtual void MoveForward();

to

virtual void MoveForward(float Scale);

and update your source code to reflect this change:

void AMyPawn::MoveForward(float Scale)
 {
     if (Scale != 0.f)
     {
         // move character
     }
 }