How do I fix runtime "Failed to compile Material Instance" and "Building adjacency information"?

I’ve had many of these in my logs since day one when I load new levels:



Warning: Warning, Failed to compile Material Instance
Log: Building adjacency information for static mesh


I never really bothered with them because the game seemed to run fine. But now I think that the attempted runtime compiling of material instances is really hurting performance. Any idea why these are happening and how I can stop it?

Yeah, it takes about 6 seconds each time the game tries to compile a material instance at runtime. I have a level that has 4 of these in them. It spends 24 seconds trying and failing to compile material instances, then it saves LocalShaderCache-PC-D3D-SM3.upk. How do I stop that?

have you opened the editor and fully load all your games assets. That should compile all your material shaders for you and save them. Then the waiting should go away.

Yeah, I did that. I found out it actually leaves the same warning in the log when I try compiling the materials in the editor.

I’ve also spent the last two days fruitlessly chasing the warning deeper into C++. UMaterialInstance::CacheResourceShaders to UMaterial::CompileStaticPermutation to FMaterial::CacheShaders to FMaterial::Compile to FMaterial::CompileShaderMap to FMaterialShaderMap::Compile. I don’t know C++ very well, but what it seems like is happening right now is



UBOOL FMaterial::CompileShaderMap()
{
    return OutShaderMap.Compile(); // returns FALSE
}

UBOOL FMaterialShaderMap::Compile()
{
    // do stuff
    return TRUE;
}


It sounds as if it is a material causing it. Does it say anything about certain materials? Can you watch the log or console as its compiling and try to see whats compiling and where and when it errors? maybe you can figure out what textures causing it. Sounds like a material is not made quite right.

Yes, there were some specific materials that were not compiling. I know which materials were having the problem, but I don’t know what the problem was. Eventually I removed some features of the materials and brought their instruction count down to about 210, whereas they had been around 240 before. Now they seem to be working. They don’t quite match the other materials now, but at least they are compiling and saving, so they don’t have to recompile every time the player loads a level.