Pass a variable by ref to timer's lambda function

I want to create a function for interpolate a float without a timeline and not in tick.
I created it using timer, but the problem is, it’s not updating the original float (Passed in Blueprints)

Can someone help?

> UFUNCTION(BlueprintCallable, Category="Tween")
> static void InterpolateFloat(UObject* Context, UPARAM(ref) float& InFloat, float TargetValue, float Duration, UCurveFloat* Curve, FOnTweenCompleted OnCompleted);
> void UTweenFunctionLibrary::InterpolateFloat(UObject* Context, float& InFloat, float TargetValue, float Duration,UCurveFloat* Curve, FOnTweenCompleted OnCompleted)
> {
> 	if (UWorld* World = Context->GetWorld())
> 	{
> 		float StartValue = InFloat;
> 		float ElapsedTime = 0;
> 		float Alpha = 0;
> 
> 		FTimerManager& TimerManager = World->GetTimerManager();
> 		TSharedPtr<FTimerHandle> TimerHandle = MakeShared<FTimerHandle>();
> 
> 		UE_LOG(LogTemp, Type::Warning, TEXT("Start Tween"));
> 		TimerManager.SetTimer(*TimerHandle, [Context, UPARAM(ref) &InFloat, StartValue, TargetValue, ElapsedTime, Duration, Alpha, OnCompleted, TimerHandle]() mutable
> 		{
> 			if (Alpha < 1)
> 			{
> 				ElapsedTime += Context->GetWorld()->GetDeltaSeconds();
> 				Alpha = ElapsedTime / Duration;
> 
> 				const float NewValue = FMath::Lerp(StartValue, TargetValue, Alpha);
> 				InFloat = NewValue;
> 				
> 				UE_LOG(LogTemp, Type::Warning, TEXT("The value is %f"), InFloat); 
> 			}
> 			else
> 			{
> 				Context->GetWorld()->GetTimerManager().ClearTimer(*TimerHandle);
> 				if (OnCompleted.IsBound()) OnCompleted.Execute();
> 				
> 				UE_LOG(LogTemp, Type::Warning, TEXT("Stopped Tween. Float is %f"), InFloat);
> 			}
> 		},
> 		World->GetDeltaSeconds(), true);
> 	}
> }

can you share the logs for this function?

are your log messages inside the Lambda firing “the Value is” and the like (is the code being called in the first place)? especially the code outside outside the Lambda as well.

is the Delegate being fired (OnTweenEnd)?

a Looping Delay into a Timeline with the exec of the OnComplete leaving the loop would have far greater granularity in the level design stage.

image

Yes, The logs and the Delegate are being fired, and the logs are showing the new value.