I’m trying to override a boolean parameter in a material instance in an editor plugin.
Texture parameters can be overridden without problems with SetTextureParametervalueEditorOnly, but…
there’s no such thing for boolean parameters.
I’ve tried the following by looking at PreviewMaterial.cpp, and it does update the UMaterialInstance in VS’s watch window, but doesn’t get reflected in the final version that gets saved it seems… What am I missing?
bool testBool = false; // throwaways for checking purpose
FGuid testGUID;
if (sourceMaterial->GetStaticSwitchParameterValue(FName("WorldVertexTransition"), testBool, testGUID))
// do we have the switch bool?
{
// grab all material params, including those of the source
FStaticParameterSet updatedParams;
newMaterial->GetStaticParameterValues(updatedParams);
for (int paramIdx = 0; paramIdx < updatedParams.StaticSwitchParameters.Num(); paramIdx++)
{
if (updatedParams.StaticSwitchParameters[paramIdx].ParameterName == FName("WorldVertexTransition"))
{
// Flip the boolean to what we need and override it...
updatedParams.StaticSwitchParameters[paramIdx].Value = switchBlend;
updatedParams.StaticSwitchParameters[paramIdx].bOverride = true;
break;
}
}
// does this do anything? Doesn't seem so
newMaterial->bHasStaticPermutationResource = true;
// this does absolutely nothing, even though it should!
newMaterial->UpdateStaticPermutation(updatedParams, true);
// next one doesn't help either
newMaterial->ForceRecompileForRendering();
}
http://i.imgur.com/sLN2KTx.png
This is the material parameter I’m trying to adjust, and I’m totally okay with it needing to be recompiled or whatever if necessary.