Copying AActor for use in Timer

Hello there,

I am trying to destroy an actor after a delay in C++. I need the other Actor to be passed to the DestroyOther method.

GetWorldTimerManager().SetTimer(DestroyDelayHandle, this, &ATileShooterProjectProjectile::DestroyOther, 3.0f, false);
However it is not possible to use parameters in a delegate method (Source: Using SetTimer() on a Function with Parameters - UE4 AnswerHub).

To try to solve this I created an instance pointer called HitActor.
(inside H file)
/Other actor hit by the projectile/
AActor* HitActor;

(inside method with Timer)
HitActor = OtherActor;

Inside the DestroyOther method I try to destroy this HitActor.
void ATileShooterProjectProjectile::DestroyOther(){

However this does not work, I think OtherActor goes out of scope because of the timer.
So how would I make a copy of the other actor, The engine does not seem to allow me to do HitActor = *OtherActor when HitActor is a normal object instead of a pointer. (does not allow me to use = operator)
Is there another alternative to solve this issue?

Thank you!

You can declare a delegate with parameters, use the sufixe`s _OneParam, _TwoParam so 4th

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FTimePassedSignature, AActor*, HitActor);

And then the method you bind the delegate to needs to have the same signature.

void TimePassedDelegate(AActor* HitActor);

Hope it helps

Yes it is. It’s explained in the second answer on the page you linked. That will do exactly what you’re after.