Search Unity

Current best practice for testing Asset Bundles in the editor?

Discussion in 'Asset Bundles' started by rchapman, Sep 17, 2019.

  1. rchapman

    rchapman

    Joined:
    Feb 13, 2014
    Posts:
    105
    We're having the common problem that our Android Asset Bundles are showing up pink while testing in the editor. It's not feasible to constantly prepare the bundles for both PC and Android every time we make a handful of changes. I came across this FAQ which recommends a system for loading assets locally while running in the editor, but it's a few years old:

    https://docs.unity3d.com/550/Documentation/Manual/AssetBundleFAQ.html

    Essentially this is advocating loading the assets locally when you're running in the editor to bypass the Asset Bundles entirely. Is this still considered the best practice for this use case? I can't find any reference to it in the latest documentation.
     
  2. rchapman

    rchapman

    Joined:
    Feb 13, 2014
    Posts:
    105
    So for what it's worth, this code fixes up the shaders in this case. Not sure if this would be a recommended approach, but it's simple and it works. "obj" was just instantiated from an Asset Bundle.
    Code (CSharp):
    1.  
    2. #if UNITY_EDITOR
    3.                         var gameObj = obj as GameObject;
    4.  
    5.                         if (gameObj)
    6.                         {
    7.                             // If we're running in the editor, let's assume that the bundle was
    8.                             // targeting a different platform and try to fix up the shaders.
    9.                             var renderers = gameObj.GetComponentsInChildren<Renderer>();
    10.  
    11.                             foreach (var renderer in renderers)
    12.                             {
    13.                                 foreach (var mat in renderer.materials)
    14.                                 {
    15.                                     mat.shader = Shader.Find(mat.shader.name);
    16.                                 }
    17.                             }
    18.                         }
    19. #endif
    20.  
     
    orrinjones likes this.