Hello everyone!
I need to execute delayed fuction with parameters, but can’t understand how can I do it
I tried some ways that I found on old forumsm but it doesn.t work =(
Params
- UAnimMontage* FireAnim,
- FRotator FireDirection,
- const TArray>& Query,
- float Damage
Which way can I pass this parameters to timer?
1 Like
Figured it out with lambda
void APlatformerCharacter::FireReq_Implementation(UAnimMontage* FireAnim, FRotator FireDirection, const TArray<TEnumAsByte<EObjectTypeQuery>>& Query, float Damage)
{
Fire(FireAnim, FireDirection, Query, Damage);
GetWorldTimerManager().ClearTimer(FirePreDelay);
TimerDelegate.BindLambda([&, FireAnim, FireDirection, Query, Damage]()
{
if (HasAuthority())
{
FVector StartTrace = GetCapsuleComponent()->GetComponentLocation();
FVector EndTrace = GetCapsuleComponent()->GetComponentLocation() + (FireDirection.Vector() * 200.f);
FHitResult HitRes;
TArray<AActor*> Empty;
UKismetSystemLibrary::LineTraceSingleForObjects(
GetWorld(),
StartTrace,
EndTrace,
Query,
false,
Empty,
EDrawDebugTrace::ForDuration,
HitRes,
true,
FLinearColor::Red,
FLinearColor::Green,
5.f
);
AP_DestructBlock* DestrBlock = Cast<AP_DestructBlock>(HitRes.Actor);
if (DestrBlock)
{
DestrBlock->AddDamage(Damage, DestrBlock);
if (DestrBlock->DMI)
{
float NewHealthVal = DestrBlock->CurrentHealth - Damage;
DestrBlock->SetCurrentHealth(NewHealthVal);
DestrBlock->OnRep_CurrentHealth();
}
}
}
});
if (CurrentWeapon)
{
GetWorldTimerManager().SetTimer(FirePreDelay, TimerDelegate, CurrentWeapon->PreFireDelay, false);
}
}
1 Like