[HDRP] Dynamically change emission value

Hello everyone,
I’m using the Lit shader in HDRP and I would like to control the emission value in EV100 or Nits dynamically from a script.

I have a code which reads from a 0-1 curve and then multiplies the result to a value (so I can stay in a given range of emission). The code seems to work, if I look in the material I can see the value changing. However, the object emission in the scene doesn’t change accordingly. Is that normal?

The code goes like this:

_mat.SetFloat(Shader.PropertyToID("_EmissiveIntensity"),emissionIntensityCurve.Evaluate(Time.time)*emissionMultiplier);

I tried with different values, and the emission changes if I change them manually (even in play mode) but it seems that the script is ignoring it.

I’m facing the same problem. The solution is to use MaterialPropertyBlock and EmissiveColor instead of material.SetFloat

public Renderer targetRenderer;
[Range(0f, 1f)]
public float emissiveIntensity = 0f;
public Color baseEmissiveColor;
     
// You may want to alter this value depending on how intense you want your emissive strength to be
private const float MaxIntensity = 30f;
 
private MaterialPropertyBlock _propBlock;
 
private void OnEnable()
{
     _propBlock = new MaterialPropertyBlock();
}
 
// Update is called once per frame
private void Update()
{
     // Get Material Property Block from Material at first index on specified Glove Renderer
     targetRenderer.GetPropertyBlock(_propBlock, 0);
 
     _propBlock.SetColor("_EmissiveColor", baseEmissiveColor * Mathf.Lerp(0f, MaxIntensity, emissiveIntensity));
 
     // Update Material on specified Glove Renderer at first index of materials
     targetRenderer.SetPropertyBlock(_propBlock, 0);
}

I found the solution here
https://forum.unity.com/threads/hdrp-shader-change-in-build-lead-to-black-material.732350/#post-6094659