LeanTween not able to tween timeScale, need help

Alright so, chances are I might just have blundered with the implementation but LeanTween doesn’t seem to be able to tween timeScale to a higher value. It’s able to tween to a lower value eg. 1f to 0.75f but it doesn’t seem to go from 0.75f to 1f.

var TweenID = LeanTween.value(Time.timeScale, 1f, EndTweenDurationConvert).setEase(LeanTweenType.linear).setIgnoreTimeScale(true).id;
print(TweenID);
PreviousTimeScaleEndTweenID = CurrentTimeScaleEndTweenID;
CurrentTimeScaleEndTweenID = (int)TweenID;
print(CurrentTimeScaleEndTweenID);

The code uses a var to hold a LeanTween ID that is only used in a single instance in the code for cancelling the tween, I tested this one spot where it can potentially do so and it was not the cause of the issue. The prints show that the ID is valid both when it’s initially declared as TweenID and when it’s saved as CurrentTimeScaleEndTweenID.

The issue at first glance also doesn’t seem to be the result of the timeScale already being lower since setIgnoreTimeScale is set to true and the .id at the end doesn’t seem to be causing issues either because it works just fine with other occurrences in the script with that same format.

Additionally there aren’t any errors shown for this, the only thing that showed up in the console was the print functions.

Any guidance here would be appreciated.

Did you destroy the old tween when you started the new one to bring it back up to 1?

If not then I imagine the two are fighting it out and 0.75-boy is winning.

funny enough, I actually didn’t have code that stopped a previous tween there which would have interfered as well, so thanks for that.

unfortunately it didn’t quite fix the issue, same results as before.

I’m looking at that Leantween.value() call… the first argument is just a float.

Passing in Time.timeScale doesn’t let the guy inside change it. That’s not how passing floats works. It would need to be passed by ref if you contemplated it being changed in there.

Are you hooking some other set-timescale kinda callback on there that I’m just not seeing?

You might want to go read more about that Leantween.value method. I just don’t think it works like you imagine above.

yeah I figured I was probably doing something wrong with the declaration of the tween here.

I’ve gotten it closer to the correct format for LeanTween.value but I’m not entirely sure how to declare the timeScale as the first argument.

var TweenID = LeanTween.value(Time.timeScale, updateValueExampleCallback, SlowmoLevel, 1f, EndTweenDurationConvert).setEase(LeanTweenType.linear).setIgnoreTimeScale(true).id;
void updateValueExampleCallback(float val)
{
    Debug.Log("goober gingleson");
}
print(TweenID);
PreviousTimeScaleEndTweenID = CurrentTimeScaleEndTweenID;
CurrentTimeScaleEndTweenID = (int)TweenID;
print(CurrentTimeScaleEndTweenID);

Seems like a LOT of extra complexity to involve a tweener for this.

If you’re just moving a number smoothly from one thing to another, just do it. I always use this pattern:

Smoothing movement between any two particular values:

You have currentQuantity and desiredQuantity.

  • only set desiredQuantity
  • the code always moves currentQuantity towards desiredQuantity
  • read currentQuantity for the smoothed value

Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.

The code: SmoothMovement.cs · GitHub

In your case you could just track float desiredTimeScale; and move Time.timeScale towards it.

it definitely is a lot of extra complexity, but that’s what I’m going for here. this is part of a general-purpose slowmo script I’m writing with some degree of flexibility.

the idea of just mimicing a tween with math does sound like an option but that’s really only going to replicate a basic Linear tween unless I manually wrote in the math for the other types ( which I am most likely not experienced enough to do )

unity also returned an error ( which it didn’t previously ) now stating that it “cannot convert from ‘float’ to ‘UnityEngine.GameObject’”, makes sense given that LeanTween.value seems to require a GameObject to even use.

it also turns out I made a blunder in another part of the code which made me assume it worked one way but not the other, instead it just doesn’t do it at all.

extra note:
I completely overlooked this bit by the way

.setEase(LeanTweenType.linear)

it was written as just a Linear tween when it was actually meant to contain a variable containing a LeanTweenType so the type could be interchanged

ok yeah after toying around a bit I got a solution with this working

var TweenID = LeanTween.value(Parent, updateValueExampleCallback, Time.timeScale, 1f, EndTweenDurationConvert).setEase(EndTweenTypeConvert).setIgnoreTimeScale(true).id;
void updateValueExampleCallback(float val)
{
    Time.timeScale = val;
}
print(TweenID);
PreviousTimeScaleEndTweenID = CurrentTimeScaleEndTweenID;
CurrentTimeScaleEndTweenID = (int)TweenID;
print(CurrentTimeScaleEndTweenID);