I am getting these errors
c:\users\engelsflm\documents\unreal projects\toontanks\source\toontanks\pawns\PawnBase.h(30) : error C2065: 'AProjectileBase': undeclared identifier
c:\users\engelsflm\documents\unreal projects\toontanks\source\toontanks\pawns\PawnBase.h(30) : error C2923: 'TSubclassOf': 'AProjectileBase' is not a valid template type argument for parameter 'TClass'
[2/10] PawnTank.cpp
And I could solve them when I add the following include:
#include "ToonTanks/Actors/ProjectileBase.h"
To the includes of PawnBase.h, but this include is not done in the course.
I do not get it?
Here is my code:
PawnBase.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "ToonTanks/Actors/ProjectileBase.h"
#include "PawnBase.generated.h"
class UCapsuleComponent;
class ProjectileBase;
UCLASS()
class TOONTANKS_API APawnBase : public APawn
{
GENERATED_BODY()
private:
//COMPONENTS
UPROPERTY(VisibleAnywhere,BluePrintReadOnly, Category = "Components",meta = (AllowPrivateAccess = "true"))
UCapsuleComponent* CapsuleComp;
UPROPERTY(VisibleAnywhere,BluePrintReadOnly, Category = "Components",meta = (AllowPrivateAccess = "true"))
UStaticMeshComponent* BaseMesh;
UPROPERTY(VisibleAnywhere,BluePrintReadOnly, Category = "Components",meta = (AllowPrivateAccess = "true"))
UStaticMeshComponent* TurretMesh;
UPROPERTY(VisibleAnywhere,BluePrintReadOnly, Category = "Components",meta = (AllowPrivateAccess = "true"))
USceneComponent* ProjectileSpawnPoint;
//VARIABLES
UPROPERTY(EditAnywhere, BluePrintReadOnly,Category = "Projectile type",meta = (AllowPrivateAccess = "true"))
TSubclassOf<AProjectileBase> ProjectileClass;
public:
// Sets default values for this pawn's properties
APawnBase();
protected:
void RotateTurret(FVector LookAtTarget);
void Fire();
virtual void HandleDestruction();
};
PawnBase.cpp
#include "PawnBase.h"
#include "Components/CapsuleComponent.h"
#include "ToonTanks/Actors/ProjectileBase.h"
// Sets default values
APawnBase::APawnBase()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule Collider"));
RootComponent = CapsuleComp;
BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Base Mesh"));
BaseMesh->SetupAttachment(RootComponent);
TurretMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Turret Mesh"));
TurretMesh->SetupAttachment(BaseMesh);
ProjectileSpawnPoint = CreateDefaultSubobject<USceneComponent>(TEXT("Projectile Spawn Point"));
ProjectileSpawnPoint->SetupAttachment(TurretMesh);
}
void APawnBase::RotateTurret(FVector LookAtTarget)
{
FVector LookAtTargetClean = FVector(LookAtTarget.X,LookAtTarget.Y,TurretMesh->GetComponentLocation().Z);
FVector StartLocation = TurretMesh->GetComponentLocation();
FRotator TurretRotation =FVector(LookAtTargetClean - StartLocation).Rotation();
TurretMesh ->SetWorldRotation(TurretRotation);
}
void APawnBase::Fire()
{
if (ProjectileClass)
{
FVector SpawnLocation = ProjectileSpawnPoint->GetComponentLocation();
FRotator SpawnRotation = ProjectileSpawnPoint->GetComponentRotation();
AProjectileBase* TempProjectile = GetWorld()->SpawnActor<AProjectileBase>(ProjectileClass, SpawnLocation,SpawnRotation );
TempProjectile->SetOwner(this);
}
}
void APawnBase::HandleDestruction()
{
// --- Universal functionality ---
// Play death effects particle, sound and camera shake.
// --- Then do Child overrides ---
// -- PawnTurret - Inform GameMode Turret died -> Then Destroy() self.
// -- PawnTank - Inform GameMode Player died -> Then Hide() all components && stop movement input.
}
ProjectileBase.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ProjectileBase.generated.h"
class UProjectileMovementComponent;
UCLASS()
class TOONTANKS_API AProjectileBase : public AActor
{
GENERATED_BODY()
private:
UPROPERTY(VisibleAnywhere, BluePrintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UProjectileMovementComponent* ProjectileMovement;
UPROPERTY(VisibleAnywhere,BluePrintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UStaticMeshComponent* ProjectileMesh;
UPROPERTY(EditDefaultsOnly, Category = "Damage")
TSubclassOf<UDamageType> DamageType;
UPROPERTY(EditAnywhere,BluePrintReadOnly, Category = "Move", meta = (AllowPrivateAccess = "true"))
float MovementSpeed = 1300.f;
UPROPERTY(EditAnywhere,BluePrintReadOnly, Category = "Damage", meta = (AllowPrivateAccess = "true"))
float Damage = 50;
public:
// Sets default values for this actor's properties
AProjectileBase();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};
ProjectileBase.cpp
#include "ProjectileBase.h"
#include "Components/StaticMeshComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
// Sets default values
AProjectileBase::AProjectileBase()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Projectile Mesh"));
RootComponent = ProjectileMesh;
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Projectile Movement"));
ProjectileMovement->InitialSpeed = MovementSpeed;
ProjectileMovement-> MaxSpeed = MovementSpeed;
InitialLifeSpan = 3.0f;
}
// Called when the game starts or when spawned
void AProjectileBase::BeginPlay()
{
Super::BeginPlay();
}