Cannot open include file: 'HealthComponent.generated.h':

I have been following the tutorial closely. I have no idea what happened or how to handle this error upon compiling. :

D:\Epic Games\UE_4.26\Unreal Training\ToonTanks\Source\ToonTanks\Components\HealthComponent.h(7): fatal error C1083: Cannot open include file: ‘HealthComponent.generated.h’: No such file or directory

I tried hitting Ctrl Shift + B to do a clean build and I get an error message for that.

Additional here is the header and code for the healtrh component. :

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


#include "HealthComponent.h"
#include "ToonTanks/GameModes/TankGameModeBase.h"
#include "Kismet/GameplayStatistics"

// Sets default values for this component's properties
UHealthComponent::UHealthComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = false;

	// ...
}


// Called when the game starts
void UHealthComponent::BeginPlay()
{
	Super::BeginPlay();

	// ...
	Health = DefaultHealth;
	GameModRef = Cast<ATankGameModeBase>(UGameplayStatics::GetGameMode(GetWorld()));
	GetOwner()->OnTakeAnyDamage.AddDynamic(this, &UHealthComponent::TakeDamage);
	
}

void UHealthComponent::TakeDamage(AActor * DamagedActor, float Damage, const UDamageType* DamageType, AController* InstigatedBy, AActor* DamageCauser) 
{
	if(Damage == 0)
	{
		return;
	}

	Health = FMath::Clamp(Health - Damage, 0.0f,DefaultHealth);

	if(Health <= 0)
	{
		if(GameModeRef)
		{
			GameModeRef->ActorDied(GetOwner());
		}
		else
		{
			UE_LOG(LogTemp, Warning,TEXT("Health Component has no referenece to the game mode please check"));
		}
	}
}

And Header:

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

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "HealthComponent.generated.h"

class ATankGameModeBase

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TOONTANKS_API UHealthComponent : public UActorComponent
{
	GENERATED_BODY()

private:
UPROPERTY(EditAnywhere)
 float DefaultHealth = 100.0f;

 float Health = 0.0f;

 ATankGameModeBase* GameModeRef;


public:	
	// Sets default values for this component's properties
	UHealthComponent();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;
	UFUNCTION()
	void TakeDamage(AActor * DamagedActor, float Damage, const UDamageType* DamageType, AController* InstigatedBy, AActor* DamageCauser);

		
};

You’re missing a semicolon in the header here

class ATankGameModeBase

Thanks!

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

Privacy & Terms