Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

[SOLVED] Watcher does not notify about changes while short animations

Discussion in 'Project Tiny' started by reallyhexln, Apr 9, 2019.

  1. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Hi guys.

    I have the following code that using to create animation and to determine if such animation is completed:

    Code (JavaScript):
    1. let time: number = 0.2;
    2.  
    3. ut.Tweens.TweenService.addTween(
    4.                 this.world, entity,
    5.                 ut.Core2D.Sprite2DRenderer.color.a,
    6.                 0, 1,
    7.                 time, 0,
    8.                 ut.Core2D.LoopMode.Once,
    9.                 ut.Tweens.TweenFunc.OutExponential,
    10.                 true);
    11.        
    12. let watcher = new ut.Watchers.WatchGroup();  
    13. watcher.watchChanged(
    14.             this.world, entity, ut.Core2D.Sprite2DRenderer.color.a,
    15.             (entity, cid, offset, prevValue: number, newValue: number, watchId) => this.onTweenUpdate(entity, prevValue, newValue));
    16.             watcher.schedule(this.world.scheduler());
    17.          
    18.          
    19. ...
    20.  
    21. private onTweenUpdate(entity: ut.Entity, prevValue: number, newValue: number): void {
    22.       console.log("Tween update");
    23. }
    I use Watcher to determine if animation is completed, as it was described in the manual.
    I have determined that sometimes Watcher callback is not called at all.
    This issue reproduces often when I set little time interval for animation, just like in the code above.
    Is it some kind of expected behavior?
    Is there more robust way to determine if an animation is completed?
     
  2. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Sorry guys, it's my own issue.

    I checked newValue and maxValue with too big precision (6 digits), while the tweener stops when the newValue is equal to maxValue with 4-digits precision.

    Maybe, it was helpful for someone.