UI Custom Shader disappears on Android when the application is sent on background

Hello everyone,

I am struggling to get my custom shader to work on Android. The shader is working well on PC editor, and on Android until the device send the application on background (during an ads display for example). The UI canvas mode is on Overlay mode and the shader was created with ShaderGraph Sprite Unlit.
This problem has occurred on several Android devices.

I am using Unity 2020.3.23f1 on URP.

Many thanks for your help!

Apologies for bumping an old thread, but I was having the same issue and thought I’d share my workaround for anyone else who’s googling. (I’m using Unity 2021.3.3f1)

In my case, my custom Shadergraph-made UI shaders were disappearing whenever OnApplicationFocus(false) event occurred - eg when the keyboard was opened, or the mediapicker was opened.

Using the generated shader code, I went through and I deleted out any sections that seemed more relevant to 3D surfaces. To be safe, I saved & checked it in Unity after each bit, but definitely make sure you make a backup copy first. There were some bits I deleted & then had to immediately undo.

Examples of the bits I ended up removing:

#define ATTRIBUTES_NEED_NORMAL
#define ATTRIBUTES_NEED_TANGENT
#define ATTRIBUTES_NEED_TEXCOORD0
#define ATTRIBUTES_NEED_COLOR
#define VARYINGS_NEED_POSITION_WS
#define FEATURES_GRAPH_VERTEX
#define SHADERPASS SHADERPASS_SPRITEUNLIT

#if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
#endif
#if (defined(UNITY_STEREO_INSTANCING_ENABLED))
uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
#endif
#if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
#endif

#if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
#define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN                output.FaceSign =                                   IS_FRONT_VFACE(input.cullFace, true, false);
#else
#define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
#endif
#undef BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN