Pointer to incomplete class is not allowed on UInputComponent pointer in class derived from ACharacter

I create my own class based on ACharacter however in my method responsible for setting up input Visual Studio 2017 highlight error:

void APlayerCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	// Movement
	PlayerInputComponent->BindAxis("MoveForward", this, &APlayerCharacter::MoveForward);

}

It highlight PlayerInputComponent with message: “Pointer to incomplete class is not allowed”

What cause this?

My class is based on AActor doesn’t it mean that InputComponent is included somewhere in it hierarchy? I am going through Rama Survival tutorial and his source codes:

https://github.com/tomlooman/EpicSurvivalGameSeries/blob/Section-1/SurvivalGame/Source/SurvivalGame/Private/SCharacter.cpp

There is no InputController include in his code.

This is output from building

1>D:\Dokumenty\Projects\Unreal Engine\RYFT\Source\RYFT\PlayerCharacter.cpp(48): error C2027: use of undefined type 'UCharacterMovementComponent'
1>C:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\Engine\Classes\GameFramework/Character.h(24): note: see declaration of 'UCharacterMovementComponent'
1>D:\Dokumenty\Projects\Unreal Engine\RYFT\Source\RYFT\PlayerCharacter.cpp(48): error C2227: left of '->IsMovingOnGround' must point to class/struct/union/generic type
1>D:\Dokumenty\Projects\Unreal Engine\RYFT\Source\RYFT\PlayerCharacter.cpp(48): error C2227: left of '->IsFalling' must point to class/struct/union/generic type
1>D:\Dokumenty\Projects\Unreal Engine\RYFT\Source\RYFT\PlayerCharacter.cpp(48): error C2789: 'bLimitRotation': an object of const-qualified type must be initialized
1>D:\Dokumenty\Projects\Unreal Engine\RYFT\Source\RYFT\PlayerCharacter.cpp(48): note: see declaration of 'bLimitRotation'
1>D:\Dokumenty\Projects\Unreal Engine\RYFT\Source\RYFT\PlayerCharacter.cpp(52): error C2065: 'Val': undeclared identifier
1>ERROR : UBT error : Failed to produce item: D:\Dokumenty\Projects\Unreal Engine\RYFT\Binaries\Win64\UE4Editor-RYFT.pdb

Yep it worked however PlayerInputController calls are still highlighted with message: “Pointer to incomplete class is not allowed on UInputComponent pointer”. Whats more, why removing “class” keyword fix it? According to this stackoverflow topic it should be valid in that case because we only indicating that that UInputController is a class.

It is strange…

class declares this as a new class what we want in case of a header file because we cant include the “original” there because otherwise it would casue circular dependency but in the cpp we dont want that because in an empty class (incomplete class) there is nothing we could reference to (and thats what throws the error); in the cpp file we want an reference to the actual class and in the cpp we can include it without causing circular dependency. I think this explains it as well.

Since you are in the .cpp file you do not declare forward with the “class” just leave it out. And of cource include InputComponent in the .cpp file.

Didnt look that up in code actually but did it work if you only removed the “class” what did it say then?

I know I’m not the OP, but I’m getting the same problem. I get that we need to include the original class, but what directory is the original class in? Following a video tutorial, it appears that the error isn’t thrown there, yet it is thrown here.

I noticed that everything included in my cpp and h files match his, albeit with more inclusions than what he has, and it still throws the same error.

It only makes me angrier when I notice how the line above it (Super::SetupPlayerInputComponent(PlayerInputComponent():wink: throws no errors yet the line below it (PlayerInputComponent->BindAxis(“MoveForward”, this, &AMyCharacter::MoveForward):wink: does throw an error.

Following up from my comment on EagleOwl’s answer, I found out exactly what needs to be done and why.

Add #include “Components/InputComponent.h” to the top of your file. Apparently UE4 encourages you to import only what you need by default, and then manually import everything else afterwards.

Answer Source: PlayerInputComponent - pointer to incomplete class type is not allowed - Programming & Scripting - Epic Developer Community Forums

1 Like