dentedpixel / LeanTween

LeanTween is an efficient animation engine for Unity
608 stars 135 forks source link

Tweens with long delays are never called? #145

Open ChristianMcFarlaneWork opened 4 years ago

ChristianMcFarlaneWork commented 4 years ago

We've recently noticed on one of our projects, that if we have two lean tweens running, where one has a long delay, and another tween running on a completely separate object is using the PingPong loop type, it seems to cause with the first tweens delay to never complete. Example: Long Delay Tween (GameObject 1)

LeanTween.moveLocal(gameObject, Vector3.zero, 5)
     .setDelay(5)
    .setEase(LeanTweenType.easeOutQuad)
    .setLoopType(LeanTweenType.once)
    .setIgnoreTimeScale(false);

Ping Pong Tween (GameObject 2)

LeanTween.moveLocal(gameObject, Vector3.one, 1)
     .setDelay(1)
    .setEase(LeanTweenType.easeOutQuad)
    .setLoopType(LeanTweenType.pingPong)
    .setIgnoreTimeScale(false);

In this situation, GameObject 1 will never move at all because the delay doesn't seem to complete?

Is it something we are doing wrong? We think its because our tween is never fully initialized until the actual tweening begins and not during the delay, which inturn means that we are inheriting the deltaTime from the other tween which has already begun?

For the moment we have managed to get around this by setting the bool usesNormalDt so we force recalculation.

    public bool updateInternal(){

        float directionLocal = this.direction;

        // CUSTOM CODE!
        //
        // Force Calculation of our normal DT right here. Fixes errors with long delays on tweens never working
        usesNormalDt = !(useEstimatedTime || useManualTime || useFrames); // only set this to true if it uses non of the other timing modes
        //
        //

        if(this.usesNormalDt){
            dt = LeanTween.dtActual;
        }else if( this.useEstimatedTime ){
            dt = LeanTween.dtEstimated;
        }...

Thanks in advance!