Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sprite is broken

Discussion in 'General Graphics' started by Shushustorm, Apr 24, 2016.

  1. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Hello everyone!
    I've got some sprites in my project and one of them is broken.
    I don't know how this happens, nor could I find a solution to this problem.

    screenshot.PNG

    As you can see in the attached screenshot, other sprites do work (like CubeSprite23).
    But CubeSprite25 will have a weird glitch.
    Also, when I use CubeSprite25 in Unity's UI Image component, it will show up fine.
    The problem only shows up in the editor when I expand the file and when I use it as sprite for a 2D sprite GameObject.

    This is what I tried without resolving the issue:
    - Reimport file
    - Refresh file
    - Edit file in Photoshop and give it a completely black layer above everything (this will result in a black square without the problem showing! But when I remove that layer again, the issue reappears)
    - Copy & paste content of the layer onto a new layer in Photoshop
    - Save the image as a new file
    - Reimport all files of the project
    - Restart machine
    Do you have any idea how to fix it?
    It seems quite persistent.

    Best wishes,
    Shu

    EDIT:
    Even when duplicating a working file and pasting the image content from CubeSprite25 in Photoshop, the duplicated working file will break.

    EDIT2:
    Does Unity contain censoring certain "illegal" patterns? Maybe I created a pattern that isn't supposed to be displayed? I have no idea, but this is very confusing as the issue seems to be connected to the actual arrangement of the pixels rather than the file.

    EDIT3:
    It works when I set its "Max Size" to 64. But anything above will break the image.
     
    Last edited: Apr 24, 2016
  2. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    Are you importing these as PSD files? My first guess is it may be some quirk of the Unity PSD importer; some rare bug with a certain number of layers with certain properties or blend modes.

    I would flatten all the layers and export it as a PNG file. See if that fixes it.
     
    Shushustorm likes this.
  3. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    @CaptainScience
    Thank you for your suggestion!
    Yes, all the files are .psd. But as you suggested, I exported the problematic one as .png.
    Unfortunately, the problem persists. As long as the .png sprite is above 64*64 "Max Size", it will break.
    Also, all the files only have one layer, which is set to "normal". So there really isn’t anything fancy going on. The files should be completely the same besides the patterns themselves. Even that one layer is named the same: "Ebene 0" (German for "Layer 0").
     
  4. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    That is strange. Is there anything strange happening in your alpha channel? You could set the texture to "Advanced" and try some different types of settings/compression types there to see if that changes anything. Maybe even try saving it through a different image program like GIMP? Not that that any of that should make a difference, but if it is just a strange, random bug then there's no telling what kind of change might be necessary to work around it.

    If you want to post the file, I can always trying importing it on my machine and seeing what happens.
     
    Shushustorm likes this.
  5. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    You can take a look at the file: I attached CubeSprite25.psd.

    I don’t use GIMP, but I tried exporting from Affinity Photo as .png, but it will result in the same issue.
    When it comes to the alpha channel, there is nothing that seems weird to me.

    But:
    When I import the file into Unity, the meta data will differ from the meta data of the other files. There will be this one line that is not included in the other files:
    allowsAlphaSplitting: 0

    Does anybody know what that means?
    I tried saving a fresh file that doesn’t have that meta data, though, but the new meta data will also include that line.

    EDIT:
    I also attached CubeSprite24.psd, which is working.
    Oh and I didn't change anything in the Sprite Editor. All the distances are set to 0.
    Besides, renaming the file didn't solve the problem.

    EDIT2:
    When I edit the file significantly, it will work (see CubeSprite25_2.psd).
    CubeSprite25_2.psd's meta data will also include allowsAlphaSplitting: 0, but there will be other lines changed:

    CubeSprite25.psd’s meta data will include (same as all the other files):
    textureFormat: -3
    filterMode: 0
    aniso: 16


    CubeSprite25_2.psd’s meta data will include:
    textureFormat: -1
    filterMode: -1
    aniso: -1

    Also, I just removed the allowsAlphaSplitting: 0 from CubeSprite25.psd's meta data and I reimported the file, but unfortunately with no success (meta data won't regenerate that line, though).
    And allowsAlphaSplitting: 0 is even there when putting CubeSprite25.psd to 64*64 Max Size (when it works).
    This is very confusing.
     

    Attached Files:

    Last edited: Apr 25, 2016
  6. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    Okay, I took a look and it, and I was getting the same issue. It is a problem with Unity's sprite mesh utility. By default it seems like Unity creates a mesh for the sprite that trims off any unused parts of the texture (based on alpha). It seems like there is a bug with the mesh generation for particular texture so it is related to the exact configuration of pixels within the texture.

    If you switch to "Advanced" mode in the texture inspector, you can look in the "Sprite" section and switch "Mesh Type" from "Tight" to "Full Rect". That will give you a full quad for your sprite which is what you want here since there isn't a lot you can trim off your sprite anyway.

    That should fix your issue, but you should also submit a bug report to Unity with your texture so they can take a look at their algorithm and see why it was cutting off a piece of the sprite in this case.
     
    Shushustorm likes this.
  7. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    @CaptainScience
    I see! Thank you very much! This indeed is a workaround to the problem! Awesome!
    Also, I just reported this as a bug. Hopefully, they can improve this.
     
    Martin_H likes this.