First, please note Unity Issue Tracker - Materials lose reference to textures if loaded from Asset Bundles this shows this same issue happening, and then said it was fixed in 5.1, then nearly every version after, for years now, people have been replying to that saying it is still happening in later versions. I.e. setup an asset bundle, add the prefabs/materials, and when the object loads, it is missing the shader, either going pink all together, or only using the albedo color.
I just setup a system in the most basic way, importing materials, gameobjects, etc, and it happened to me. The fix was literally to put in a function like this after loading.
private void ResetMaterials(GameObject go)
{
foreach(var renderer in go.GetComponentsInChildren<Renderer>())
{
foreach(var m in renderer.materials)
{
m.shader = Shader.Find(m.shader.name);
}
}
}
Which literally just replaces the shader reference, and in this case, everything is using the standard shader.
It is a little frustrating to come across this every year or so, and to come across this but that says its fixed, with pages and pages of responses saying its not, and no way for us to say “NO, that bug is not fixed, or has come back.”
- Don’t get me wrong, I appreciate the site/services, but please don’t give us a channel to get updates on fixes, and then ignore it once you think its fixed.
I have my code resolved for now with this code, but the problem is clearly still around.