Why is OnActorHit not calling my function?

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

	BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("RootComponent"));
	RootComponent = BoxComponent;
	BoxComponent->InitBoxExtent(FVector(100.0f, 100.0f, 100.0f));

	FScriptDelegate Delegate;
	Delegate.BindUFunction(this, "OnPongActorHit");

My Hit Function:

void APongActor::OnPongActorHit() {
	GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, "OnHit() called");

Header file declaration:

		void OnPongActorHit();

I tried the Add Dynamic function too, but couldn’t get it too work


UFUNCTION(AActor * SelfActor, AActor * OtherActor, FVector NormalImpulse, struct FHitResult Hit)
		void OnPongActorHit();


APongActor::APongActor() {
... code ...
OnActorHit.AddDynamic(this, &APongActor::OnPongActorHit);

APongActor::OnPongActorHit(AActor * SelfActor, class AActor * OtherActor, FVector NormalImpulse, struct FHitResult Hit)
{ ... code ... }

The collision is likely set to ECollisionEnabled::QueryOnly. In your constructor, try setting it to ECollisionEnabled::PhysicsOnly or ECollisionEnabled::QueryAndPhysics. To do this:




Here is a link to ECollisionEnabled::Type

Either that or you may not have your collision response setup correctly. Here is a link to that: Collision Response Reference.

Ok then i repost it, you said overlap worked for you so i was scared that i might be wrong and deleted my anwser, sorry:

Don’t bind in constructor, what you actully did is binding of class default object (CDO) to event. Everything you do in constructor in UObject based class is used exclusivly to create master copy of object of specific class (previuesly mentioned CDO), thats why if you do something wrong in constructor it crashes engine on start when CDO is created, not where object is spawned. Insted of constructor use BeginPlay() event (or PostInitProperties() in non-Actor UObjects), you are 100% sure at that point that your actor is ready to go. In constructor you only set default varables and setup components, everything related to your class not future object that gonna be created from it.

Okay wait nevermind, my editor was not updating correctly to my code changes.

I am back to the scenario where only OnComponentBeginOverlap works in the constructor and the collision profile name is Trigger.

Sorry I was mistaken, i am back to only having OnActorBeginOverlap bind to my function in the constructor.

After some research, I was able to use this in my constructor. In fact using this in the constructor is the only recommended way I found that actually works.

BoxComponent->OnComponentHit.AddDynamic(this, &APongActor::OnPongActorHit);