Uniforms from custom function not working

Hi,

Unity: 2019.3.f12
HDRP: 7.3.1

I am trying to declare some uniforms from a custom function node, so I can later use them in different shader graphs. I have many shader inputs repeating in all graphs so I want to define them in source which will use all of them to output just a few colors.

According to the docs for Custom Function Node this should work. However I have problems. To test, I have created a custom function with one color uniform.

float4 colorU;

void get_tex_float(out float4 color) {
    color = colorU;
}

I create two spheres and assign them the same material but with different values for the color in the custom function. One is read the other is green. But while rendering they always have the same color, sometimes red and sometimes green. Here is how I set the colorU uniform.

        shader = Resources.Load<Shader>("shader");

        var mat1 = new Material(shader);
        mat1.SetColor("colorU", Color.red);
        GameObject.Find("Sphere1").GetComponent<MeshRenderer>().material = mat1;

        var mat2 = new Material(shader);
        mat2.SetColor("colorU", Color.green);
        GameObject.Find("Sphere2").GetComponent<MeshRenderer>().material = mat2;

It works if I define all variables in the shader graph UI and use them w/o declaring the uniform, but this still requires creating them in all graphs, just eliminates the need to connect them to the custom function. Not really an option form me however.

A workaround is to set some keyword (does not actually exist in the shader) to one of the shaders.

mat2.EnableKeyword("asd");

I managed to pass StructuredBuffer and correctly read random data from it in the shader code.
Not sure what causes this behavior and how stable it is to rely on this workaround.