Hit Events not firing

Hey!
I can’t seem to get the hit events to fire doing the exact same code as displayed in the session:

In Projectile.cpp:

void AProjectile::BeginPlay()
{
	Super::BeginPlay();
	
	ProjectileMesh->OnComponentHit.AddDynamic(this, &AProjectile::OnHit);
	UE_LOG(LogTemp, Warning, TEXT("Begin Play"));
}

void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	UE_LOG(LogTemp, Warning, TEXT("On Hit"));
}

In Projectile.h private:

UFUNCTION()
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

It’s very short code and nothing complex, I went over this again and again and couldn’t find a difference from the instructor code, what am I missing here?
Thanks in advance

Could you show the viewport in the projectile blueprint?

And you’re not getting the BeginPlay log either?

I’m getting the BeginPlay log, every time a projectile is created (shot)

Just to add a note if it matters, I’m using UE5

Does it work if you delete that projectile blueprint and then re-create it?

No, I tried recreating the BP from the c++ file twice again before asking here, didn’t work

Could you try rebuilding by closing Unreal then deleting the Binaries and Intermediate folders?
If that doesn’t work would you mind sending me your project using the following link?

https://gdev.tv/projectupload

Please use File > Zip Project within Unreal as this will ensure only required files are zipped up and things like the Binaries are excluded.

I am also using UE5 and having the same problem. I’ve tried all your solutions here to no avail. I’ll be uploading my project zip to the link you provided here in a minute.

Alright, after playing around with it more I found the issue. You must turn on “generates hit events” for the static mesh component and turn OFF generate overlap events. Apparently now (at least in some cases) in UE5 they are mutually exclusive.

1 Like

An object can have both types of events but it isn’t recommended according to the documentation.

In general, overlap events are useful for detecting when an object enters or exits invisible volumes (e.g. triggers) whereas hit events are more useful for detecting collisions between objects that essentially ‘block’ each other (a projectile colliding with a wall, for example). So while technically not mutually exclusive, they generally have different uses.

That is option is only for when simulating physics. You should disable simulate physics and then move your spawn point further away as it was too close to the mesh on both tank and turret pawns preventing it from moving.

@DanM If you’re referring to the ‘Simulation Generates Hit Events’ option, that’s actually not true - an object can absolutely generate hit events with the ‘Simulate Physics’ option disabled, albeit both the name of the option and the tooltip are a bit misleading. Also from the second screenshot it appears that ‘Simulate Physics’ is already disabled.

I assume your second comment about the spawn point being too close to the tank & turret is in reference to the actual project that was uploaded, which I don’t have access to, but that sounds correct based on similar issues I’ve seen in the past.

Different person.

I think you misunderstand. That option is only for “Simulate Physics”; however that doesn’t imply that you can’t have hit events without “Simulate Physics” otherwise that would mean with my suggested fix above it wouldn’t actually fix the issue.

That’s kind of the whole point of the bool, hit events are disabled if you simulate physics unless you opt into it by checking that.

For illustration:

1 Like

Yep, got it. I was a bit confused because you said to disable ‘Simulate Physics’ but it appeared that it already was disabled based on the screenshot. I also thought you were implying that hit events were only generated if ‘Simulate Physics’ was enabled, which you clarified.

And yes, to be fair, I didn’t realize that enabling ‘Simulate Physics’ actually disabled hit events unless you opt-in with the flag as you indicated and also as stated in the documentation.

I learned something today, thank you! :slight_smile:

1 Like

Hi, I’m having the same problem and not understanding what the fix is. My projectile does not have simulate physics enabled.


So to confirm, your projectile is being fired and you’re not getting the log when it hits? What happens instead?

I had the same issue here’s what I did:

  • Tick “Simulation Generates Hit Events” in BP_Projectile
    image
  • Close the editor and recompile from VSCode
  • After that you can re-open the editor
    These steps fixed it for me
7 Likes

Privacy & Terms