"Pointer to incomplete class type is not allowed"

.h file includes:

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "PTZRCharacter.h"
#include "PTZRPortal.generated.h"

.cpp file function snippet:

void APTZRPortal::TeleportActor(AActor* ActorToTeleport)
	if (ActorToTeleport == nullptr || Target == nullptr)

	//Retrieve and save Player Velocity
	//(from the Movement Component)
	FVector SavedVelocity = FVector::ZeroVector;
	APTZRCharacter* EC = nullptr;

	if (ActorToTeleport->IsA(APTZRCharacter::StaticClass()))
		EC = Cast<APTZRCharacter>(ActorToTeleport);

		SavedVelocity = EC->GetCharacterMovement()->Velocity;

Above is part of my code and the problem I am having is that VS is underlining the “EC” variable in the “SavedVelocity” definiton (last line) in red, telling me that “Pointer to incomplete class type is not allowed”. I am quite new to C++ in Unreal and I have no idea why I am getting this error. I have searched around on Google for this issue and all the answers basically tell them that they forgot to include a certain engine component. However I can’t think of what I could have possibly forgotten to include here. “EC” here is just a pointer to the “PTZRCharacter” class (a custom character class I made) and I have indeed included the header file of that class in my header file.

I can’t possibly think of anything else I need to include. Any ideas?

Can it compile?

@GarnerP57 Nope, it doesn’t compile.

Normally when declaring a class variable in a header file it is done by what is known as “Forward Declaration”.


#pragma once

#include "CoreMinimal.h"

class ADifferentActor; //Forward declaration of ADifferentActor

class AMyActor : public AActor
	ADifferentActor* MyDifferentActorPointer ;


#include "MyActor.h"
#include "ADifferentActor.h" //Completed Declaration of ADifferentActor
//Now when you have Set MyDifferentActorPointer to point at an instance of ADifferentActor you can begin to use the functions in it

So make sure that you completed the declaration and not only made a forward declaration to the APTZRCharacter class.
You always want to include as few things as possible in a header file so it is lighter when other classes need to include it. When declaring a pointer variable it doesn’t need to know what the class consist of and can be handled as any other generic pointer UNTIL you want to use the type the pointer points to.

Ah, thanks! It worked.