How to pass an array of floats to vfxgraph

This took a little time to figure out, so I thought I’d share a quick code example.

void Start() {
sizes = new float[11];
sizesTexture = new Texture2D(sizes.Length, 1, TextureFormat.RFloat, false);
vfx.SetTexture(Shader.PropertyToID("Sizes"), sizesTexture);
}

void Update() {
//update the "sizes" array of values every frame here
sizesTexture.SetPixelData<float>(sizes, 0);
sizesTexture.Apply();
}

In the Update Particle block of your graph, create a block similar to this image:

6873587--802370--setsizefrommap.jpg

Hey @DylanF ,

Thanks for sharing! You may be also interested to know that work has been done on adding Graphics Buffer support for the VFX Graph, which will hopefully be available in 2021.2. This would allow you to pass a lot more data to the VFX graph from code without having to rely on textures.

Any advice on how to actually access the buffer using VFX?

https://discussions.unity.com/t/849663

https://discussions.unity.com/t/862147