Character Class not working

Hello,

I am having real trouble getting the FPSCharacter class from the FPS C++ programming tutorial to work. Here’s the code:

FirstPersonGameModeBase.cpp

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

#include "FirstPersonCGameModeBase.h"

void AFirstPersonCGameModeBase::StartPlay() {

	Super::StartPlay();

	if (GEngine) {

		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("First Person Game Mode Base Running..."));
	}
}

FPSCharatcer.h

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Engine.h"
#include "FPSCharacter.generated.h"

UCLASS()
class FIRSTPERSONC_API AFPSCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	AFPSCharacter();

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 MoveX (float axisValue);

	UFUNCTION ()
		void MoveY (float axisValue);

	
	
};

FPSCharacter.cpp

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

#include "FPSCharacter.h"


// Sets default values
AFPSCharacter::AFPSCharacter()
{
 	// Set this character 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 AFPSCharacter::BeginPlay()
{
	Super::BeginPlay();

	if (GEngine) {

		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Orange, TEXT("FPSCharacter is on."));
	}
}


// Called every frame
void AFPSCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AFPSCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis("moveX", this, &AFPSCharacter::MoveX);
	PlayerInputComponent->BindAxis("moveY", this, &AFPSCharatcer::MoveY);

}


void MoveX(float axisValue) {

	FVector direction = FRotationMatrix(Controller->GetControlRotation().GetScaledAxis(EAxis::X));
	AddMovementInput(direction, axisValue);

}

void MoveY(float axisValue) {

	FVector direction = FRotationMatrix(Controller->GetControlRotation().GetScaledAxis(EAxis::Y));
	AddMovementInput(direction, axisValue);
}

I have set the BP_FPSCharacter in the Game Mode as the default pawn class but it doesn’t do ANYTHING whatsoever and these are some of the error messages I’m getting:

  • D:\UnrealProjects\FirstPersonC\Source\FirstPersonC\FPSCharacter.cpp(39)
    : error C2653: ‘AFPSCharatcer’: is
    not a class or namespace name

  • ERROR: UBT ERROR: Failed to produce
    item:
    D:\UnrealProjects\FirstPersonC\Binaries\Win64\UE4Editor-
    FirstPersonC-6063.dll

Any kind of help would be appreciated. Thank you. :smiley:

Hi,

It seems like you are missing the namespace from your MoveX and MoveY functions in FPSCharacter.cpp

It should be like this :

void AFPSCharacter::MoveX(float axisValue) {
 
     FVector direction = FRotationMatrix(Controller->GetControlRotation().GetScaledAxis(EAxis::X));
     AddMovementInput(direction, axisValue);
 
 }
 
 void AFPSCharacter::MoveY(float axisValue) {
 
     FVector direction = FRotationMatrix(Controller->GetControlRotation().GetScaledAxis(EAxis::Y));
     AddMovementInput(direction, axisValue);
 }

Hey, thank you very much this seems to have fixed the errors but I have one more issue. In the BeginPlay () function the GEngine->AddOnScreenDebugMessage () function doesn’t seem to be working. I have included the “Engine.h” library, any ideas? :smiley: