- Home /
AssetBundleManager Shaders broken?
I’m working on an app which contains a main game and several minigames as well. I’m trying to separate the mini games each into their own asset bundle and store them on our server. I’ve downloaded Unity’s AssetBundleManager plugin for this task.
Each minigame is it’s own scene and I’ve built the asset bundles by allowing the AssetBundleManager to automatically select the dependencies. I’m building for iOS and I’ve uploaded the bundles to a server. Once I’ve built the game for my device (iPad 2) I load the assets using a script very similar to what’s included in LoadScenes.cs. It seems to download the assets and open the scene just fine.
The problem is that I believe many of my shaders are broken at this point. The terrain in one scene is broken and the standard shader also seems to not work in some instances. I’m seeing a few parts where the mesh is invisible and other parts where the mesh is that pink colour you see when the material doesn’t have a texture.
In the editor, I’ve tried opening the same scenes after downloading from the server and although they were broken at first, I was able to fix them by simply adding the relevant shaders to my “always included shaders” and rebuilding the assets. When they didn’t work I was able to see the correct textures and shader name in the inspector window on an impacted model. When I reselected the shader, the model loaded fine.
I also should point out that everything works fine on my iPad 2 when I load these scenes normally and not from an asset bundle I am trying to get my build size down though.
Answer by _creatio_ · Dec 14, 2015 at 07:20 PM
Looks like your problem appears because you are using the same set of shaders for all your materials. At the AssetBundles build time, you have to move them into a separate AB which will be a dependency for all the other ABs and will have to be loaded prior to all the other asset bundles and assets.
I'm a little hesitant to go ahead and download a new copy of all of Unity's default shaders, reapply them to every mesh, then separate that out into it's own asset bundle. I understand that it's a best practice to avoid doubling up on the assets but I'm not really making the connection to it fixing my issue.
All of these are default shaders. The gun, and the arms both use the same shader...
@glenwatkinson, you will not have to reapply anything dynamically. You just have to download the AB with shaders (and load it), prior to instantiation of the objects, that are in your current AB. Everything will link automatically.
Just a guess. The issue appears because the instances of the shaders with the same internal IDs prevent them from instantiation for the second time (as same ID is already appears used), during the load time of the AB, and it breaks loading sequence.
@_creatio I didn't mean to imply anything about writing a script to dynamically link shaders at run-time. In a perfect world I'd like to just leave the shaders on the main build and have all the asset bundles link from there. Ins$$anonymous$$d, it seems I have to download a new copy of the Unity default shaders, create a new asset bundle from them, change the textures in my $$anonymous$$igame asset bundles to reference the new copies of the shaders, then set the shader bundle as a dependency for my $$anonymous$$igame asset bundles.
I think your guess is absolutely correct btw.
@glenwatkinson, yes, Unity is not ideal, but it works :) Btw, I've used the described scenario in my game, so it works for sure. I'm not sure if there are any other way to do it better.
Answer by glenwatkinson · Dec 15, 2015 at 08:57 AM
While I'm sure that conflicting shaders is what caused my problem, I'm able to get everything to look fine by unchecking "Strip Engine Code" in the build settings.
Your answer
Follow this Question
Related Questions
AssetBundles - depend on asset already included in executable 0 Answers
Loading GameObject with the Script Attached from the AssetBundle. 0 Answers
Addressable Assets Cache 0 Answers
Missing shader variants/features in asset bundles 2 Answers
Asset Bundle Prefabs missing textures & materials, but have geometry 1 Answer