Hello, good morning. I`m trying to do a Destroy() on OtherActor in a OnHit function after certain time. Basically I added some impulse to the Actor I hit, and I want to destroy it few seconds after.
I`m trying to use “FTimerDelegate”, using this syntax:
in the header file:
UFUNCTION()
void DestroyOtherActor(AActor* ActorToDestroy);
FTimerHandle DestroyActorHandle;
FTimerDelegate DestroyActorHandleDelegate;
In cpp file I tried with this syntax:
I`m trying to do inside the OnHit function, which is this:
void ABulletProjectile::OnHit(UPrimitiveComponent * HitComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, FVector NormalImpulse, const FHitResult & Hit)
{
FTimerDelegate DestroyActorHandleDelegate;
DestroyActorHandleDelegate.BindUFunction(this, FName("DestroyOtherActor"), OtherActor);
GetWorldTimerManager().SetTimer(DestroyActorHandle, DestroyActorHandleDelegate, 0.2f, false, 0.2f);
}
and this syntax:
FTimerDelegate RespawnDelegate = FTimerDelegate::CreateUObject(this, &ABulletProjectile::DestroyOtherActor, OtherActor);
GetWorldTimerManager().SetTimer(DestroyActorHandle, RespawnDelegate, 0.2f, false, 0.2f);
and this is the function to call:
void ABulletProjectile::DestroyOtherActor(AActor* ActorToDestroy)
{
FVector OtherActorLocation = ActorToDestroy->GetActorLocation();
UGameplayStatics::SpawnEmitterAtLocation(this, KilledEnemyParticle, OtherActorLocation);
ActorToDestroy->Destroy();
}
but neither seem to work. I dont see any errors in the editor, nor warnings.
Thanks