Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

modify Always Included Shaders with Pre processor?

Discussion in 'Unity Cloud Build' started by CDF, Dec 20, 2017.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    739
    Hi, so I've been racking my head around a bug recently. Videos suddenly stopped working on Android devices and it was because of a missing shader: "Hidden/VideoDecodeAndroid". It seems like Unity automatically adds this to the "always included shaders" list in the Graphics settings on the desktop app. However, cloud build is not the case.

    The issue arose because of changing platforms. I changed to iOS which removes the shader from the always included list. Pushed my changes to the repo and build for all platforms on cloud. Then Android complaining that it couldn't find the correct video shader.

    So I'm wondering, how can I tell Unity to always include this shader for Android on Cloud Build?
    I can't seem to find any Editor class that defines this.

    For now my solution is to switch to Android (locally) before pushing changes to the repository. Kind of a pain, especially now I'm using asset bundles.
     
  2. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    115
    Code (CSharp):
    1. public static void AddAlwaysIncludedShader(string shaderName)
    2. {
    3.     var shader = Shader.Find(shaderName);
    4.     if (shader == null)
    5.         return;
    6.  
    7.     var graphicsSettingsObj = AssetDatabase.LoadAssetAtPath<GraphicsSettings>("ProjectSettings/GraphicsSettings.asset");
    8.     var serializedObject = new SerializedObject(graphicsSettingsObj);
    9.     var arrayProp = serializedObject.FindProperty("m_AlwaysIncludedShaders");
    10.     bool hasShader = false;
    11.     for (int i = 0; i < arrayProp.arraySize; ++i)
    12.     {
    13.         var arrayElem = arrayProp.GetArrayElementAtIndex(i);
    14.         if (shader == arrayElem.objectReferenceValue)
    15.         {
    16.             hasShader = true;
    17.             break;
    18.         }
    19.     }
    20.  
    21.     if (!hasShader)
    22.     {
    23.         int arrayIndex = arrayProp.arraySize;
    24.         arrayProp.InsertArrayElementAtIndex(arrayIndex);
    25.         var arrayElem = arrayProp.GetArrayElementAtIndex(arrayIndex);
    26.         arrayElem.objectReferenceValue = shader;
    27.  
    28.         serializedObject.ApplyModifiedProperties();
    29.  
    30.         AssetDatabase.SaveAssets();
    31.     }
    32. }
    Code (CSharp):
    1. AddAlwaysIncludedShader("Hidden/VideoDecodeAndroid");