How to change parent class of a C++ class?

Hello! After a decent time of coding the systems I realised a horrible mistake. My BaseEnemy class has derived from Actor instead of Pawn. And now when I try to use AddMovementInput with a FloatingPawnMovement it doesn’t move. Beyond the movement mechanics, I tried solely using AddMovementInput and it does not work, no movement (no errors or anything).

I think that’s because of my class derived from Actor. I tried to simply change it to Pawn as AEnemyBase : public APawn but it seems that didn’t change anything. I think this could be about the background processes of creating a class, .generated.h etc. . So how can I properly change the base class?

Floating movement will fail with an actor as both SetUpdatedComponent and AddMovementInput do internal checks via casting or calling Internal_AddMovementInput on the owner.

They will fail during the update of the movement causing the character to stay immobile.

Just change your class definition from

class YOUR_API ABaseEnemy : public AActor{

// code here

}

to

class YOUR_API ABaseEnemy : public APawn{

// code here

}

and be sure to include

include “GameFramework/Pawn.h” in place of the Actor.h file

This base class works fine

.h



#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "BaseEnemy.generated.h"

class UFloatingPawnMovement;

UCLASS()
class YOUR_API ABaseEnemy : public APawn
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ABaseEnemy();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(BlueprintReadWrite,EditAnywhere)
	UFloatingPawnMovement*  FloatingMovement;


	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	UStaticMeshComponent* Mesh;

};

.cpp

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


#include "BaseEnemy.h"
#include "GameFramework/FloatingPawnMovement.h"


// Sets default values
ABaseEnemy::ABaseEnemy()
{

	PrimaryActorTick.bCanEverTick = true;
	FloatingMovement = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("Floating Movement"));
	Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
	FloatingMovement->SetUpdatedComponent(Mesh);
}

// Called when the game starts or when spawned
void ABaseEnemy::BeginPlay()
{
	Super::BeginPlay();
	
}

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

}