C++ Destroy Actor on Projectile Hit

I have function to destroy Actor on hit, but it works only with my charachter touch
I want to change it to projectile hit (FPS Template).
How may I do this?

@Lordderon
The condition is only True if otherActor->GetOwner() is Equal to GetFirstPlayerController().
So you need to remove it ( if it can collide with anything ) or add an or and check if GetOwner() is the type of your projectile.

@SolidSk
Thanks for advice. But how should I implement this to code? I’m new in UE4 and don’t understand this

He means something like this:

if (IsValid(OtherActor) && IsValid(OtherComp)) { // Check that these are not nullptr and not pending kill

    // Were we hit be the player?
    if (OtherActor->GetOwner() == GetWorld()->GetFirstPlayerController()) {
        addDeathCount(); // Increment the death count
    }

    Destroy(); // Destroy self if we hit anything
}

Also, you don’t need to write “ASphereEnemy::Destroy();” and “ASphereEnemy::addDeathCount();”. You only need to write “Destroy();”, and “addDeathCount();”.

Another thing: You’re technically supposed to use PascalCase for all of your names in your code. This will make it look more consistent with the Engine code. So “addDeathCount” would become “AddDeathCount”.

Hope this helps!

1 Like

Thath’s it! And I rename all in the code)
Thanks

1 Like