Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Why is SetVectorArray only setting first index in compute shader?

Discussion in 'Shaders' started by keromonkey, Dec 14, 2021.

  1. keromonkey


    Jan 16, 2019
    Hello all,
    I need to draw a large amount of moving objects, each of which has its own position and a target that is shared between groups of them.

    All objects are rendered with Graphics.DrawMeshInstanced successfully.

    Code (CSharp):
    1. Graphics.DrawMeshInstancedIndirect( Mesh, 0, Material, bounds, argsBuffer, 0);

    I've written a custom compute shader to move these objects.
    I pass in a small VectorArray of Vector4 positions (which I then constantly update right before compute shader dispatch), but it only seems to take the first value.

    This issue seems similar to this one here, but using a compute shader I can't set anything to "gpu instanced" to fix it (I tried with the material that draws the objects but not change).

    Have I missed something, or is compute.SetVectorArray() buggy in Unity2021.2 hdrp?

    EDIT (12/14/21): It turns out the SetVectorArray is being set correctly, its just not being indexed correctly for some reason. (I tested it by using explicit indices)...

    EDIT (12/14/21): Resolved. The issue was the data in the C# struct wasn't in the same order as the data in the compute shader struct :pepoblanket:
    Last edited: Dec 14, 2021