Why isn't my Pawn moving?

I believe I implemented all the code needed for my Pawn to accept input and move. I have tried input with Keyboard/Mouse as well as Controller. Am I missing something?


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

#pragma once

#include "CoreMinimal.h"
#include "BasePawn.h"
#include "MainPlayer.generated.h"

class THIRDPERSONMOVEMENT_API AMainPlayer : public ABasePawn
	// Sets default values for this pawn's properties
	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
		// Called when the game starts or when spawned
		virtual void BeginPlay() override;

	UPROPERTY(VisibleAnywhere, Category = "Components")
	class USpringArmComponent* SpringArm;
	UPROPERTY(VisibleAnywhere, Category = "Components")
	class UCameraComponent* Camera;

	UPROPERTY(EditAnywhere, Category = "Movement")
	float RotationRate = 10.f;

	void MoveForward(float AxisValue);
	void MoveRight(float AxisValue);
	void LookUpRate(float AxisValue);
	void LookRightRate(float AxisValue);

	class APlayerController* MainPlayerController;


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

#include "MainPlayer.h"
#include "Camera/CameraComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/Character.h"
#include "GameFramework/PlayerController.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/GameplayStatics.h"

  // Setup SpringArm and Camera components
  SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));

  Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));


void AMainPlayer::BeginPlay() 

// Called to bind functionality to input
void AMainPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)

	// Mouse/KeyBoard Movement
	PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &AMainPlayer::MoveForward);
	PlayerInputComponent->BindAxis(TEXT("LookUp"), this, &APawn::AddControllerPitchInput);
	PlayerInputComponent->BindAxis(TEXT("MoveRight"), this, &AMainPlayer::MoveRight);
	PlayerInputComponent->BindAxis(TEXT("LookRight"), this, &APawn::AddControllerYawInput);
	// Controller
	PlayerInputComponent->BindAxis(TEXT("LookUpRate"), this, &AMainPlayer::LookUpRate);
	PlayerInputComponent->BindAxis(TEXT("LookRightRate"), this, &AMainPlayer::LookRightRate);

void AMainPlayer::MoveForward(float AxisValue) 
  AddMovementInput(GetActorForwardVector(), AxisValue);

void AMainPlayer::MoveRight(float AxisValue) 
  AddMovementInput(GetActorRightVector(), AxisValue);

void AMainPlayer::LookUpRate(float AxisValue) 
  AddControllerPitchInput(AxisValue * RotationRate * GetWorld()->GetDeltaSeconds());

void AMainPlayer::LookRightRate(float AxisValue) 
  AddControllerYawInput(AxisValue * RotationRate * GetWorld()->GetDeltaSeconds());

1 Like

I don’t know what ABasePawn is, but the implementation for APawn::AddMovementInput is as follows:

Are you sure that your pawn has a movement component?
Have you tried debugging this line to see if GetMovementComponent() returns a nullptr?

I apologize for the very late reply. I made a rookie mistake (I’m very new to game dev/c++) and made a class that inherited from my custom APawn class ‘BasePawn’ rather than create a class that inherits from ‘ACharacter’ lol. It was missing the movement component. I just created a new Character class, rewrote the Input code, and it worked!!
Thank you for your help!!

1 Like

No worries - I think you’ll find that these things happen more often than you’d like :joy:

Oh I feel like I’ve many so many mistakes in such a short time since I’ve started haha.
Can’t wait to become a lot more experienced!!

1 Like