Compile Error

Hi I keep getting this compile error after I added particle effects to the PawnBase Parent Class. I dont quite understand what is wrong. My Code for PawnBase and the headers for the PawnTank and PawnTurret are included below.


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


#include "PawnBase.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);

	HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
}

void APawnBase::RotateTurret(FVector LookAtTarget)
{
	FVector LookAtTargetCleaned = FVector(LookAtTarget.X, LookAtTarget.Y, TurretMesh->GetComponentLocation().Z);
	FVector StartLocation = TurretMesh->GetComponentLocation();
	FRotator TurretRotation = FVector(LookAtTargetCleaned - 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

	UGameplayStatics::SpawnEmitterAtLocation(this, DeathParticle, GetActorLocation());

	//Then do child overrides
	// PawnTurret Inform GameMode Turret died -> then Destroy() self


	//PawnTank inform GameMode Player died -> then Hide() all components && stop movement input
}

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Components/SceneComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Particles/ParticleSystem.h"
#include "Kismet/GameplayStatics.h"
#include "ToonTanks/Components/HealthComponent.h"
#include "ToonTanks/Actors/ProjectileBase.h"
#include "PawnBase.generated.h"

class UCapsuleComponent;
class AProjectileBase;
class UHealthComponent;

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;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	UHealthComponent* HealthComponent;
	
	//Variables
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Projectile Type", meta = (AllowPrivateAccess = "true"))
	TSubclassOf<AProjectileBase> ProjectileClass;

	UPROPERTY(EditAnywhere, Category = "Effects")
	UParticleSystem* DeathParticle;

public:
	// Sets default values for this pawn's properties
	APawnBase();
	virtual void HandleDestruction();

protected:

void RotateTurret(FVector LookAtTarget);

void Fire();





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

#pragma once

#include "CoreMinimal.h"
#include "Pawns/PawnBase.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/Actor.h"
#include "GameFramework/PlayerController.h"
#include "Components/InputComponent.h"
#include "Math/Rotator.h"
#include "PawnTank.generated.h"

class USpringArmComponent;
class UCameraComponent;
class UHealthComponent;
class APawnBase;

UCLASS()
class TOONTANKS_API APawnTank : public APawnBase
{
	GENERATED_BODY()

private:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UCameraComponent* Camera;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
USpringArmComponent* SpringArm;

FVector MoveDirection;
FQuat RotationDirection;


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (AllowPrivateAccess = "true"))
float MoveSpeed = 500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (AllowPrivateAccess = "true"))
float RotateSpeed = 250.0f;

APlayerController* PlayerControllerRef;

void CalculateMoveInput(float Value);
void CalculateRotateInput(float Value);

void Move();
void Rotate();
bool bIsPlayerAlive = true;

public:

	APawnTank();

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

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

	virtual void HandleDestruction() override;

	bool GetIsPlayerAlive();

protected:
	virtual void BeginPlay() override;

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

#pragma once

#include "CoreMinimal.h"
#include "Pawns/PawnBase.h"
#include "Pawns/PawnTank.h"
#include "Engine/EngineTypes.h"
#include "Kismet/GameplayStatics.h"
#include "TimerManager.h"
#include "Engine/World.h"
#include "PawnTurret.generated.h"


class APawnTank;
class UHealthComponent;
class APawnBase;


UCLASS()
class TOONTANKS_API APawnTurret : public APawnBase
{
	GENERATED_BODY()

private:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat", meta = (AllowPrivateAccess = "true"))
	float FireRate = 2.0f;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat", meta = (AllowPrivateAccess = "true"))
	float FireRange = 500.0f;

	FTimerHandle FireRateTimerHandle;
	
	APawnTank* PlayerPawn;

	void CheckFireCondition();
	float ReturnDistanceToPlayer();

public:
	// Called every frame
	virtual void Tick(float DeltaTime) override;
	
	virtual void HandleDestruction() override;
protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	
};

Try rebuilding. With Unreal close do the following in VS Code

Ctrl + Shift + B > ProjectNameEditor Platform Development Reuild

Where ProjectName is the name of your project and Platform is the platform you’re targeting e.g. Win64

I tried that and got this message in the Visual Studio Code Terminal. It just kept saying building for hours on the bottom of the screen. I tried closing and and recompiling in unreal after that and i still got the same error.

You seem to have an issue with your PATH. Could you try repairing your Visual Studio installation through the Visual Studio Installer?

I added the PATH when i tried to instal Visual Studio Code with the Visual Studio Installer.
But i got the same thing when i tried to do the development build again.

I didn’t suggest you add it to your path. I was suggesting that there’s something wrong with it which is causing that ““C:\Program” is unrecognised…” message.

I recommended you try use the Visual Studio Installer to repair your Visual Studio installation in hopes that it repairs it as some people have managed. Did you do that?

No I didn’t. I’m trying to figure out what to do in visual studio installer to fix the issue. If you could tell me what to do in visual studio installer or send me a link it would be appreciated.

Hi @DanM .

I´m getting the same errors as @JhuttyBoys in his first post. I´ve tryed reparing visual studio and Unreal 4.26.2 as well; and also rebuilding the project, not just building it.

As a last desesperate try, I remove all the code added in the Spawning Particles lecture of the project Toon Tanks of this course (Unreal 4.22 C++ Developer, just in case). And it compiles again as before and everything works fine. So I think it must be something we add in this lecture.

The only diferece between the lecturer and @JhuttyBoys and me is that we both has added the header files includes in the header file of each class that needs it, instead of including it on the implementation file or cpp as the lecturer did. Can this cause such an error like this?

Unlikely as #include just copies and pastes the file.

Well, the problem seems to be at adding the Health Component to the PawnBase class.

This seems to throw the compile error:

// PawnBase.h
[...]
#include "ToonTanks/Components/HealthComponent.h"
[...]
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
    UHealthComponent* HealthComp;
[...]

// PawnBase.cpp
[...]
APawnBase::APawnBase()
{
    [...]
    HealthComp = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
}
[...]

But if we do exactly as the lecturer, it compiles fine XD:

// PawnBase.h
[...]
class UHealthComponent;
[...]
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
    UHealthComponent* HealthComp;
[...]

// PawnBase.cpp
[...]
#include "ToonTanks/Components/HealthComponent.h"
[...]
APawnBase::APawnBase()
{
    [...]
    HealthComp = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
}
[...]

So I think that must be the solution to our problem @JhuttyBoys

The only think I don´t understand it´s the exactly difference between include the header in the PawnBase.h or in the PawnBase.cpp (adding also the class UHealthComponent; declaration in the .h)

Oh right I think I mixed up this thread with the one I previously replied to but that is due to a circular dependency.

Do you have TankGameModeBase.h in HealthComponent.h and perhaps the tank and turret headers within the game mode header?

The issue can be demonstrated with the following

A.h:

#pragma once

#include "B.h"
class A
{
    B* b;
};

B.h:

#pragma once

#include "A.h"
class B
{
    A* a;
};

main.cpp:

#include "A.h"

int main() { }

Which means the file gets preprocessed as

class B // doesn't re-include "A.h" thanks to `#pragma once`
{
    A* a; // compilation error: compiler says what on earth is A?? 
};
class A
{
    B* b;
};

int main() {}

Using a forward declaration instead would mean the class A and B both get told that the other is a type before being used.

1 Like

Oh :scream: That´s the problem there!

Thank you so much :heart:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms