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 have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

" Sprite outline generation failed - could not read texture pixel data." - When building the game...

Discussion in '2D' started by HideOnMada, Apr 6, 2020.

  1. HideOnMada

    HideOnMada

    Joined:
    Jan 23, 2020
    Posts:
    2
    Sprite outline generation failed - could not read texture pixel data. Did you forget to make the texture readable? pops up whenever I build the game. The consequences are that some of the 2d physics I have in said game has broken and I'm not sure how I would go about fixing it
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    If you are using Sprites, ideally you would have generated a Physics Shape for your Sprite to use in runtime. If not, you will need to make the Sprite's texture readable for Unity to read the pixels of the texture to create a shape based on the Sprite's outline.

    To do this, you will need to change the import settings of your Sprite's texture :
     
  3. ThatOneDudeFromThePlace

    ThatOneDudeFromThePlace

    Joined:
    Apr 1, 2018
    Posts:
    4
    Is this the only way this error can be thrown? I have meta files enabled and I searched for the string: spriteGenerateFallbackPhysicsShape: 0 in my project. I got one hit and enabled physics shape for that texture (even though it wasn't even used in my scene). Even with Generate Physics Shape enabled for every sprite in my project, I am still getting the error.
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    That is the most likely case where the error would be thrown. It could be possible that this is a bug or a special case where the Sprite Outline generation fails. If you could file a bug report using the Unity bug reporter with your failing texture and post the case number here, that would be helpful!
     
  5. Aurigan

    Aurigan

    Joined:
    Jun 30, 2013
    Posts:
    291
    For future me: This can happen if you have a tile on a tilemap that's linked to a blank sprite (likely because the sliced texture had blank regions in it), with a tilemap collider, in a build only, when trying to instantiate from a prefab.

    Best guess why this happens - sprite packing somehow breaks things.
     
    Black_Demon and Zelek like this.
  6. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    104
    This is exactly what's happening to me. Did you find a workaround?

    Edit: nevermind, one of the *thousands* of sprites in the project didn't have Read/Write and Generate Physics Shape enabled. Hey @ChuanXin (mentioning you because you're here, sorry if this is not your area!) would it be possible to add the name of the troubling texture to the log message? It could save some time to other devs in the future!
     
    Last edited: Dec 21, 2020
    Nith666, DungDajHjep and xjjon like this.
  7. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    723
    I have this in a webgl, I have no idea what sprites are causing the error. How do you enable "Generate Physics Shape" en masse? I have lots of sprites scattered across my project(it's not my project, just one I'm working on... hence why it's disorganized lol) I just got this error recently... I didn't add any new sprites... i did, however, duplicate a couple tlesets and slice them as "multiple" if that could've caused it?
     
  8. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    104
    I ended up making a custom editor script that looked for every single sprite in the project and listed all the sprites that didn't have "Generate Physics Shape" option ticked, so it was easier to find the problematic one. I don't think enabling that option comes at no cost, so you should only enable it where it's necessary.

    Sadly, I'm no longer part of that project and don't have the script I used to share.

    If I recall correctly, I used AssetDatabase.LoadAssets with "t:Texture" as parameter to save every texture in the project to an array. Then I just looped through that array and printed the name of the textures with the "generate physics shape" (I don't remember the real name) property set to false. You could also set the property to true there, but again I'm not sure what the caveats would be.

    I hope I was useful!
     
    Mashimaro7 likes this.
  9. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    723
    Ah, I figured I had to do something along those lines. I wasn't 100% sure on how though, so thanks! I'll try that :)