Search Unity

Xbox One UWP Timescale messed up?

Discussion in 'Windows' started by HaakonL, Dec 21, 2016.

  1. HaakonL

    HaakonL

    Joined:
    Mar 13, 2014
    Posts:
    123
    Hi,

    we have a minute/second/hundreds counter in our game, working flawlessly on all devices. Except on the Xbox One when built as UWP. The time just speeds away several times faster than it should.

    We're using UniRx, but that should not matter. Something makes time go faster on Xbox One S.

    I recorded a short video showing the time UI going bananas: https://www.dropbox.com/s/iqpw5ok7erdshbp/IMG_0813.MOV?dl=0

    Anyone have experience with this? Is it the Timescale that needs to be tweaked when publishing to XBox?


    RaceModel.cs
    =====
    public LongReactiveProperty Time;
    Time = new LongReactiveProperty();

    RaceController.cs
    =====
    public void UpdateTime(RaceModel raceModel, long value)
    {
    raceModel.Time.Value = value;
    }

    RaceView.cs
    =====
    ViewModel.Time.Subscribe(OnTimeChanged).AddTo(gameObject);

    void Update()
    {
    if (_stopwatch != null && _stopwatch.IsRunning)
    {
    _raceController.UpdateTime(ViewModel, _stopwatch.ElapsedTicks);
    }
    }

    private void OnTimeChanged(long value)
    {
    _raceTimeText.text = DateTime.MinValue.Add(new TimeSpan(value)).ToString("mm\\'ss\\\"ff");
    }
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    This piece of code looks incorrect. TimeSpan constructor takes "ticks" as in "time period expressed in 100-nanosecond units", while Stopwatch "ticks" is a hardware dependent unit of time. I can see where the confusion might be coming from - they're both called "ticks", but they're not the same. Use Stopwatch.Frequency field to convert stopwatch ticks to seconds.
     
  3. HaakonL

    HaakonL

    Joined:
    Mar 13, 2014
    Posts:
    123
    Hi,

    cool, nice catch! Thanks, I learned something new.

    A small rewrite, and it should be handled without the need to convert with Frequency:

    RaceModel.cs
    ===
    public ReactiveProperty<TimeSpan> Time;
    Time = new ReactiveProperty<TimeSpan>();

    RaceController.cs
    =====
    public void UpdateTime(RaceModel raceModel, TimeSpan elapsed)
    {
    raceModel.Time.Value = elapsed;
    }

    RaceView.cs
    =====
    ViewModel.Time.Subscribe(OnTimeChanged).AddTo(gameObject);

    void Update()
    {
    if (_stopwatch != null && _stopwatch.IsRunning)
    {
    _raceController.UpdateTime(ViewModel, _stopwatch.Elapsed);
    }
    }

    private void OnTimeChanged(TimeSpan elapsed)
    {
    _raceTimeText.text = DateTime.MinValue.Add(elapsed).ToString("mm\\'ss\\\"ff");
    }