Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.34k stars 351 forks source link

DOTween.To() Not working for long value> 2cr value #630

Open rakshithshettycs opened 1 year ago

rakshithshettycs commented 1 year ago

_value=100000000(10cr) target=1000000001 _tween = DOTween.To(() => _value, UpdateValue, target, 0.5f)

If i use above code: expected value is :1000000001 but out we get is some random number. Reproduction step : Add 1 value to target in every frame and check. it not increasing value directly to the target

rakshithshettycs commented 1 year ago

I came to know the issue. DOTween.To() supports till max value of float(16777217). is it possible to update it to long?

Demigiant commented 1 year ago

Ahoy, the DOTween.To method already supports both long and ulong, can you check if your _value is a long too?

rakshithshettycs commented 1 year ago

i am Attaching used code please check. UpdateValue(value) receives some random value instead of proper value. OnButtonUpdate() is getting called from unity button. On button click i am increasing the value. But it's not updating new value properly. I will attach video please check.

https://user-images.githubusercontent.com/127080019/228417031-0601cfae-fb51-4f55-bb94-5557e3515081.mov

using System.Collections; using System.Collections.Generic; using DG.Tweening; using TMPro; using UI; using UnityEngine;

public class Test : MonoBehaviour { public long _value=100000000; public long tempadd = 1; public long finalValue; long target;

[SerializeField] private TMP_Text _text;
private Tween _tween;

private void Start()
{
    target = _value;
    UpdateValue(_value);
}

public void OnButtonUpdate()
{
    finalValue = _value + 1;
    TweenBasedUpdate();
}

private void TweenBasedUpdate()
{
    _tween?.Kill();
    target = finalValue;
    _tween = DOTween.To(() => _value, UpdateValue, target, 1f).SetEase(Ease.OutQuad).OnComplete(() => UpdateValue(finalValue));
}

private void UpdateValue(long value)
{
    Debug.LogFormat("Target:{0} --- Current:{1}", finalValue, value);
    if (_value != value)
    {
        _value = value;
        _text.text = value.ToString();
    }
}

}

gray-pigeons commented 1 year ago

Oh my God, I had the same problem today, when my initial value was in the hundreds of millions, it showed a little bit more than expected, The API I use is public static Tweener To(DOGetter getter, DOSetter setter, long endValue, float duration); I ended up writing the code like this: public void StartToEndText(long startValue, long endValue, Text txt, float showTime = 2f) { DOTween.To( () => startValue,//get v => { txt.text = v.ToString(); },//set endValue,//endValue showTime).SetEase(Ease.Linear).OnComplete( () => { if (!txt.text.Equals(endValue.ToString())) { txt.text = endValue.ToString(); } });//time } The version used is:1.1.640