Pass arguments to GetWorldTimerManager().SetTimer function

Ah, I think I know why it’s not working. Delegates can only accept parameters that are passed by value, not references (because there no way to tell if the referenced value would still exist when the delegate is called) and the Explode() method expects a reference.

Try using a lamdba like this:



FTimerHandle ExplosionTimer;
FTimerDelegate ExplosionDelegate = FTimerDelegate::CreateLambda(=]()
{
	this->Explode(FHitResult());
});

GetWorldTimerManager().SetTimer(ExplosionTimer, ExplosionDelegate, ProjectileLifeTime, false);

The code inside the lambda will execute when the delegate is fired and then it will call Explode().

2 Likes