Lecture 144 Handling Input: Input is never called, as far as I can tell

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);
}

Now I’m noticing that I don’t even enter the ATank constructor.

Phew, it’s working now.

So apparently what I had to do was to make my instance of the tank into a BasePawn again, compile, then make it a Tank again.

Maybe it can help others who bump against the same issue.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms