Search Unity

Question Scaling a 2D Sprite/GameObject via Animation - Smooth in Scene Window, Not Smooth in Game Window.

Discussion in '2D' started by jf065d, Jun 4, 2023.

  1. jf065d

    jf065d

    Joined:
    May 28, 2018
    Posts:
    23
    Hi,
    Strange situation: I have a game object with a sprite renderer and animation component.

    What: Over the course of 30 frames, this object's X and Y scale uniformly from 1.1 to 1.0
    Problem: When I play the animation (via the Animation Window in the editor), the scaling looks different in the Scene vs. Game window: In the Scene window, it looks very smooth and you can see a very minor change on every frame. In the Game window, it's not smooth. There will be multiple frames where you will not see the object changing in size at all, and then suddenly it moves more than it should, and typically on the X or Y, before the other axis jumps a frame or two later.

    I'm attaching a GIF in an attempt to show the issue taking place. Note how the scaling is uniform and smooth on the right/Scene window.

    Could be this be a result of a resolution setting in the game perhaps? Or how the sprite is scaled? (although making a much large sprite or changing the pixels per unit didn't help).

    Thoughts? Scaling-Issue.gif
     
    Last edited: Jun 5, 2023
  2. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    Hi @jf065d, are you using cinemachine or pixel perfect camera in your scene? Not sure exactly what's causing the discrepancy, if you can share your project I'll be happy to take a look.
     
    jf065d likes this.
  3. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    this is normal, there arent enough pixels to smoothly scale like that

    try it in a larger sprite and dont zoom in your scale to 5x and you will see that if you supply more pixels to the screen it will be smoother
     
    jf065d likes this.
  4. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    601
    The main source of discrepancy seem clear to me. In the scene view the visible part gets rendered at whatever resolution the corresponding subsection of Unity window is. So when you zoom in scene view you will get a lot more intermediate steps.
    In the game view the scale option only upscales the already rendered output. It no matter what scale you set on the top it will still renderer the whole camera view at 1920x1080 or whatever your chosen resolution is. When using point sampling mode, minimum size change is one pixel. And when you zoom in 5x in the rendered output, that 1 pixel change will become 5px change making look less smooth. But that's not representative of what players will normally see. On their screens it will look like shrinking the sprite by one onscreen pixel. Can't really have any intermediate steps between scaling from 36 to 35 pixels.

    Some things you should learn from this -> scene view isn't accurate representation of how things will be rendered in game especially when it comes to counting pixels, because the resolutions in scene view are completely different.

    In general when drawing pixelart maximum sharpness conflicts with smoothness, you can't have smooth subtle movements or scaling. Moving and scaling in size of 1px increments can result in visible jumps even on 2560x1440 screens, it's worse for slow movements. If you know what you are doing you can tradeoff some amount of sharpness for smoothness, by blending pixels with appropriate shaders.
     
    jf065d likes this.
  5. jf065d

    jf065d

    Joined:
    May 28, 2018
    Posts:
    23
    Thanks for everyone's insights! The explanation makes sense (the Scene window is dedicating my entire screen's 1920x1080 resolution to show whatever I'm zoomed in on. Where as the Game window is still dedicating all 1920x1080 for the entire game, but just enlarging the portion I'm zooming in on, thus making it lower resolution compared to the Scene window).

    I'll investigate a shader based solution (or learn to live with it - It's actually not too noticeable in game if I also do some minor position changes along with the scale changes). Thanks again.