[5.8] Substrate: "Material information is invalid" when a Static Switch input goes through a Named Reroute to a non-first output of a Material Function

Summary

With Substrate enabled, a material logs “Material information is invalid” on load, and cooking fails, when all of the following are true:

  • Front Material is fed by a Static Switch (or Static Switch Parameter / Quality Switch / Shading Path Switch)
  • One of the switch inputs goes through a Named Reroute (or a regular Reroute)
  • That reroute points to the second or a later output pin of a Material Function, and that pin is a Substrate output

The material compiles and renders correctly in the editor, so the problem only appears in the log on load and as a cook failure.

What Type of Bug are you experiencing?

Rendering (Graphics / Niagara)

Steps to Reproduce

  1. Enable Substrate in Project Settings.
  2. Create a Material Function with multiple outputs, in this order:
    • Output 0: Scalar (e.g. “Opacity”)
    • Output 1: Scalar (e.g. “AO”)
    • Output 2: Substrate material (e.g. from a Substrate Slab BSDF)
  3. In a material, add a call to that function.
  4. Add a Named Reroute Declaration connected to output 2 (the Substrate output).
  5. Add a Static Switch. Connect A (True) to any Substrate BSDF, and B (False) to a Named Reroute Usage of the declaration from step 4.
  6. Connect the Static Switch to Front Material, then save.
  7. Reopen the editor and load the material (or run a cook).

Expected Result

No error. Output 2 of the function is a Substrate material.

Observed Result

On load, the material logs:

LogMaterial: Error: : Material information is invalid.

The material compiles and renders correctly in the editor viewport. However, cooking fails with “Cook failed” and ExitCode=25 (Error_UnknownCookFailure).

UMaterialExpressionStaticSwitch::IsResultSubstrateMaterial (MaterialExpressions.cpp) follows the Named Reroute to the Material Function Call, but checks the reroute’s OutputIndex (0) instead of the traced OutputIndex (2). So it checks the wrong output pin and returns false. The same pattern exists in StaticSwitchParameter, QualitySwitch and ShadingPathSwitch.

Affects Versions

5.8

Platform(s)

Windows

Additional Notes

Suggested fix: use the traced input’s OutputIndex instead of the original input’s OutputIndex.

const FExpressionInput TracedA = A.GetTracedInput();
const FExpressionInput TracedB = B.GetTracedInput();
if (TracedA.Expression && TracedB.Expression)
{
    return TracedA.Expression->IsResultSubstrateMaterial(TracedA.OutputIndex)
        && TracedB.Expression->IsResultSubstrateMaterial(TracedB.OutputIndex);
}

The same change is needed in GatherSubstrateMaterialInfo and in:

  • UMaterialExpressionStaticSwitchParameter
  • UMaterialExpressionQualitySwitch
  • UMaterialExpressionShadingPathSwitch

Substrate nodes such as UMaterialExpressionSubstrateHorizontalMixing already use the traced input’s OutputIndex, so they work as expected.

Workaround: connect the Material Function output directly to the switch input, without a reroute, or make the Substrate output the first output (index 0) of the function.