Void AttackDelay_Elapsed(ACharacter* InstigatorCharacter) High-Frequency Timers The header file contains the UFUNCTION() marked function and the parameter: UFUNCTION() GetWorld()->GetTimerManager().SetTimer(TimerHandle_AttackDelay, Delegate, AttackAnimDelay, false) FTimerHandle TimerHandle_AttackDelay įTimerDelegate Delegate // Delegate to bind function with parametersĭelegate.BindUFunction(this, "AttackDelay_Elapsed", Character) // Character is the parameter we wish to pass with the function. In this case, we bind the function by name instead. The example is from the Action Roguelike project. It’s possible to pass parameters into timer functions (delegates). } Using SetTimer() on a Function with Parameters GetWorld()->GetTimerManager().ClearAllTimersForObject(this) Alternatively you can clear ALL timers that belong to this (Actor) instance. GetWorld()->GetTimerManager().ClearTimer(FuzeTimerHandle) Ensure the fuze timer is cleared by using the timer handle void ASBombActor::EndPlay(const EEndPlayReason::Type EndPlayReason) You don’t need to do this for timers that have elapsed and aren’t looping. There are two ways of dealing with timer removal. When destroying or deactivating objects, make sure you clear any active timers. Your function will look something like this: UFUNCTION() It’s important to mark your function with UFUNCTION() macro in order to have it bind correctly with the timer. * Handle to manage the timer */įTimerHandle FuzeTimerHandle Binding Timer to Function Although you are not required to keep a reference to the handle, it’s recommended to put this in your header to properly clear or pause your timer instance. GetWorld()->GetTimerManager().SetTimer(FuzeTimerHandle, this, &ASBombActor::OnExplode, MaxFuzeTime, false) * Activate the fuze to explode the bomb after several seconds */ You can also set a timer to run the next frame by calling SetTimerForNextTick().Ĭode sample from SurvivalGame BombActor where we set a timer for a delayed explosion: void ASBombActor::OnUsed(APawn* InstigatorPawn) There are a couple of overloads (function variations) available to pass the function to execute, the interval between ticks (if looped) and flag to set looping, and the optional first delay. You set timers through the global timer manager which is available through GetWorld()->GetTimerManager() or the shorthand available in any Actor, GetWorldTimerManager() which returns the same timer manager. Using SetTimer() on a Function with Parameters.
0 Comments
Leave a Reply. |