"Onhit" function not working correctly

Don’t bind the delegate in the constructor as it’s not reliable. Move the following line from the constructor to e.g. BeginPlay:

CollisionComp->OnComponentHit.AddDynamic(this, &AFPSProjectile::OnHit);  

You can override BeginPlay by adding the following to your header:

public:
        virtual void BeginPlay() override;

and implement it in your cpp file as follows:

void AFPSProjectile::BeginPlay()
{
            // Always remember to call Super
    	    Super::BeginPlay();
    
            // Bind delegate
            CollisionComp->OnComponentHit.AddDynamic(this, &AFPSProjectile::OnHit);
}
1 Like