Error Failed import for HealthComponent /Game/FirstPerson/Blueprints/FirstPersonCharacter.Default__FirstPersonCharacter_C:HealthComp
I get this every time I add my HealthComp.
#pragma once
#include "Components/ActorComponent.h"
#include "HealthComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class SHOOTER_API UHealthComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UHealthComponent();
UPROPERTY(Replicated, VisibleAnywhere)
float Health;
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
void SetHealth(float NewHealth);
// Called when the game starts
virtual void InitializeComponent() override;
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Shooter.h"
#include "Net/UnrealNetwork.h"
#include "HealthComponent.h"
#include "UnrealMathUtility.h"
// 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.
bWantsInitializeComponent = true;
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UHealthComponent::InitializeComponent()
{
Super::InitializeComponent();
// ...
}
// Called every frame
void UHealthComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
{
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
}
void UHealthComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UHealthComponent,Health);
}
void UHealthComponent::SetHealth(float NewHealth)
{
Health = FMath::Max<float>(NewHealth,0);
}
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Health)
class UHealthComponent* HealthComponent;
...
AShooterCharacter::AShooterCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
...
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("HealthComp"));
HealthComponent->SetHealth(100);
}
Everything seems to work so far though. Does anyone know why this happens and how I can fix this?