I can’t seem to figure out why the compiler is telling me ACharacter is undefined from this line:
PlayerControllerRef = Cast<APlayerControllerBase>(UGameplayStatics::GetPlayerCharacter(this, 0));
Specifically in this context:
#include "TankGameModeBase.h"
#include "ToonTanks/Pawns/PawnTank.h"
#include "ToonTanks/Pawns/PawnTurret.h"
#include "Kismet/GameplayStatics.h"
#include "ToonTanks/PlayerControllers/PlayerControllerBase.h"
// -------------------------------------------------------------------------------------------
void ATankGameModeBase::BeginPlay()
{
Super::BeginPlay();
HandleGameStart();
}
// ...
void ATankGameModeBase::HandleGameStart()
{
UpdateTurretsAlive();
PlayerTank = Cast<APawnTank>(UGameplayStatics::GetPlayerPawn(this, 0));
PlayerControllerRef = Cast<APlayerControllerBase>(UGameplayStatics::GetPlayerCharacter(this, 0)); // C2027 undefined type 'ACharacter' from GetPlayerCharacter.
GameStart();
// To make sure the player can't move during countdown.
if (PlayerControllerRef) {
PlayerControllerRef->SetPlayerEnabledState(false);
FTimerHandle PlayerEnableHandle;
// TODO: I don't understand this at all.
FTimerDelegate PlayerEnableDelegate = FTimerDelegate::CreateUObject(
PlayerControllerRef,
&APlayerControllerBase::SetPlayerEnabledState,
true
);
GetWorld()->GetTimerManager().SetTimer(
PlayerEnableHandle,
PlayerEnableDelegate,
StartDelay,
false);
}
}
Header:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "ToonTanks/PlayerControllers/PlayerControllerBase.h"
#include "TankGameModeBase.generated.h"
// -------------------------------------------------------------------------------------------
// Forward declarations.
class APawnTurret;
class APawnTank;
// -------------------------------------------------------------------------------------------
UCLASS()
class TOONTANKS_API ATankGameModeBase : public AGameModeBase
{
GENERATED_BODY()
public:
void ActorDied(AActor* DeadActor);
private:
UPROPERTY()
APawnTank* PlayerTank;
UPROPERTY()
TArray<AActor*> Turrets;
UPROPERTY()
APlayerControllerBase* PlayerControllerRef;
void HandleGameStart();
void HandleGameOver(bool PlayerWon);
void UpdateTurretsAlive();
protected:
virtual void BeginPlay() override;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Game Loop")
int32 StartDelay = 3;
// The following UFUNCTIONs mean we'll be able to implement these functions in Blueprints.
// Certain things like setting timers and creating widgets are much faster and easier in BP.
UFUNCTION(BlueprintImplementableEvent)
void GameStart();
UFUNCTION(BlueprintImplementableEvent)
void GameOver(bool PlayerWon);
};
Full log is:
PointerIsConvertibleFromTo.h(19): [C2027] use of undefined type 'ACharacter'
GameplayStatics.generated.h(55): see declaration of 'ACharacter'
PointerIsConvertibleFromTo.h(60): see reference to class template instantiation 'UE4PointerIsConvertibleFromTo_Private::TImpl<From,To,ACharacter,UObject>' being compiled
Casts.h(93): see reference to class template instantiation 'TPointerIsConvertibleFromTo<T,volatile const UObject>' being compiled
TankGameModeBase.cpp(61): see reference to function template instantiation 'To *Cast<APlayerControllerBase,ACharacter>(From *)' being compiled
PointerIsConvertibleFromTo.h(19): [C2338] TPointerIsConvertibleFromTo must not be instantiated with incomplete types
Casts.h(93): [C2976] 'TIsIInterface': too few template arguments
Casts.h(40): see declaration of 'TIsIInterface'
Casts.h(111): [C2976] 'TGetCastType': too few template arguments
Casts.h(95): see declaration of 'TGetCastType'
Casts.h(219): [C2976] 'TCastImpl': too few template arguments
Casts.h(113): see declaration of 'TCastImpl'
Casts.h(219): [C2665] 'TCastImpl<From,To,ECastType::UObjectToUObject>::DoCast': none of the 2 overloads could convert all the argument types
Casts.h(152): could be 'To *TCastImpl<From,To,ECastType::UObjectToUObject>::DoCast(FField *)'
Casts.h(141): or 'To *TCastImpl<From,To,ECastType::UObjectToUObject>::DoCast(UObject *)'
Casts.h(219): while trying to match the argument list '(From *)'