Search Unity

modify Always Included Shaders with Pre processor?

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

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    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:
    117
    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");
     
  3. Deleted User

    Deleted User

    Guest

    It's kind of annoying that this happens automatically because it means you either exclude QualitySettings from your versioning tool, or you live with keeping these file changes around in your uncommitted changes list...
     
  4. victorw

    victorw

    Joined:
    Sep 14, 2016
    Posts:
    459
    This issue should also replicate when running a build in Batchmode so the best way to resolve this in the long term would be if you could test that out and then report this as a bug using Help -> Report a Bug in the Editor.
     
  5. NameOfTheName

    NameOfTheName

    Joined:
    May 13, 2020
    Posts:
    2
    well do
    well done!