I created a UActorComponent called damage dealer that use one of its function to react when the actor is hit.
the actor I attach it to is a projectile and is spawned in the world.
I set the function to use in the constructor
UDamageDealerComponent::UDamageDealerComponent()
{
PrimaryComponentTick.bCanEverTick = true;
AActor* owner = GetOwner();
if (owner)
{
UPrimitiveComponent* collider = Cast<UPrimitiveComponent>(owner-GetDefaultSubobjectByName(*mColliderName));
if (collider)
{
collider->SetNotifyRigidBodyCollision(true);
collider->SetSimulatePhysics(true);
collider->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
collider->BodyInstance.SetCollisionProfileName("BlockAllDynamic");
collider->OnComponentHit.AddDynamic(this, &UDamageDealerComponent::OnHit);
}
}
}
but OnHit is never called when the projectiles hit (I did check the signature for the function).