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. Dismiss Notice

Question One-loop animation in animated tiles is sometimes "late"

Discussion in '2D' started by putto72, Sep 18, 2023.

  1. putto72

    putto72

    Joined:
    May 21, 2023
    Posts:
    2
    Hello, I'm developing a 2D game using Unity Editor 2022.3.4f1; it's an action strategy game in the style of Tetris. For animations, I'm using animated tiles (2D Tilemap Extras 3.1.0, 2D Animation 9.0.3, 2D Common 8.0.1, 2D Pixel Perfect 5.0.3, 2D SpriteShape 9.0.2). Essentially, on a separate layer I set a single-loop animated tile when I need to transform one tile into another; on the layer below, there's the final static tile. When the animation is complete, I hide the animated tile. Most of the animated tiles consist of 7 frames played at 20 fps, so the animation lasts about 350 ms. The issue I'm encountering is that the animations, while mostly playing correctly, sometimes appear "delayed" on the screen, making them seem shorter than 350 ms. Sometimes it almost seems like the played animation only includes the last frames.

    I've tried hiding the animated tiles both based on the expected completion time and the current frame (checking if it's the last one to determine that the animation has been fully played), but the behavior remains as described: the animations are mostly fine, but sometimes they are "late". In the log, I print the timestamp when I show and hide each animated tile, and the interval is always correct (350 ms).

    The animated tiles are displayed and hidden using a FixedUpdate in the associated script; initially, I was doing these operations in the Update function, but I got better results using FixedUpdate (Project Settings -> Time -> Fixed Timestep = 0.005).

    Do you have any suggestions on what I could check/modify to ensure that the animations in the animated tiles always appear "complete"? Thank you.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Is that a typo? That's a HORRENDOUSLY high fixed timestep (200 fps)... it should be more like 0.02, the default

    Generally, don't do anything except physics in FixedUpdate. If you had a bug when you did it that way, fix the bug, don't do it incorrectly in the FixedUpdate() loop.
     
  3. putto72

    putto72

    Joined:
    May 21, 2023
    Posts:
    2
    Actually I reset to default (0.02) and even moved my animation check routine to Update(); last time I did it, using FixedUpdate seemed to make a difference, but frankly the difference now is minimal. Neverthless I keep getting inconsistent animation from animated tiles: during gameplay sometimes they are complete, sometimes you get just a glimpse at the last frames.