#[Tip] Destroy bullet shells after a few seconds instead of right away - two line change

2 messages · Page 1 of 1 (latest)

teal compass
#

Instead of destroying the casing in OnHit, add SetLifeSpan to your constructor. that way you get a nice pile of shell casings accumulating on the floor for a short while. Simple change.

ACasing::ACasing()
{
    // ...

    // This will auto destroy after 5 seconds.  You can use whatever delay you prefer
    SetLifeSpan(5.0f);
}


void ACasing::OnHit(UPrimitiveComp||onent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
    if (ShellSound)
    {
        UGameplayStatics::PlaySoundAtLocation(this, ShellSound, GetActorLocation());
    }

    // Remove following line:
    //Destroy();
}
teal compass
#

Just noticed that this was actually a section Challenge! Unfortunately I don't see a way to change the tagging or message title after posting the message. Well there you go! 🙂