Hello everyone, I am having trouble implementing Health Component in c++.
I am confused as to when I use GEngine the HP of the enemy is udpated. But when I called the Health Stat from the HpComp C++ in the Blueprint, It doesn’t seem to update. I don’t know where I am lacking.
This is from the HpComponent header file
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float Health;
UFUNCTION(BlueprintCallable)
float GetHealth() const;
UFUNCTION(BlueprintCallable)
void SetHealth(float NewHealth);
And this is the CPP File, it somehow shows the expected HP when I run the game.
float UHPComp::GetHealth() const
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Purple, FString::Printf(TEXT(“New Enemy health: %f”), Health));
return Health;
}
void UHPComp::SetHealth(float NewHealth)
{
Health = NewHealth;
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Cyan, FString::Printf(TEXT("New Enemy health: %f"), Health));
Health = GetHealth();
}
In Blueprint, I attached the HpComponent on the enemy. And I tried to call it in Begin Play.
Like this,
HpComp->Health->PrintString.
As you can see, it is updating in C++ but when I called it in Blueprint, it is not.
I hope you can all help me. I am new to C++ in Unreal.
Thank you in advance.