Hey everyone! For some reason, when I bind in C++ the callback function only prints a 0. Is there any step that changed from previous versions? My project is brand new, but for some reason, I only get to receive the actual value if I use it on a blueprint.
Here is my code:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "CPawn.generated.h"
UCLASS()
class CUBEMOVEMENT_API ACPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ACPawn();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION()
void MoveForward(float Throttle);
UFUNCTION()
void MoveRight(float Throttle);
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "CPawn.h"
// Sets default values
ACPawn::ACPawn()
{
// Set this pawn 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 ACPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ACPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ACPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
check(PlayerInputComponent);
PlayerInputComponent->BindAxis("MoveForward",this,&ACPawn::MoveForward);
PlayerInputComponent->BindAxis("MoveRight",this,&ACPawn::MoveRight);
}
void ACPawn::MoveForward(float Throttle)
{
UE_LOG(LogTemp, Warning, TEXT("Forward: %d"),Throttle);
}
void ACPawn::MoveRight(float Throttle)
{
UE_LOG(LogTemp, Warning, TEXT("Right: %d"),Throttle);
}
Nothing to fancy.
I would appreciate any comment, feedback, or advice you would have.