I want to add component event in c++

Hi I’m converting Blueprint to c++ and i got Some problem.

In Blueprint, I could call component event in actor easley but in c++ I dont know how to call it.

how can i call component event in c++ Actor that owns it?

Something like this?

Component cpp

void UHealthComponent::TakeDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser)
{
	OnHealthChanged.Broadcast(this, Health, Damage, DamageType, Instigator, DamageCauser);
...
}

actor .h

class Test_API ACharacterBase : public Acharacter
{
...
UFUNCTION()
	virtual void OnHealthChanged(UHealthComponent* OwningHealthComp,
 float Health, float HealthDelta, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser);
...
}

actor .cpp

void ACharacterBase::OnHealthChanged(UHealthComponent* OwningHealthComp, float Health, float HealthDelta, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser)
{
	...
}

and actor.cpp
in begin play

HealthComponent->OnHealthChanged.AddDynamic(this, &ACharacterBase::OnHealthChanged);

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