RealDocs

AActor::NotifyHit

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: virtualENGINE_API

Description

Called when this actor bumps into a blocking object or is bumped into. Covers both movement-sweep hits and physics collision hits. For non-blocking overlaps, use NotifyActorBeginOverlap instead.

Caveats & Gotchas

  • For physics simulation hits to trigger this, 'Simulation Generates Hit Events' must be enabled on the primitive component. Without it, physics collisions are silent.
  • When bSelfMoved is false (the other object moved into you), HitNormal and Hit.ImpactNormal are adjusted to point from the other object's perspective. This can be counterintuitive — the normal points toward the other object, not away from your surface.
  • NormalImpulse is zero for kinematic (non-simulating) sweep hits, even if a large force was applied. Only rely on it when both actors are simulating physics.

Signature

ENGINE_API virtual void NotifyHit(class UPrimitiveComponent* MyComp, AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit);

Parameters

Name Type Description Default
MyComp class UPrimitiveComponent* The component on this actor that was hit.
Other AActor* The other actor involved in the collision.
OtherComp class UPrimitiveComponent* The component on the other actor that was hit.
bSelfMoved bool True if this actor's movement caused the hit; false if the other actor moved into this one.
HitLocation FVector World location of the hit point.
HitNormal FVector Normal at the hit point, pointing away from the hit surface.
NormalImpulse FVector Impulse applied at the hit point. Only non-zero for physics-simulating bodies; zero for swept blocking collisions.
Hit const FHitResult& Full hit result data including bone name, face index, and trace information.

Return Type

void

Example

Override to apply damage on physics hit C++
void AMyProjectile::NotifyHit(
	UPrimitiveComponent* MyComp, AActor* Other, UPrimitiveComponent* OtherComp,
	bool bSelfMoved, FVector HitLocation, FVector HitNormal,
	FVector NormalImpulse, const FHitResult& Hit)
{
	Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved,
		HitLocation, HitNormal, NormalImpulse, Hit);
	if (Other)
	{
		UGameplayStatics::ApplyPointDamage(
			Other, Damage, GetVelocity().GetSafeNormal(),
			Hit, GetInstigatorController(), this, DamageType);
	}
	Destroy();
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.