I followed the lecture, did the same things in my code, but when I run the game it never prints the Value from the Move function. And from what I can tell, we never call the SetupPlayerInputComponent. So I really don’t understand how it’s supposed to work…
Here’s my Tank.h
#pragma once
#include "CoreMinimal.h"
#include "BasePawn.h"
#include "Tank.generated.h"
/**
*
*/
UCLASS()
class TOONTANKS_API ATank : public ABasePawn
{
GENERATED_BODY()
public:
ATank();
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private:
UPROPERTY(meta = (AllowPrivateAccess = "true"), Category = "Components", VisibleAnywhere)
class USpringArmComponent* SpringArm;
UPROPERTY(meta = (AllowPrivateAccess = "true"), Category = "Components", VisibleAnywhere)
class UCameraComponent* Camera;
void Move(float Value);
};
And my Tank.cpp
#include "Tank.h"
#include "Camera/CameraComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/SpringArmComponent.h"
ATank::ATank()
{
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm for the Camera"));
if(!SpringArm) UE_LOG(LogTemp, Error, TEXT("ATank::ATank() SpringArm is a nullptr"));
SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
if(!Camera) UE_LOG(LogTemp, Error, TEXT("ATank::ATank() Camera is a nullptr"));
Camera->SetupAttachment(SpringArm);
}
// Called to bind functionality to input
void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
}
void ATank::Move(float Value)
{
UE_LOG(LogTemp, Warning, TEXT("MOVING FORWARD (or backward)! Value: %f"), Value);
}