I have looked at all the most common answers of how to setup to use OnActorHit and tried all of them. I can’t seem to get OnActorHit to fire off correctly. I don’t get any errors with adding a delegate through the .Add function or using the .AddDynamic function. However, I have been following this tutorial where he uses Event Begin Overlap in a Blueprint and set the Collision Preset to Trigger. I was able to replicate that functionality in C++. However, I decided I want to use OnActorHit instead of overlapping. I can’t seem to get OnActorHit to work but I can get OnActorBeginOverlap. Does anyone know enough about OnActorHit as to why this happens? Here is my code below that I have tried for attempting to use OnActorHit.
APongActor Constructor
APongActor::APongActor()
{
...
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("RootComponent"));
RootComponent = BoxComponent;
BoxComponent->InitBoxExtent(FVector(100.0f, 100.0f, 100.0f));
BoxComponent->SetCollisionProfileName(TEXT("PhysicsActor"));
...
BoxComponent->SetSimulatePhysics(true);
BoxComponent->SetEnableGravity(false);
BoxComponent->SetNotifyRigidBodyCollision(true);
FScriptDelegate Delegate;
Delegate.BindUFunction(this, "OnPongActorHit");
OnActorHit.Add(Delegate);
}
My Hit Function:
void APongActor::OnPongActorHit() {
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, "OnHit() called");
...
}
Header file declaration:
UFUNCTION()
void OnPongActorHit();
I tried the Add Dynamic function too, but couldn’t get it too work
.H FILE
UFUNCTION(AActor * SelfActor, AActor * OtherActor, FVector NormalImpulse, struct FHitResult Hit)
void OnPongActorHit();
.CPP FILE
APongActor::APongActor() {
... code ...
OnActorHit.AddDynamic(this, &APongActor::OnPongActorHit);
}
APongActor::OnPongActorHit(AActor * SelfActor, class AActor * OtherActor, FVector NormalImpulse, struct FHitResult Hit)
{ ... code ... }