AR Foundation shader error when using URP

Yo, I’m using the latest URP package (7.1.8) & AR Foundation (3.1.0. preview.4). I was using LWRP for my current project and now after migrating to URP when I build my project for iOS platform, this error appears which prevents me from building successfully:

Shader error in ‘Unlit/ARKitLWRPBackground’: failed to open source file: ‘Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl’ at line 41 (on metal)

Compiling Vertex program with ARKIT_HUMAN_SEGMENTATION_ENABLED
Platform defines: UNITY_NO_DXT5nm UNITY_NO_RGBM UNITY_ENABLE_REFLECTION_BUFFERS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 SHADER_API_MOBILE UNITY_HARDWARE_TIER2 UNITY_LIGHTMAP_DLDR_ENCODING

This shader file is located at “Packages/com.unity.xr.arkit/Assets/Shaders/ARKitLWRPBackground.shader”.

TEMPORARY SOLUTION:

I know this shader requires lines 40 & 41 to change to:
40: #include “Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl”
41: #include “Packages/com.unity.render-pipelines.universal/ShaderLibrary/Color.hlsl”

and then unity builds for iOS successfully. I don’t like this solution because sometimes this shader file resets and I have to rewrite those two lines again and sometimes it happens really often.

*** So my questions are:

  • What triggers that annoying reset of this shader file?
  • Is there another (stable) way of updating this shader file so that is plays with URP nicely?

What package version are you using for com.unity.xr.arkit? I’m using 3.1.0 preview and the ARKitLWRPBackground shader and ARKitURPBackground shader are listed separately and therefore causes no issues.

If you are versioned locked a temporary solution could be to create a new shader instance of the ARKitLWRPBackground shader and update the lines like you did above and assign the new shader.

My ARKit XR Plugin has version 3.1.0 preview 4 - same as ARFoudnation. I even have both LWRP and URP vesions of this shader but only the LWRP version causes issues as shown on the image below:

Can I get rid of it somehow? since reimporting didn’t help…

You can remove it from the packages folder in your library cache but this is not ideal. Interestingly enough I have almost the exact setup as you and this error doesn’t stop me from building. Could you share your console of the build error?

Yes, well I’ve noticed sometimes it is problematic but when I click “Build” button again with no changes to my project and it suddenly builds with absolutelly no problem, can you explain this to me please since I have absolutely no clue what is going on

I get this same error only when selecting the shader. Remember that the versions we are using for ARKit plugin and AR Foundation are in preview.

Therefore there may still be some bugs and things needing addressing.

This issue never inhibits me from building so for now it’s probably best left ignored or can be removed from the project at:

Project Root ->Library ->PackageCache → com.unity.xr.arkit@3.1.0-preview.4 ->Assets ->Shaders->ARKitLWRPBackground

My guess is it was left in during the upgrade process of LWRP to URP and just needs to be deprecated/removed.

You can raise with Unity if you’d like…

Final solution I got used to is to just open the Unlit/ARKitBackground shader file and remove entire #elif ARKIT_BACKGROUND_LWRP block of code.

1 Like

I’m still experiencing this issue, with all of the latest versions of ARKit, ARFoundation, XRPluginManagement etc. I’ve tried the “verified” versions all the way up to the latest and they all contain this issue. I can’t modify the packaged code, because I’m using CI and it needs to check out the project fresh each time. What can I do here? I’m not sure why the code still includes references to packages that were deprecated a long time ago…

I’m not sure what to do. So far I was always able to double click the error in Unity console which opened the shader file from where I’ve removed that code.

Is it in your ‘always included shaders’ by chance? (Project Settings → Graphics).
It sounds like it is being referenced somewhere.

No it’s not referenced there in fact, when I navigate inside Unity’s project window to Packages/ARKit XR Plugin/Assets/Shaders and double click on that shader it opens no problem in my Visual Studio, maybe you need to link external IDE to unity in order to open it?

So it seems like my project builds for XCode even with this error in the logs.

I had to fix another error however, which was:

Shader 'Universal Render Pipeline/Particles/Lit': fallback shader 'Universal Render Pipeline/Particles/SimpleLit' not found
Looking inside Library/PackageCache/com.unity.render-pipelines.universal@10.3.2/Shaders/Particles/ParticlesLit it has this line: Fallback "Universal Render Pipeline/Particles/SimpleLit" but the name of the Shader is actually Shader "Universal Render Pipeline/Particles/Simple Lit" (with a space)

To patch this I just made a copy of that file, and changed the shader name to remove the space.