I was following this tutorial 2. Displaying Health, Energy and Ammo | Unreal Engine Documentation and I got stuck when trying to access my health component.
I added the Health Component to the character’s blueprint. I opened my UI and accessed the character, but I cant find the Health Component after casting to my player controller.
Here is my health component.h:
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class WHYME_API UHealthComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UHealthComponent();
UFUNCTION(BlueprintPure, Category = "Health")
FORCEINLINE float GetMaxHealth() const { return _maxHealth; }
UFUNCTION(BlueprintPure, Category = "Health")
FORCEINLINE float GetCurrentHealth() const { return _currentHealth; }
/** Setter for Current Health. Clamps the value between 0 and MaxHealth and calls OnHealthUpdate. Should only be called on the server.*/
UFUNCTION(BlueprintCallable, Category = "Health")
void SetCurrentHealth(float health);
UFUNCTION()
void Delegate_OnTakeAnyDamage(AActor* DamagedActor, float Damage, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser);
protected:
// Called when the game starts
virtual void BeginPlay() override;
UPROPERTY(EditDefaultsOnly, Category = "Health")
float _maxHealth;
UPROPERTY(ReplicatedUsing = OnRep_CurrentHealth)
float _currentHealth;
UFUNCTION()
void OnRep_CurrentHealth();
/** Response to health being updated. Called on the server immediately after modification, and on clients in response to a RepNotify*/
void OnHealthUpdate();
};