Enabling subsurface scattering mode in HDRP/Lit from Editor script

I am attempting to set Material Type from “Standard” to “Subsurface Scattering” via an Editor script in an existing material, but I am having no luck.

This is what I want to set:

Code I’ve tried:

material.SetFloat("_MaterialID", 1.0f);
material.SetFloat("_TransmissionEnable", 1.0f);
var diffusionProfile = AssetDatabase.LoadAssetAtPath<DiffusionProfileSettings>("Assets/Settings/HDRPDefaultResources/SkinDiffusionProfile.asset");
HDMaterial.SetDiffusionProfile(material, diffusionProfile);
material.EnableKeyword("_MATERIAL_FEATURE_SUBSURFACE_SCATTERING");
material.EnableKeyword("_MATERIAL_FEATURE_TRANSMISSION");
HDMaterial.ValidateMaterial(material);

Debug.Log("Subsurface is: "+material.IsKeywordEnabled("_MATERIAL_FEATURE_SUBSURFACE_SCATTERING"));

Debug.Log is false! (and the material is still “Standard” material type in Inspector)

Thanks for any help!

I’m still struggling with this. Does anyone have any ideas for directions to explore? It seems the best workaround might be to programmatically copy an existing material with SSS enabled and modify from there.

I think you have to validate/compile the material before the changes take effect.

https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@13.1/manual/Material-API.html

edit: nvm you already did that I just missed it.

the material ID for subsurface scattering is 0, and in general for other types, it’s the index of the entry in the dropdown list (so 1 is ID for type Standard)
Following code should work

material.SetFloat("_MaterialID", 0.0f);
material.SetFloat("_TransmissionEnable", 1.0f);
HDMaterial.SetDiffusionProfile(material, diffusionProfile);
HDMaterial.ValidateMaterial(material);