Download

Projectile OnHit Function

Hey, I am running in to a type of bug I think. Not sure what’s going on here but my OnHit function in my game is giving unexpected results. When the enemies shoot me, my player pawn takes the damage. But when I shoot the enemy the OnHit is not registered. I will include the snippet of my code, not sure what I am doing wrong here. I have the same collision settings on both Actors. Actors do generate Overlaps when the projectile hits them but the OnHit function isn’t called.



void AProjectile::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit)
{
	Blast->Deactivate();
	Impact->Activate();
	Force->FireImpulse();

	SetRootComponent(Blast);
	CollisionMesh->DestroyComponent();

	FTimerHandle Timer;

	UGameplayStatics::ApplyRadialDamage(
		this,
		Damage,
		OtherActor->GetActorLocation(),
		Force->Radius, //Bound together for consistency
		UDamageType::StaticClass(),
		TArray<AActor*>() //Damage all actors
	);


	UE_LOG(LogTemp, Error, TEXT("I hit ->%s"), *(OtherActor->GetName()));
	//GetWorld()->GetTimerManager().SetTimer(Timer, this, &AProjectile::OnTimerExpire, DestroyTime, false);
	//GetWorldTimerManager().SetTimer(Timer, this, &AProjectile::OnTimerExpire, DestroyTime, false);
}


EDIT:
Looks like only the Projectile Blueprint class for the Enemy was working. So I had to duplicate it, make the needed changes and delete the old ones. But now everything is working as intended. This is the second time in Unreal I had to delete the Blueprint of a parent C++ class and recreate it to get it working as intended. Is this a caching issue?

I’ve had this happen to me as well with overlaps through C++, where the overlap simply wouldn’t run unless I completely removed the class and remade it. Only twice in 1-2 years though.

I’ve had it happen twice to me on the same project. The other case was I had a blueprint derivative of a C++ class auto destroying itself. No code in the C++ had a destroy call and I cleared the entire event graph and the object was still being destroyed. But when I created a new blueprint based on the same C++ class it was working fine.