How to update TMP Pro Sprite Shader using script/C#?

I am using a custom Shader for my TMP Fallback sprites which are emojis. I want to change a value on the shader dynamically based on user input. If I pause my game in the editor and change the value in the UI it works, but in c# the change is never displayed. Here is what I have tried:

var subMesh = GetComponentInChildren<TMP_SubMeshUI>();
subMesh.material.SetFloat("_GrayscaleAmount", 0f);

I’ve also tried fallbackMaterial, creating a whole new material and setting that, subMesh.SetMaterialDirty() and subMesh.RefreshMaterial() and text.ForceMeshUpdate on the parent TextMeshProUGUI object.

The shader values work great when I update them in the UI, it only seems to be via script that they don’t get re-rendered.

Any ideas? Thank you!

You should try to use subMesh.sharedMaterial instead of subMesh.material