OnComponentHit Function not working

Hello, I’m having problem with the OnComponentHit activation.

Basically I’ve written this code for my projectile class:

And this is how the OnHit function is declared and defined:

The problem is that the OnHit function is never called.

The collision settings on my projectile’s static mesh component (which is the root component and the only scene component of the actor) are the following:

And those are the collision settings of the object type “Enemy”:

In game, the only things that actually block my projectile are indeed actors with collision type of “Enemy”, but the OnHit function is never called.

Can somebody help me and tell me what I’m missing here? Thanks a lot!

Try binding in BeginPlay() instead of the constructor. For some reason the constructor doesn’t always bind to events correctly.

Hey, I have the same problem with the same class. Only, binding this event in BeginPlay vs the constructor isn’t helping.

You may be asking why the similarity - it’s because it’s a tutorial on Udemy we’re following.

My code:

Never mind, found someone that had the same issue in the tutorial forums - link here if you have the course to read it yourself.

The answer is though, close unreal editor, recompile (build) and then relaunch editor.

1 Like

Thanks man! Still having trouble figure out how Visual Code, Unreal Engine and LiveCoding vs. ‘normal’ Compiling plays together…
ToonTanks right? So how is your Unreal Journey going so far?

A year and a half in, it does start making sense!

I don’t remember if it was ToonTanks, but it was that tutorial series on Udemy. It really helped me a lot.

You can see an update of where I’m at in building ‘the game’ here - Edge Emperor - Game Update - Harvesting Improvements - YouTube