How do you make a float array param in Shader Graph?

In Unity, in a Shader Graph, there is a dropdown to add params as seen in the attached image. Nowhere here is there an option that lets you create arrays, which is a very basic feature of any shader language. I see there is an option to pass in a Texture, and this can be used as a hacky workaround, but using a texture as an array has huge drawbacks:

  1. the complexity involved in having to deal with precision, texture widths/heights, converting array indices into a 2d uv index, worrying about the ranges ofthe uv and the texture, and other pointless complexity burdens.
  2. a Texture2D inherently is just going to be an array of vector4s, but maybe the shape of your data awkwardly fits into a vector4 for whatever reason.
  3. the readability is trash. It’s confusing to everybody that you are using a full texture just to store some floats.
  4. reuploading a texture every frame to the GPU has more overhead than simply uploading a float array

I need to simply have a float array. Again, in every shading language this would be trivial. I come from a GLSL and WGSL background where creating an array buffer of floats is as simple as creating a single float buffer. It would frankly be shocking and absurd if Unity could not do this.

So how do you do it?

note, “upgrading” to the built in pipeline from URP allows you to do this, and it is pretty easy to create float arrays in an HLSL script

I believe you can declare an array using a dummy CustomFunction node (include an HLSL file, not inline code), like:


float YourArrayProperty[8];

void DummyFunc_float(out float Out)
{
 Out = 1;
}
void DummyFunc_half(out half Out)
{
 Out = 1;
}

Just remember to connect the “Out” value to something (like a multiply by 1). This will prevent ShaderGraph removing the node.

Im unsure if this would make your Shader non SRPBatcher-compatible, as this property will be outside the UnityPerMaterial CBuffer

Thank you for the response. Hopefully this will help somebody. I am unable to verify that this works because I have already upgrade back to the build in render pipeline from the URP.

I suspect that this missing functionality is a far greater pain point for Unity users than what they realize, otherwise it probably would have already been implemented into URP.