Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: real-time animations take more time than expected #690

Open
vanaigr opened this issue Aug 13, 2024 · 0 comments
Open

bug: real-time animations take more time than expected #690

vanaigr opened this issue Aug 13, 2024 · 0 comments

Comments

@vanaigr
Copy link

vanaigr commented Aug 13, 2024

Description

Real-time animations (SetUpdate(UpdateType updateType, bool isIndependentUpdate) with isIndependentUpdate=true) take more time than they should, with slowdown dependent on the framerate (higher framerate - longer animations). 

Cause

The cause of the issue is that Time.realtimeSinceStartup is accessed twice in DG.Tweening.Core.DOTweenComponent.Update() (lines 72 and 77). But its value changes between the reads, so the time to process animations is not accounted for.

The relevant part of the Update() method:

_unscaledDeltaTime = Time.realtimeSinceStartup - _unscaledTime;
if (DOTween.useSmoothDeltaTime && _unscaledDeltaTime > DOTween.maxSmoothUnscaledTime) _unscaledDeltaTime = DOTween.maxSmoothUnscaledTime;
if (TweenManager.hasActiveDefaultTweens) {
TweenManager.Update(UpdateType.Normal, (DOTween.useSmoothDeltaTime ? Time.smoothDeltaTime : Time.deltaTime) * DOTween.timeScale, _unscaledDeltaTime * DOTween.unscaledTimeScale * DOTween.timeScale);
}
_unscaledTime = Time.realtimeSinceStartup;

From the Unity docs on Time.realtimeSinceStartup:

This is the time in seconds since the start of the application, and is not constant if called multiple times in a frame. [emphasis mine]

Solution

Read Time.realtimeSinceStartup once at the start of the method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant