x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Using SetTimer() on a Function with Parameters

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?

Product Version: Not Selected
Tags:
more ▼

asked Jan 29 '15 at 07:48 AM in C++ Programming

avatar image

Janyx
469 62 61 210

(comments are locked)
10|2000 characters needed characters left

4 answers: sort voted first

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 and my blog post here

-Orfeas

more ▼

answered Feb 11 '16 at 09:17 AM

avatar image

Orfeas El.
257 8 24 25

avatar image Vahid Feb 22 '16 at 04:18 PM

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.

(comments are locked)
10|2000 characters needed characters left

It is possible using FTimerDelegate as described here: 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 );
 }
more ▼

answered Oct 22 '15 at 09:02 PM

avatar image

Ghar
652 32 104 126

avatar image Pedro Palacios Feb 08 '16 at 01:17 PM

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

(comments are locked)
10|2000 characters needed characters left

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

more ▼

answered Feb 08 '16 at 01:16 PM

avatar image

Pedro Palacios
3 2 3 5

avatar image ja0335 May 10 '18 at 02:48 PM

Yes, as FTimer::CreateUObject signatures says:

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

so you can pass multiple parameters.

(comments are locked)
10|2000 characters needed characters left

Animations are one of the effective things to tell and explain your thoughts and edu birdie always perform a good task for students. The writer is focusing on one of the best things so that they can easily run this set up. using a set timer. So I really appreciate the amazing idea of the writer.

more ▼

answered Nov 19 '18 at 03:21 PM

avatar image

Vence Braad
0 1 1

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question