Description

Calling UStaticMeshComponent::GetMaterial() during a Blueprint compile on load can cause the Material shader to fail to compile because GetMaterial will trigger a PostLoad call on that Material and cause it to be loaded in an order the Editor doesn't expect. Material Instances for that material that failed to compile will show the default world material in the viewport and in content browser thumbnails until the Material Instance is opened up or RECOMPILESHADERS CHANGED is run.  If the the game is cooked before the materials are fixed they will show as the world grid material in game also.

Steps to Reproduce
  1. Create a custom FKismetCompilerContext on a UBlueprint type and a Blueprint that uses it with bRecompileOnLoad=true
  2. Inside PreCompileUpdateBlueprintOnLoad reference a material on a static mesh component:

 

    if (Blueprint->SimpleConstructionScript)
    {
        for (USCS_Node* Node : Blueprint->SimpleConstructionScript->GetAllNodes())
        {
            if (auto StaticMeshComponent = Cast<UStaticMeshComponent>(Node->ComponentTemplate))
            {
                for(int i=0; i < StaticMeshComponent->GetNumMaterials(); ++i)
                {
                    auto Material = StaticMeshComponent->GetMaterial(i);
                }
            }
        }
    } 

Expected

Materials shaders compile correctly and Material Instances don't use the default world material

Actual

Some Material shaders will not compile correctly because UStaticMeshComponent::GetMaterial() will trigger a UMaterial::PostLoad() call and cause the Material to be loaded in an order the Editor does not expect.  Material Instances for that material that failed to compile will show the default world material in the viewport and in the content browser thumbnail render until the Material Instance is opened up or RECOMPILESHADERS CHANGED is run.

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-226715 in the post.

0
Login to Vote

By Design
CreatedOct 4, 2024
ResolvedOct 7, 2024
UpdatedOct 21, 2024
View Jira Issue