Hello everyone, I am trying to create a battle royale game, for idle, walk and sprint, I am getting two errors in my C++ code,
pointer to incomplete class type “UCharacterMovementComponent” is not allowed
Here is the code of Onyx.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Onyx.generated.h"
UCLASS()
class MYBG_API AOnyx : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AOnyx();
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;
//Public Variables
//Define Input key for MoveForwardKey
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BR Variables")
FString MoveForwardKey;
//Define Input key for MoveRight
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BR Variables")
FString MoveRightKey;
//Define Input key for Turn
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BR Variables")
FString TurnKey;
//Define Input key for LookUp
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BR Variables")
FString LookUpKey;
//Define Input key for Sprint
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BR Variables")
FString SprintKey;
//Max Walk Speed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BR Variables")
float MaxWalkSpeed;
//Max Sprint Speed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BR Variables")
float MaxSprintSpeed;
protected:
void MoveForward(float AxisVal);
void MoveRight(float AxisVal);
void LookUp(float AxisVal);
void Turn(float AxisVal);
void Jump();
void Sprint();
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta = (AllowPrivateAccess = true))
bool bPlayerIsSprinting;
};
Here is the code for onyx.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Onyx.h"
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Onyx.generated.h"
// Sets default values
AOnyx::AOnyx()
{
// 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 AOnyx::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AOnyx::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AOnyx::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(FName(*MoveForwardKey), this, &AOnyx::MoveForward);
PlayerInputComponent->BindAxis(FName(*MoveRightKey), this, &AOnyx::MoveRight);
PlayerInputComponent->BindAxis(FName(*LookUpKey), this, &AOnyx::LookUp);
PlayerInputComponent->BindAxis(FName(*TurnKey), this, &AOnyx::Turn);
}
void AOnyx::MoveForward(float AxisVal)
{
AddMovementInput(GetActorForwardVector() * AxisVal);
}
void AOnyx::MoveRight(float AxisVal)
{
AddMovementInput(GetActorRightVector() * AxisVal);
}
void AOnyx::LookUp(float AxisVal)
{
}
void AOnyx::Turn(float AxisVal)
{
}
void AOnyx::Jump()
{
}
void AOnyx::Sprint()
{
UCharacterMovementComponent* MovementComponentPointer = Cast<UCharacterMovementComponent>(GetMovementComponent());
if (MovementComponentPointer)
{
if (!bPlayerIsSprinting)
{
bPlayerIsSprinting = false;
MovementComponentPointer->MaxWalkSpeed = MaxWalkSpeed;
}
else
{
bPlayerIsSprinting = true;
MovementComponentPointer->MaxWalkSpeed = MaxSprintSpeed;
}
}
}
Please help me how to deal with the error.