RealDocs

UPrimitiveComponent::OnComponentHit

property Engine Blueprint Since unknown
#include "Components/PrimitiveComponent.h"
Access: public Specifiers: UPROPERTYBlueprintAssignable

Description

Delegate fired when this component physically hits another. Only fires when physics simulation is active or when the component is moved with bSweep=true and encounters a blocking hit.

Signature

FComponentHitSignature OnComponentHit

Parameters

Name Type Description Default
HitComponent UPrimitiveComponent* This component.
OtherActor AActor* The actor that was hit.
OtherComp UPrimitiveComponent* The component on the other actor that was hit.
NormalImpulse FVector Impulse applied at the hit point. Zero if simulation is disabled.
Hit const FHitResult& Full hit result with location, normal, and surface material.

Caveats & Gotchas

  • Only fires for blocking collisions, not overlaps. Use OnComponentBeginOverlap for overlap events.
  • Requires simulation or swept movement to produce hit events. A component moved via SetWorldLocation(NewLoc) without bSweep=true will not fire this event.
  • NormalImpulse is zero when the component is not simulating physics. For gameplay damage from hits, use AActor::TakeDamage triggered from the hit callback.

Example

Bind hit in BeginPlay and handle explosion C++
void AMyProjectile::BeginPlay()
{
	Super::BeginPlay();
	CollisionComponent->OnComponentHit.AddDynamic(this, &AMyProjectile::OnHit);
}

void AMyProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor,
	UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	UGameplayStatics::ApplyRadialDamage(this, 100.0f, GetActorLocation(), 300.0f,
		UDamageType::StaticClass(), {}, this);
	Destroy();
}

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.