MaterialInstance UsedWith flags

Our artists would like to work with base materials that contain a lot of static switches, and be able to apply the material instances across a wide range of mesh types (meaning they want to tick a lot of UsedWith flags).

Currently, UsedWith flags are only on UMaterials, so whenever a MaterialInstance is created with a static parameter set, it generates a lot of shaders that might not actually be needed. For example, the MaterialInstance might only be used on ParticleSprites, but not Beams or Mesh Particles.

Have you thought about allowing Material Instances to have their own UsedWith flags? Would the work involved be much more difficult than changing MaterialShared.cpp so that the FMaterialResource::IsUsedWith* functions check the MaterialInstance member before falling back to the Material?

The closest thing I can think of that will allow you to do this is using a material parameter collection to set values that negate effects that they dont want. All materials who use this parameter collection will be affected so by setting a single material parameter collection you can see changes in all materials.

For example, make a scalar called useMatA. Set it to zero. Inside the material make the nodes for both materials.

Multiply the material A with the value from useMatA and multiply the material B with 1-useMatA. Then blend the two.

Now you can set the variable useMatA to 0 or 1 in BPs to flip between the two materials. You can even use material functions in the multiplications.

HTH