Assetbundles containing materials do not build correctly for other platforms

We recently updated our project from Unity 2022 LTS to Unity 6000.1.1f1. Our Assetbundle pipeline script builds for both Windows and Android, and has always worked fine. Recently we found that only the active build platform (that is, the one selected in the Build Profiles menu) correctly builds Materials into the Assetbundle.

This means that if you, for example, specify BuildTarget.Android while the Unity project is set to Windows active build target, the materials/shaders (even default URP Lit) in that bundle will fail to render on Android and vice versa. This did not used to be the case, and the documentation indicates that it shouldn’t be, given that it allows a built target to be specified other than the active build platform.

This can be easily reproduced by building a bundle with a simple prefab with a cube and a material using the default URP shader, and targeting a platform other than the one currently in use. Upon load, the GameObject will be present but the cube will be invisible (i.e. appearing that the shader was not compiled).

I assume this is an engine bug? Did some quick searching and couldn’t find anything about it even thought I suspect it must be a common use case so I’m wondering if there is something we’re missing. Thanks.

Hey Jake,

Thanks for this - I’ve just chatted through it with our engineering group & we agree that it sounds like a bug. Would you be able to submit a small repo project through the bug reporter and I’ll make sure we get an engineer looking into it.

I’m wondering if it’s a bug with the build-profiles system rather than AssetBundles but we’ll see!

Hi, I’ve just gone ahead and sent a bug report from within the Editor under this account. I included a small sample project with reproduction steps that uses code snippets from Unity’s docs. Please let me know if there are any questions/updates on this bug. Thanks!

Hey Jake,

Thanks very much! I appreciate it requires effort on your part, and I’m sure I speak for our dev team in saying really appreciate it <3

Someone from QA will give it a repo, and then send it over to me and the team - looking forward to taking a look!

Thank you! I am really surprised that this issue is not more widespread as we have 100% reproduction of it across multiple Unity 6 versions and machines within our team. For anyone else having this issue, here is a workaround we are using for the time being:

During our build process, we use EditorUserBuildSettings.SwitchActiveBuildTarget just before building the asset bundle to switch the Editor to the platform in question. This can be done multiple times synchronously as each platform is built, so while it does add some unnecessary time to the build it does not add any additional manual steps to the process.

We’ve repo-ed using your project / instructions - thanks for your help, Jake!

Hi. Is this the relevant issue that’s affecting Assetbundle invisible - New Plugin API - Rising World ?

The game uses Unity 6000.0.60f1.

Me and another person concluded that it might be a Unity 6 issue that broke it and not the game code itself.

I tried everything from a custom shader. The ONLY thing that worked was re-assigning the texture and material in runtime using plugin code. It doesn’t apply the material automatically.

Let me know if this is a known issue or a game issue, I’m also waiting for some response from the game devs.