# Using SetTimer() on a Function with Parameters

**URL:** <https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335>\
**Category:** Character & Animation\
**Tags:** parameters, timer, unreal-engine, CPP, question\
**Created:** [January 29, 2015, 7:48am UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335 "2015-01-29T07:48:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Janyx](https://forums.unrealengine.com/u/Janyx)\
**Post date:** [January 29, 2015, 7:48am UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335/1 "2015-01-29T07:48:03Z")

</div>

I am currently trying to implement a method that calls 2 functions. The catch is I don’t want the second one to run until the animation of the first has finished playing.

I am trying to unequip a weapon then equip a new one. Each weapon in the game has its own holster/equip animation, that’s why I need to play the animations separately.

I have been trying to do it by:

```
GetWorldTimerManager().SetTimer(this, &AArenaCharacter::EquipWeapon, Duration, false);

```

The problem is AArenaCharacter::EquipWeapon(class AArenaRangedWeapon\* NewWeapon) takes a parameter in, so the timer gets upset. Does anyone know of a way I can have the timer run a function that takes in parameters?

---

<div class="post-metadata">

**Author:** ![Ghar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ghar](https://forums.unrealengine.com/u/Ghar)\
**Post date:** [October 22, 2015, 9:02pm UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335/2 "2015-10-22T21:02:59Z")

</div>

It is possible using FTimerDelegate as described here: [SetTimer with parameters - C++ - Unreal Engine Forums](https://forums.unrealengine.com/showthread.php?55363-SetTimer-with-parameters)

```
void AMyGameMode::RespawnPlayerWithDelay(APlayerController * Player, float Delay)
{
	FTimerHandle UniqueHandle;
	FTimerDelegate RespawnDelegate = FTimerDelegate::CreateUObject( this, &AMyGameMode::RespawnPlayer, Player );
	GetWorldTimerManager().SetTimer( UniqueHandle, RespawnDelegate, Delay, false );
}
```

---

<div class="post-metadata">

**Author:** ![Pedro\_Palacios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pedro\_Palacios](https://forums.unrealengine.com/u/Pedro_Palacios)\
**Post date:** [February 8, 2016, 1:16pm UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335/3 "2016-02-08T13:16:53Z")

</div>

it’s possible to do the same thing but with two parameters instead of only one?

---

<div class="post-metadata">

**Author:** ![Pedro\_Palacios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pedro\_Palacios](https://forums.unrealengine.com/u/Pedro_Palacios)\
**Post date:** [February 8, 2016, 1:17pm UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335/4 "2016-02-08T13:17:11Z")

</div>

it’s possible to do the same thing but with two parameters instead of only one?

---

<div class="post-metadata">

**Author:** ![Orfeas\_El](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Orfeas\_El](https://forums.unrealengine.com/u/Orfeas_El)\
**Post date:** [February 11, 2016, 9:17am UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335/5 "2016-02-11T09:17:14Z")

</div>

Hello, of course it’s possible to have the requested functionality you seek! Inside your header file type in the following code:

```
UFUNCTION()
void MyUsefulFunction(int32 x, float y);

```

Then, inside your source file:

```
FTimerDelegate TimerDel;
	
FTimerHandle TimerHandle;

int32 MyInt = 10;
float MyFloat = 20.f;

//Binding the function with specific values
TimerDel.BindUFunction(this, FName("MyUsefulFunction"), MyInt, MyFloat);
//Calling MyUsefulFunction after 5 seconds without looping
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDel, 5.f, false);

```

**Don’t forget** to include the MyUsefulFunction logic in your source file as well:

```
void AMyActor::MyUsefulFunction(int32 x, float y)
{
	GLog->Log("x="+FString::FromInt(x));
	GLog->Log("y=" + FString::SanitizeFloat(y));
}

```

For more information about delegates, check out the [official documentation](https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Delegates/index.html) and my blog post [here](http://orfeasel.com/using-delegates/)

-Orfeas

---

<div class="post-metadata">

**Author:** ![Vahid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vahid](https://forums.unrealengine.com/u/Vahid)\
**Post date:** [February 22, 2016, 4:18pm UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335/6 "2016-02-22T16:18:32Z")

</div>

Thanks for your answer i use it and it’s working but i have a issue.  
I have a loop timer and my parameter changed from different function but that Delegate just use initial value ! is it possible to use dynamic parameter .

In you example you used a local variable, but i using a public variable and it’s changing from different functions.

---

<div class="post-metadata">

**Author:** ![ja0335](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ja0335/32/560997_2.png) [@ja0335](https://forums.unrealengine.com/u/ja0335)\
**Post date:** [May 10, 2018, 2:48pm UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335/7 "2018-05-10T14:48:10Z")

</div>

Yes, as FTimer::CreateUObject signatures says:

inline static TBaseDelegate CreateUObject(UserClass\* InUserObject, typename TMemFunPtrType::Type InFunc, VarTypes… Vars)

so you can pass multiple parameters.

---

<div class="post-metadata">

**Author:** ![Vorrin\_Tal](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vorrin\_Tal](https://forums.unrealengine.com/u/Vorrin_Tal)\
**Post date:** [February 7, 2025, 7:10pm UTC](https://forums.unrealengine.com/t/using-settimer-on-a-function-with-parameters/305335/9 "2025-02-07T19:10:26Z")

</div>

> [@Orfeas\_El](#):
>
> TimerDel.BindUFunction(this, FName(“MyUsefulFunction”), MyInt, MyFloat);  
> //Calling MyUsefulFunction after 5 seconds without looping  
> GetWorld()-\>GetTimerManager().SetTimer(TimerHandle, TimerDel, 5.f, false);

ah that’s even using a different and somewhat more pleasant syntax, thanks a lot for this!
