Search Unity

Loading assets from assetbundles makes assets appear pink in editor.

Discussion in 'Editor & General Support' started by MarimoAli, May 18, 2015.

  1. Sparrowfc

    Sparrowfc

    Joined:
    Jan 31, 2013
    Posts:
    100
    I think that issue is unrelated to this subject. The materials in the bundle turns pink are not because missing texture, but due to the shader in the bundle is not referenced to the one in project.
     
  2. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    This bug still exists in Unity 5.3, :(
     
    andersemil likes this.
  3. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    Make sure that you have completely new assetbundles, since 5.3 is not backwards compatible. I used a 5.3 build with a lot of assetbundles, but somehow there was one old one still among them, causing the whole scene to turn pink.
     
  4. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    I have re-created my asset bundles in 5.3 and now I seem to have a problem where all particle systems loaded from bundles appear pink (using Unity's particle shaders), whereas other assets load fine from them. In 5.2.x it was all fine, no changes since then. I haven't done more investigation yet.
    Am I doing some wrong or might this be a Unity problem?
     
  5. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    If I were you I'd create a small project that loads that assetbundle and see if it's also pink. Log all assets that can be found in the assetbundle. Most of the time I find my problems this way.
     
  6. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    I have this problem with custom shaders but only in the editor. On all platforms it works ok.

    To fix it, I just select the offending material in the editor and reapply the custom shader at runtime.
     
  7. darcyrayner

    darcyrayner

    Joined:
    Jun 20, 2013
    Posts:
    6
    I have an iOS/Android project, and the alexvda's workaround doesn't work for me on 5.2.2, 5.2,3 or 5.3.0. In addition, default shaders refuse to load as well. I'm using the Mac version of the editor, which might make a difference. So far we've hacked a work around where we search for all the Renderers and perform a shader replacement on them, but it is super hacky.
     
  8. Who-am-I

    Who-am-I

    Joined:
    Mar 29, 2014
    Posts:
    73
    What is your current target platform in build setting?
    I was facing same problem in editor only(Selected platform Android in build settings) but after build apk its working fine.
     
  9. darcyrayner

    darcyrayner

    Joined:
    Jun 20, 2013
    Posts:
    6
    I've tried it on both. It works perfectly at build time, it's just the editor which is broken.
     
  10. Who-am-I

    Who-am-I

    Joined:
    Mar 29, 2014
    Posts:
    73
    yes you are right? same here
    I think this is unity editor bug
     
  11. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    120
    I had the pink textures in editor for a bundle where I'm reading in textures to assign to my in-scene objects. Got around it using this variation of the shader hack script that was posted on page 1 that uses #if:

    Code (CSharp):
    1. vPlaneRenderer.material = vBundle.PlaneRenderer.sharedMaterial;
    2. // Use platform compile flags to fix for shader issue in Unity editor
    3. #if UNITY_EDITOR
    4.    vPlaneRenderer.material.shader = Shader.Find(vBundle.PlaneRenderer.sharedMaterial.shader.name);
    5. #endif
    6.  
    Where vPlaneRenderer is a public Renderer I dragged my in-scene object onto in the inspector, vBundle is just a ref to a wrapper class I use for my bundles, and vBundle.PlaneRenderer is an exposed Renderer property in that wrapper where I cached the bundled prefab gameobject's renderer.
     
  12. gfdgdfgdfg

    gfdgdfgdfg

    Joined:
    Sep 29, 2014
    Posts:
    7
    I got a problem in 5.3.
    two assetbundle, these have a build in vertexlite shader, when i load them, the "shader.parse" use a lot of time.
    i think a build in shader should not need reparse, any guy know what about this problem
     
  13. gfdgdfgdfg

    gfdgdfgdfg

    Joined:
    Sep 29, 2014
    Posts:
    7
  14. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Not here. Broken in builds and in Editor. Was fine in 5.2.x, but broke since 5.3.0.

    How are you loading your asset bundles? I am using the WWW class with a "file://" path.

    EDIT:
    I filed a bug for this and now Unity QA came back to me about it. They suggest it's a duplicate of this which I assume is a product of this thread.
    I however am not sure if it's the same problem. We will see with v5.4 I guess.
     
    Last edited: Jan 4, 2016
  15. jonlab

    jonlab

    Joined:
    Apr 6, 2010
    Posts:
    182
  16. Iseebees

    Iseebees

    Joined:
    Jan 4, 2015
    Posts:
    5
    I often encounter pink materials after updating or changing asset bundles. A solution that works for me is to clear the cache before downloading new or updated asset bundles.

    This is the script I use:
    http://www.mingruijiang.com/Clear-Unity-editor-cache

    After doing that, all the pink is gone and everything is properly rendered. For me, the error doesn't occur when simulating the asset bundles, using Unity's asset bundle manager, only when downloading from a remote source.
     
  17. SimteractiveDev

    SimteractiveDev

    Joined:
    Jul 9, 2014
    Posts:
    97
    So just to confirm, this issue hasn't been fixed yet, has it? I see some people saying it is, but I notice in Bug tracker it is still marked as active (plus I'm still getting the issue).

    Also, just want to clarify, I shouldn't add my shaders to a bundle should I or mark them as always included?

    Thanks.
     
    Last edited: Feb 18, 2016
  18. holliebuckets

    holliebuckets

    Moderator

    Joined:
    Oct 23, 2014
    Posts:
    496
    @Benzino07 Were you able to submit a bug report? When running Unity choose Help->Report a Bug in the menu. If you can/did could you post the case number for me?
     
  19. SimteractiveDev

    SimteractiveDev

    Joined:
    Jul 9, 2014
    Posts:
    97
  20. holliebuckets

    holliebuckets

    Moderator

    Joined:
    Oct 23, 2014
    Posts:
    496
    @Benzino07 It's always possible to have a common symptom but different causes. :) In this symptom, two common causes have been:
    1) failing to load the bundle that actually contains the shader, prior to loading the bundle with the material in
    2) baking bundles for one OS that are then used on another OS, so the bundles don't contain the necessary OS variants

    If you check those and still have a recurring missing texture, please submit a bug report (with a repro project if at all possible) and if you can please keep me updated! :)
     
    SimteractiveDev and karl_jones like this.
  21. SimteractiveDev

    SimteractiveDev

    Joined:
    Jul 9, 2014
    Posts:
    97
    @holliebuckets Ok I will check these, but can I ask a couple of questions on these just so I'm sure I understand you fully.

    1) I don't have my shaders or materials in an asset bundle, should I? The asset bundles only contain sprite sheets and my scenes.
    2) I assume this also includes the editor? So when building my bundles for iOS, I need to also build it for StandaloneOSXUniversal to prevent the issue from occurring in the editor when running on Mac?

    Sorry about these questions, they are probably obvious but I find the docs to be a bit unclear on some of these aspects. Thanks :)
     
  22. holliebuckets

    holliebuckets

    Moderator

    Joined:
    Oct 23, 2014
    Posts:
    496
  23. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Just to be clear: this is not one single bug.

    The pink material stuff just means there was a problem setting up the material and/or shader. There's a bunch of ways this can happen. Two of them include:
    • Loading bundles on one platform that were built for another. For example, if you build your bundles for iOS and then try loading them on PC, it won't work because PC needs the Direct3D versions of the shaders and the bundle won't contain those (because there is no Direct3D on iOS). To fix this you just need to make sure that the bundles you are loading were built for the platform you are loading them on.
    • Failing to load the bundle that contains your shader (or loading it after the one with the material in). As of Unity 5.0 the AssetBundle pipeline will calculate the dependencies between the bundles, but it won't automatically load the bundles for you (because in general it has no idea where to get them from). To fix this you just need to load all the required bundles, and you need to do it in the correct order. The AssetBundleManager demo project on the Asset Store demonstrates how you can use the AssetBundleManifest to implement your own automatic dependency loading.
    We can and will improve the error reporting around these scenarios, but in both cases there is no engine 'bug' per se - just a relatively unhelpful failure behavior.

    So, if you are still facing this issue, and neither of the mistakes described above fix your problem, please file a bug report instead of assuming that somebody else has done it - because it is very likely that their problem is not the same as yours exactly, and their problem will get fixed, but yours will not because it's actually a different case.
     
  24. oppaikir

    oppaikir

    Joined:
    Jun 17, 2015
    Posts:
    3
    I had the same problem in UnityEditor, not in platform.

    I build Android version assetbundle, and display correctly on my nexus machine.
    I build shader files to one assetbundle, and my prefab/material/texture to another.
    In my script file, I load shader assetbundle first, then load prefab from another assetbundle, finally get Renderer component and set the shader instance to it.

    It's working on my Android platform, but in Unity Editor, the material missing the shader.
    I already had switch the platform to Android in Build Setting.
     
  25. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Switching the platform to Android won't work. If your Editor is running on Windows, you need a Windows version of the bundle. If it's Mac, you need a Mac version. It doesn't matter which platform is your active build target platform.
     
    s4relok and holliebuckets like this.
  26. qiankanglai

    qiankanglai

    Joined:
    Jun 8, 2013
    Posts:
    22
    Hey Guys, I encountered this yesterday and the fix mentioned above works: If you want to show correctly in Editor, you need a asset bundle for shaders for Editor platform

    Example: I'm working on Windows Editor, built for Android Project now...
    So I need asset bundles for Android and a bundle containing all shaders built for Windows
    (But this is quite annoying indeed, since other asset bundles are for Android)

    More attention: if you need built in shaders show correctly, please put built in shaders (from Unity archive) into the asset bundle too.

    Example: the red arrow points to a material with "Unlit/Texture", after copying this shader from builtin folder into project folder, and built into a shader assetbundle for windows...This shows correctly now in Editor!

     
  27. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Hey. Could you please elaborate how to include those? I am trying to include them via script, but I dont have added for example the Standard Shader included anywhere. Do I have to put it somewhere, get the reference to it and add it manually to the assetbundle?
     
  28. qiankanglai

    qiankanglai

    Joined:
    Jun 8, 2013
    Posts:
    22
    simple steps (Let's take Unlit/Texture as example)
    1. copy `Unlit-Normal.shader` from `builtin_shaders-5.2.3f1\DefaultResourcesExtra\Unlit` into your project `Assets` folder
    2. build an asset bundle including this shader file, for windows
    3. load this asset bundle
     
    pahe likes this.
  29. JagaHee

    JagaHee

    Joined:
    Feb 18, 2010
    Posts:
    8
    Hello, i have the same trouble. I've prepared asset bundle and want to load and instantiate it in my scene. Everything went well until i tried to load object with Standard Shader and Rendering Mode set to Transparent. Every object with this shader is totally black. If i change any property on object it becomes tranparent as i wanted. When loading asset i create the copy of material as it is said here. What else can i try to prevent this black transparency?
     
  30. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    749
    same problem. transparent standard shader, or legacy transparent unlit. builf bundle in seperate project... download and load it into new project at run time, everything looks fine, but textures are pink.
    Used that script (above) to re-apply shaders to fix it. Unity pro, 5.3.4f1 pc in android setting.
     
  31. SurfDog

    SurfDog

    Joined:
    Apr 28, 2016
    Posts:
    2
    Same problem in 5.3.5f1
    Here are steps to reproduce the problem using Unity's AssetBundleDemo sample:

    1. Install Unity Personal 5.3.5f1
    2. Download Unity Asset Bundles sample from
    https://bitbucket.org/Unity-Technologies/assetbundledemo
    or from
    https://www.assetstore.unity3d.com/en/#!/content/45836
    3. Select VariantLoader.unity scene
    4. From Build Settings, select Android/iOS and Switch Platform
    5. Build Assets: Assets -> AssetBundles -> Build Assets
    6. Start Asset Server: Assets -> AssetBundles -> Local Asset Bundle Server
    7. Run Game, select "Load SD": ALL IS WELL, CUBE HAS UNITY LOGO TEXTURE

    8. On Cube prefab, change shader in "someMaterial" from "Legacy Shaders/Diffuse" to "Mobile/Diffuse"
    9. Build Assets
    10. Run Game, CUBE IS NOW PINK!

    Here are WARNINGs from Unity.log:

    WARNING: Shader Unsupported: 'Mobile/VertexLit' - Pass '' has no vertex shader
    WARNING: Shader Unsupported: 'Mobile/VertexLit' - Setting to default shader.
    WARNING: Shader Unsupported: 'Mobile/Diffuse' - Pass 'FORWARD' has no vertex shader
    WARNING: Shader Unsupported: 'Mobile/Diffuse' - Pass 'PREPASS' has no vertex shader
    WARNING: Shader Unsupported: 'Mobile/Diffuse' - Pass 'PREPASS' has no vertex shader
    WARNING: Shader Unsupported: 'Mobile/Diffuse' - All passes removed

    Note1: In our game, our meshes have this problem on almost all of the shaders we use. All works correctly when I switch to PC,Mac,.. Platform (and build Windows/Mac bundles); or when I re-select the shader while the Game is Running.

    Note2: Our game is for Mobile only, and we need to verify assets on devices. Switching between Windows & Android platforms, takes several hours, so working in Windows/Mac platform is not a realistic option.

    Note3: Even when I have four versions of the bundles (Windows, Mac, Android, and iOS), I still see PINK in Editor if I am on Android/iOS platform.
     
    Last edited: Jun 9, 2016
  32. Lszt

    Lszt

    Joined:
    Sep 28, 2015
    Posts:
    38
    For us, if we add all our shader that need to be built for all platform in :
    Edit -> Project Settings -> Graphics -> Always included shaders array

    It works. After this, we can build our asset bundle for Android target and still debug our game wihtin the unity editor
     
  33. Zaelot

    Zaelot

    Joined:
    Mar 26, 2015
    Posts:
    12
    Well, like Lszt said. There's also an option to save them (same Project Settings > Graphics) into Shader Variant Asset (shaders present in the current scene) and use that. Alternatively you can include examples of materials with all the different kind of shaders you're going to use in the Resources folder. (Remember, that choosing different Rendering modes for Standard shader effectively makes it a different shader as far as the compiler is concerned. So if you want transparent standard shaders at runtime, you'll need to have a material with such standard shader, in addition to the opaque one.) You could also change shader_feature pragmas to multi_compile, but this would positively explode your build size.

    Here's relevant discussion: http://forum.unity3d.com/threads/access-rendering-mode-var-on-standard-shader-via-scripting.287002/
    @JonnyHill @JagaHee
     
  34. adsk_marcopaivaf

    adsk_marcopaivaf

    Joined:
    Feb 5, 2015
    Posts:
    3
    Besides making sure that or Asset Bundle is built for your target platform, you need to make sure to clean the Asset Bundle cache from the previous time you downloaded it.

    I am using 5.5.0f3, and I always had this issue when using Asset Bundles. I fixed the issue today, by doing a couple of things:

    1. I made sure that the shader that I wanted to use was included in the Asset Bundle (I have a custom Standard Surface Shader);
    2. I made sure that I am building my Asset Bundle for my target platform (In my case, I am working on a Windows machine, targeting Windows 64);
    3. I included my custom shader to the "Always Included Shaders" list inside the Project Settings -> Graphics;
    4. I cleaned my Asset Bundle cache by running "Caching.CleanCache()" from an Editor script;
    5. Built Asset Bundle;

    Hope that helps someone =)
     
  35. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    If the shader is in the "always included shaders", then the shader is packed with your exe. There's no need then to add this to the assetbundle.
     
  36. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    Somewhat related to this. Has anyone gotten Shader Variants to work correctly in WebGL?

    We are trying to migrate from 5.3.x to 5.5 and all of our assets are now pink in the build. We have tried using the Shader Variant system so as not to have to include the whole Standard shader (or other shaders) in our scene, which blow up the build size.

    The only solution we've found is to have to rebuild all the assets in 5.5 for them to download and display properly.
     
  37. Zaelot

    Zaelot

    Joined:
    Mar 26, 2015
    Posts:
    12
    Rebuilding AssetBundles in new Unity version seems to be a necessary step everytime Unity team makes changes to AssetBundles.
     
  38. jonlab

    jonlab

    Joined:
    Apr 6, 2010
    Posts:
    182
    Same issue, see my post here : https://forum.unity3d.com/threads/pink-materials-from-asset-bundles.461919/
    If we have to rebuild all our Asset Bundles when Unity is updated, this is really bad.
    What I can't believe is that some of our Asset Bundles built with 4.X work very well in 5.5, but some built with 5.1 to 5.4 appear pink in 5.5.
    So no workaround at all ? No possible migration, no fix ? We are just stuck .?
     
  39. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    Are any of your assetbundles from <5.5 built with LZMA compression? Because that is no longer supported in 5.5 which we have seen cause similar issues.
     
  40. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Where did u see that LZMA is no longer supported ?
     
  41. Zaelot

    Zaelot

    Joined:
    Mar 26, 2015
    Posts:
    12
    In the changelog, they currently support Brocli and GZip.
     
  42. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    There's nothing related to that in the link you sent.
     
  43. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
  44. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Thanks. i am specifically working on mobile here, so that doesn't look like the issue for us.
     
  45. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    Agh, sorry. I spend so much time perusing the WebGL forum that I didnt even look at which forum this thread was on. May need to get some stronger coffee ;)
     
  46. CostiaRiko87

    CostiaRiko87

    Joined:
    Nov 16, 2016
    Posts:
    7
    same pink issue on 5.5.2p2
     
  47. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    112
    AND 5.6.0f3 on OS X loading an Android assetbundle with a custom shader. I realize why this would happen, but surely the Editor should detect which shader it needs and compile it for OS X, rather than failing to load an Android-compiled shader :-Z
     
  48. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    Nope, the assetbundle contains the compiled version of the shader for android. You cannot recompile this for another platform. That's like saying you would be able to recompile an exe to run on mac... Without the source you can't compile for another platform.
     
  49. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    112
    Dude, the source is right there, in the editor. That's the point.
     
  50. grrava

    grrava

    Joined:
    Nov 11, 2012
    Posts:
    46
    Yes, but you're loading the shader from the assetbundle, not from the editor. There is no reference between an asset in an assetbundle and the assets in the editor. Assets in an assetbundle could come from anywhere.

    That's why you better don't use assets from assetbundles in the editor in the first place. Check out this reference implementation: https://bitbucket.org/Unity-Technologies/assetbundledemo