Actor NotifyHit

i have a simple melee weapon c++ actor with a SkeletalMeshComponent that is set up in a blueprint deriving from the AWeapon C++ class.

void AWeapon::NotifyHit(UPrimitiveComponent* MyComp, AActor* Other, UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit)
{
	GEngine->AddOnScreenDebugMessage(-1, 1.5f, FColor::Blue, FString("hit"));
}

The weapon actor has simulate physics OFF while equipped and attached to the player and ON when its on the ground waiting to be picked up. The weapon actor is then attached to the player actor and WeaponMesh->SetSimulatePhysics(false); is called to prevent the weapon from flying out of the players hand.
This works great for when i hit (play a swinging animation) objects that have ‘simulate physics’ enabled, for example can hit a block with a shovel and it flys in correct direction. however i get no notifications for static objects with collision but not ‘simulate physics’ checked (like walls for example).

How could i detect hits on static objects with NotifyHit as well?

Also what is the difference between WeaponMesh->OnComponentHit.AddDynamic(this, &AWeapon::OnHit); vs overriding the actors notifyhit ? I saw the sample projectile uses OnComponentHit but that is also not triggering an event for me on static walls like it does with the projectile example

Hi,

Hit events are triggered between dynamic and kinematic/static objects ( like your block/shovel example ), however pairs of kinematic/static will not generate such events
For those cases you need to look at the overlap event to detect when those object overlap each other

Hope this helps

Cedric

1 Like

This worked perfectly thank you.

Just had to set my skeletalmesh component of the weapon to overlap worldstatic objects and then the OnComponentBeginOverlap event was firing right when i need it to!

Thanks again

1 Like