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

Bug Pink sprites textures in build

Discussion in '2D' started by RunningStone, Sep 2, 2023.

  1. RunningStone

    RunningStone

    Joined:
    Oct 18, 2020
    Posts:
    16
    Everything is fine in the editor and play mode. When building a project, sprites that are included in the atlas, which is included in the addressable asset bundle, are rendered pink. I get these sprites in runtime from the bundle via an AssertReference from the ScriptableObject sprite database. Is there a problem with the shader that should render them?
     

    Attached Files:

  2. RunningStone

    RunningStone

    Joined:
    Oct 18, 2020
    Posts:
    16
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Usually this is because you are mixing and matching targets, eg, addressable built for one target, application built for another.

    Otherwise, if you're using anything like
    Shader.Find()
    that will fail 100% of the time that you don't hard-reference the material somewhere else in your built project contents.
     
  4. RunningStone

    RunningStone

    Joined:
    Oct 18, 2020
    Posts:
    16
    Can I get a little more detail from now on? Where are these settings and what needs to be changed?
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Start with the Addressables docs, make a known simple test case work.

    Until you can do that, nothing else matters.

    Once you have that working, begin to bisect towards your actual project until you isolate the issue.

    https://en.wikipedia.org/wiki/Bisection_(software_engineering)
     
  6. RunningStone

    RunningStone

    Joined:
    Oct 18, 2020
    Posts:
    16
    Active build target settings [UnityEditor.EditorUserBuildSettings.activeBuildTarget], it seems to me that this is exactly what should be in this case. I'm building for Windows, bundles are also being built for it. Maybe that's not the point?
     
  7. RunningStone

    RunningStone

    Joined:
    Oct 18, 2020
    Posts:
    16
    Wouldn't the whole bundle be broken if the build target was specified incorrectly? The fact is that I get access to its resources correctly, the only problem is that the images from it are rendered incorrectly. The problem is in the shader that is being used. It doesn't work as it should. I didn't change anything in the graphics settings, so I could hardly break something with my own hands.
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Not in my experience. Assets will generally load just fine, then come up pink due to platform mismatch causing the shader to fail.

    Start your investigation there. If it works normally then it will work in Addressables, assuming you meet all the Addressable requirements (see docs).

    That's not the correct approach.

    Something is broken.

    Your job as a software engineer is to find out why.

    See steps above.
     
  9. RunningStone

    RunningStone

    Joined:
    Oct 18, 2020
    Posts:
    16
    I found a solution. It was like this: on the prefab, which is instantiated from Addressable, the graphics for which are broken, there is a SpriteRenderer. When releasing the handle, which this prefab loads, for some reason the material is also unloaded?shader? associated with the prefab render. That is, the rest of the instance objects and the instance itself remain in the scene and work as they should, but the material?shader? they are not considered by the system as resources to which there is a link, and are unloaded. Very non-obvious behavior for me.
    In order for everything to work, it was necessary to remove the unloading of the prefab's handle after creating a copy of it. I removed it in the onDestroy object.