Search Unity

Pink materials from Asset Bundles

Discussion in 'Editor & General Support' started by jonlab, Mar 20, 2017.

  1. jonlab

    jonlab

    Joined:
    Apr 6, 2010
    Posts:
    182
    Hello all,

    This is a quite known issue, but we can't find anymore any workarounds.
    When we load an Asset bundle, the loaded object appears pink because the shader can't be found.

    A few links to similar issues / posts :
    https://support.unity3d.com/hc/en-u...ders-are-pink-when-loaded-from-an-AssetBundle
    https://forum.unity3d.com/threads/l...es-makes-assets-appear-pink-in-editor.326541/
    https://forum.unity3d.com/threads/shaders-and-asset-bundles.435667/

    Our project is an online multiplayer world dedicated to audio experimentation (called New Atlantis). So we have a standalone player, and a library that user can install to build their own content (objects), exported as Asset bundles and loaded by the standalone player at runtime.
    Important thing is that Asset bundles are exported with a different Unity project than the standalone player is built, because that is the point : user generated content.

    • Back to Unity 4 (this version of the project started in 2014), there was no issue : every material or shader included in an Asset bundle was displaying properly.
    • When we upgraded to Unity 5.x (I don't remember exactly what version), we started to have pink materials issues, that we solved just by adding the missing pink shaders to the always included shaders in the Graphics settings. I heard this has something to do with Precompiled shaders no longer supported + maybe some bugs.
    • Then, on the next upgrade, this was not working anymore (pink was back). We were able to fix that with the
      Code (CSharp):
      1. renderer.material.shader = Shader.Find(renderer.material.shader.name);
      hack that I found on this forum.
    • But now on Unity 5.5.2, it does not work anymore. a Lot of the pink shaders are back, and the above hack is not working anymore. The renderer.material.shader.name in the Asset bundle is blank (an empty string), so no chance to ever know what shader this was !!!!
    What can we do ?
    Reexport the bundles is not really an option, because all these Asset bundles are works from students and people that are not available anymore.

    Are Asset bundles really not usable for user generated content from a different Unity project ?
    I really think that a shader is a data like a texture, so it should be included in the bundle, not as a reference to the main standalone player...

    Any help or hints appreciated !
    Thanks !
     
    WhiteGfx and Sami_AlEsh like this.
  2. jonlab

    jonlab

    Joined:
    Apr 6, 2010
    Posts:
    182
    Any idea ?
    We are even considering abandonning the Asset Bundles and doing our own bundle format...
     
  3. jonlab

    jonlab

    Joined:
    Apr 6, 2010
    Posts:
    182
    Strange thing is that very old Asset Bundles exported with Unity 4 work as a charm in last Unity 5.5.2 version, but other exported with Unity between 5.1.X and 5.4.X appear pink ! Any idea ?
    Thanks !
     
  4. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    I read your reply on one of the referenced threads.

    The good news: we are using asset bundles since Unity 4 up until now with Unity 5.5.2, we had the pink shader issue at one point (which is why we contributed to that thread), and now it is solved for us.

    We have 4 platforms (windows, mac, android and ios) for which we build asset bundles. These are a few things we know:
    • The assetbundles are not interchangeable between platforms. It's not entirely true, some types of assets are interchangeable, like meshes, but things like shaders and audio are not, for good reasons.
    • You can indeed add shaders to the always included list, but perhaps better is to build an assetbundle with only shaders in it, make all the other assetbundles depend on it, and at runtime load that one first. Like that, the shaders are not inside the other assetbundles or in the project.
    • Because shaders, audio and other things can be compressed, compiled or imported differently between different versions of Unity, the assetbundles are not interchangeable between versions. Sometimes they are, but then you're just lucky.
    This means that assetbundles generated with other versions of Unity by other users will probably not be compatible with your standalone player. This seems logical to me: asset bundles contain compressed and compiled assets, imported with specific settings for a specific platform.

    A shader can be treated as data like a texture, but both textures and shaders are compiled and compressed differently for different platforms and different versions of Unity, thus not interchangeable once they are put in an assetbundle.

    You create bundles of data that you want to be able to use in any future version of Unity and perhaps other platforms. Do users add their own shaders? (I would think not) In this case I would recommend to put the source data (fbx files, jpg, png and others) into a zip file and read that into your game. That way, since its uncompiled and unprocessed data, you can compile and compress it at runtime according to the latest version.

    So yes, you need to create your own bundle format, with source data.
     
  5. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    You can try the serialization tools that TNet3 offers. They don't work for me (yet), but my setup might be more exotic than yours. With Unity's asset bundles I had nothing but problems from version to version.
     
  6. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    I have the same Problem since i upgraded from Version 5.5.0f3 to 5.6.0f3

    All content is loaded from asset bundles. Now some shaders draw the lovely unity pink and throw warnings and errors:

    Failed to load GpuProgram from binary shader data in 'Standard'
    D3D shader blob is empty!


    We have separate asset bundles for PC, MAC and WebGL. All are not working anymore.

    That annoys me so much! With every new (sub-)version of unity, they introduce some new errors or undocumented changes. Every update the new question: what is it this time, that will not work anymore?!

    Unity, do you have a QA-department? How is it possible, that a bug/change whatever can be released without any warning of these changes or telling workarounds to handle this?
    There is every time here and there such a "little" undocumented change, that breaks everything.

    How about a text file: "Things that will not work anymore, when updating to the newest version"?

    Then you want us, the customers, to sit for hours to prepare the perfect bug report with sample scenes and stuff, bevor the gentlemen start to realize that a mayor bug went through their QA that needs to be fixed fast.
     
    Wothanar likes this.
  7. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    Did you rebuild the assetbundles with 5.6.0f3?
     
  8. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    Yes, we rebuilt all asset bundles for all platforms. usually, this solves these kind of problems, but not this time.
     
  9. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    They're not in the cache anymore?
     
  10. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    No, they are not cached. In Editor it reads the bundles directly from a specified directory. Only the builds read them from server or from cache. I also made some changes to the meshes, and the changes are there.

    This seems to happen mostly to the legacy vertex-lit shader with transparency. But on some points, we still want to stick with these shaders for a while, because of when you have a lot of single objects they produce less draw calls.
    These happens also to shaders produced with shader forge.

    Something must have changed with including these shaders.
    When i try to include them in edit/project settings/graphics it throws an error:

    DirectoryNotFoundException: Could not find a part of the path "...\ProjectName\Resources\unity_builtin_extra".

    I've never heard of these ressources folder in the project folder. And i never changed anything. This happened through the update to 5.6
     
  11. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    Hi -

    I'm not the most advanced coder, but I have managed to get AssetBundles systematically working for an iOS app that I developed, and resolved the pink shader issue simply by ensuring that all of the shaders I'm using are saved in a shadervariant file (filename.shadervariant), which is included with the host scene, e.g. the scene into which the AssetBundles are being loaded.

    In my case, my host scene is the GUI, and once the user has made a selection, an AssetBundle containing the chosen scene is loaded. This includes geometry, shaders, materials, audio, scripts, etc. As long as the scripts and the shaders are present in the host scene, everything seems to look and work as expected.

    Is that too simple?
     
  12. Tallek

    Tallek

    Joined:
    Apr 21, 2014
    Posts:
    34
    You ever figure out a solution for this? We have the same problem. User generated content from AssetBundles built in an older version of Unity will load in a new version, but prefabs loaded from those asset bundles can't find their shaders. Were are stuck in Unity 5.3 unless we want to break most of our user's mods...
     
  13. GssKhidev2

    GssKhidev2

    Joined:
    Oct 16, 2017
    Posts:
    1
    How can i add that shadervariant file with scene under the same AssetBundle tag for both of these?
     
    mfakkaya likes this.