Search Unity

Bug Sprite showing weird dots/lines upon rotation.

Discussion in '2D' started by JohnnyConnor, Aug 17, 2022.

  1. JohnnyConnor

    JohnnyConnor

    Joined:
    Aug 10, 2020
    Posts:
    42
    I created a test sprite sheet and am making some sprites appear in a scene by using the Sprite Renderer component attached to a GameObject. I can move and rotate most of my sprites around the scene without having any issues, however, whenever I rotate my GameObject while it's rendering a certain sprite of my sprite sheet, some weird dots appear above it. I have tried reimporting my spritesheet, the pixel perfect camera and disabling anti aliasing, but no success so far.

    Does anyone know why this is happening and how to fix it? More info below:

    Sprite Sheet configuration:
    SpriteConfig.PNG

    Rotated sprite (these dots appear in-game and it looks bad):
    weirdSprite.PNG
     
  2. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    204
    Hi @JohnnyConnor, It looks like your Sprite picks up some pixel from other area of your sprite sheet. You can try to edit your Sprite in the Sprite Editor and make sure that the Border is very tight and it encapsulates only the area you want to be visible.
     
    JohnnyConnor likes this.
  3. JohnnyConnor

    JohnnyConnor

    Joined:
    Aug 10, 2020
    Posts:
    42
    Thanks for the reply. Although I don't think my sprite should be picking the pixels above it (similar small sprites worked just fine), further reducing the border to encapsulate only the bugged sprite worked. This is how it was set it in the editor back then:

    SpriteSheet.png

    Does that means I should always leave some space in between the sprites of my sprite sheets? After all, I wouldn't be able to reduce the border size of this sprite if the sprite occupied more space.
     
  4. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    204
    Looking at your screenshot, I think what was happening is the pixels at the top part of the border were picking up the beige from the sprite above it. You could add a few pixels of padding between your sprites to make sure there is no pixel bleeding.
     
  5. JohnnyConnor

    JohnnyConnor

    Joined:
    Aug 10, 2020
    Posts:
    42
    That's strange, because I made each sprite in a 24x24 canvas and told Unity to specifically slice the sprite sheet in 24x24 squares. Not only that, similar sprites to the bugged one had no issues at all. But yeah, apparently Unity does have a chance of rendering part of the pixels around a sprite border due to a bug. I suppose I should add some padding between sprites and make tighter borders whenever necessary from now on.
     
  6. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    204
    This kind of behavior is expected and is really a nature of texture sampling.

    You could also import them as individual files and let Sprite Atlas to pack them for you.