15 - Movement
A movement booster: temporarily bumps the character's max walk speed using a SetTimer, then restores it - the idiomatic UE burst-speed pattern.
Full source
include "CoreMinimal.h"
include "GameFramework/Actor.h"
include "GameFramework/Character.h"
include "GameFramework/CharacterMovementComponent.h"
include "TimerManager.h"
uclass AExampleMover : AActor meta: api=EXAMPLES_API
{
prop public float BoostMultiplier EditAnywhere BlueprintReadWrite category="Movement" default=2.0f
prop public float BoostDuration EditAnywhere BlueprintReadWrite category="Movement" default=5.0f
field public FTimerHandle BoostResetTimer
func public void ApplyBoost(ACharacter* Char) BlueprintCallable category="Movement"
{
if (Char && Char->GetCharacterMovement())
{
UCharacterMovementComponent* M = Char->GetCharacterMovement();
M->MaxWalkSpeed *= BoostMultiplier;
GetWorldTimerManager().SetTimer(
BoostResetTimer,
[this, Char, M]()
{
M->MaxWalkSpeed /= BoostMultiplier;
},
BoostDuration, false);
}
}
}
Line by line
prop public float BoostMultiplier ... default=2.0f- how much faster during the boost.prop public float BoostDuration ... default=5.0f- how long the boost lasts.field public FTimerHandle BoostResetTimer- the handle for the restore timer (so you can clear it if needed).ApplyBoost(ACharacter* Char)- takes a character, scalesMaxWalkSpeed, then schedules a lambda viaSetTimer...[this, Char, M](){ M->MaxWalkSpeed /= BoostMultiplier; }- ...that restores the speed afterBoostDurationseconds.GetWorldTimerManager().SetTimer(...)- the global timer manager;false= don't loop.
Why this pattern
- No ticking - nothing runs every frame; the timer fires once to restore.
- Safe capture - the lambda captures the character and movement component by pointer (in a real game, guard the actor's validity, e.g.
IsValid/weak ptr). - Idempotent restore - dividing back by the same multiplier returns the original speed.
Extending
Cancel early with GetWorldTimerManager().ClearTimer(BoostResetTimer);, or add cooldown handling. See Timer instead of Tick for the general recipe.
This is the last example - continue to Recipes & patterns.