Skip to content

Instantly share code, notes, and snippets.

@DanMillerDev
Last active March 16, 2025 19:59
Show Gist options
  • Save DanMillerDev/62364c3540b07edb568bf9b02a46b2a9 to your computer and use it in GitHub Desktop.
Save DanMillerDev/62364c3540b07edb568bf9b02a46b2a9 to your computer and use it in GitHub Desktop.
A script for changing the shader type of materials at runtime. In this example we're changing to use a custom occlusion shader required on AndroidXR and Meta Quest platforms for depth based occlusion.
using UnityEngine;
using System.Collections.Generic;
public class ShaderTypeManager : MonoBehaviour
{
[SerializeField]
List<Material> m_MaterialsToChange;
void OnEnable()
{
Shader targetShader;
#if UNITY_VISIONOS
targetShader = Shader.Find("Universal Render Pipeline/Lit");
#elif UNITY_META_QUEST || UNITY_ANDROID_XR
targetShader = Shader.Find("Occlusion/OcclusionLit");
#endif
for (int i = 0; i < m_MaterialsToChange.Count; i++)
{
m_MaterialsToChange[i].shader = targetShader;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment