# Sending an array (of structs) to a usf shader

**URL:** <https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601>\
**Category:** Rendering\
**Tags:** unreal-engine, Rendering, Shaders, hlsl, question, CPP\
**Created:** [November 27, 2016, 6:30pm UTC](https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601 "2016-11-27T18:30:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_c8cdff6f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c8cdff6f](https://forums.unrealengine.com/u/anonymous_user_c8cdff6f)\
**Post date:** [November 27, 2016, 6:30pm UTC](https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601/1 "2016-11-27T18:30:26Z")

</div>

I’m trying to send an array of positions (and other info) to a usf pixel shader.  
I know I can send `float`, `FMatrix`, `FVector` stuff to the shader via the following macros:

`BEGIN_UNIFORM_BUFFER_STRUCT(FMyPixelShaderVarParams`

`DECLARE_UNIFORM_BUFFER_STRUCT_MEMBER`

`DECLARE_UNIFORM_BUFFER_STRUCT_MEMBER_ARRAY`

- Can I send an array of floats to this FMyPixelShaderVarParams struct? - Yes, by using `DECLARE_UNIFORM_BUFFER_STRUCT_MEMBER_ARRAY(float, varName, [10])`

- Can I send a custom struct inside this FMyPixelShaderVarParams struct? - NO? What exactly makes FVector struct eligible and mine not?

- Can I send an array of structs inside FMyPixelShaderVarParams? - Same

---

<div class="post-metadata">

**Author:** ![panha](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@panha](https://forums.unrealengine.com/u/panha)\
**Post date:** [March 28, 2017, 2:44pm UTC](https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601/2 "2017-03-28T14:44:08Z")

</div>

Hi, I’m trying to figure how to send 4x4 Matrix from C++ to usf shader. Any idea how can I achieve this?

---

<div class="post-metadata">

**Author:** ![Anonymous\_c0b2ef1d8b6296d661f82020eeaf73de](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/anonymous_c0b2ef1d8b6296d661f82020eeaf73de/32/742521_2.png) [@Anonymous\_c0b2ef1d8b6296d661f82020eeaf73de](https://forums.unrealengine.com/u/Anonymous_c0b2ef1d8b6296d661f82020eeaf73de)\
**Post date:** [April 26, 2018, 4:28am UTC](https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601/3 "2018-04-26T04:28:25Z")

</div>

uniform buffer may can help you,but i also don’t konw how to send uniform buffer corectly.this is my questionhttps://answers.unrealengine.com/questions/783475/%E5%A6%82%E4%BD%95%E7%BB%99shader%E4%B8%8A%E4%BC%A0uniformbuffer.html

---

<div class="post-metadata">

**Author:** ![Anonymous\_c0b2ef1d8b6296d661f82020eeaf73de](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/anonymous_c0b2ef1d8b6296d661f82020eeaf73de/32/742521_2.png) [@Anonymous\_c0b2ef1d8b6296d661f82020eeaf73de](https://forums.unrealengine.com/u/Anonymous_c0b2ef1d8b6296d661f82020eeaf73de)\
**Post date:** [April 26, 2018, 9:33am UTC](https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601/4 "2018-04-26T09:33:38Z")

</div>

## However,when i finish

BEGIN\_UNIFORM\_BUFFER\_STRUCT(FMyUniformStructData, )  
DECLARE\_UNIFORM\_BUFFER\_STRUCT\_MEMBER(FVector4, ColorOne)  
DECLARE\_UNIFORM\_BUFFER\_STRUCT\_MEMBER(FVector4, ColorTwo)  
DECLARE\_UNIFORM\_BUFFER\_STRUCT\_MEMBER(FVector4, ColorThree)  
DECLARE\_UNIFORM\_BUFFER\_STRUCT\_MEMBER(FVector4, ColorFour)  
DECLARE\_UNIFORM\_BUFFER\_STRUCT\_MEMBER(uint32, ColorIndex)  
END\_UNIFORM\_BUFFER\_STRUCT(FMyUniformStructData)

## IMPLEMENT\_UNIFORM\_BUFFER\_STRUCT(FMyUniformStructData, TEXT(“FMyUniform”));

the code won’t work! HLSL compiling failed.

---

<div class="post-metadata">

**Author:** ![Anonymous\_45c7af3adcc306c2cea2bef1bc45ad57](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_45c7af3adcc306c2cea2bef1bc45ad57](https://forums.unrealengine.com/u/Anonymous_45c7af3adcc306c2cea2bef1bc45ad57)\
**Post date:** [October 30, 2018, 4:18pm UTC](https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601/5 "2018-10-30T16:18:49Z")

</div>

4.20: Update to  
#define UNIFORM\_MEMBER\_ARRAY\_EX(MemberType,MemberName,ArrayDecl,Precision)  
#define UNIFORM\_MEMBER\_ARRAY(MemberType,MemberName,ArrayDecl)  
#define UNIFORM\_MEMBER(MemberType,MemberName)  
#define UNIFORM\_MEMBER\_EX(MemberType,MemberName,Precision)  
#define UNIFORM\_MEMBER\_SRV(ShaderType,MemberName)  
//#define DECLARE\_UNIFORM\_BUFFER\_STRUCT\_MEMBER\_UAV(ShaderType,MemberName)  
#define UNIFORM\_MEMBER\_SAMPLER(ShaderType,MemberName)  
#define UNIFORM\_MEMBER\_TEXTURE(ShaderType,MemberName)  
#define UNIFORM\_MEMBER\_STRUCT(StructType,MemberName)

---

<div class="post-metadata">

**Author:** ![blackfr8er](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blackfr8er](https://forums.unrealengine.com/u/blackfr8er)\
**Post date:** [December 26, 2023, 2:46pm UTC](https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601/6 "2023-12-26T14:46:42Z")

</div>

AOS seems still not available for uniform buffer, I tried to create a `SHADER_PARAMETER_STRUCT` and reference it in a `GLOBAL_SHADER_PARAMETER_STRUCT`, but got crash on ` CreateHLSLUniformBufferStructMembersDeclaration`

---

<div class="post-metadata">

**Author:** ![Santaiko](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santaiko](https://forums.unrealengine.com/u/Santaiko)\
**Post date:** [November 20, 2024, 3:46pm UTC](https://forums.unrealengine.com/t/sending-an-array-of-structs-to-a-usf-shader/377601/7 "2024-11-20T15:46:25Z")

</div>

Hi.  
I need to do something similar but I dont have much experience on coding usf files, I have coded on custom nodes(btw its a pain) and I am also starting with c++ but still not much.  
I just have some doubts.

Firstly I supose that this uniform arrays/buffers can only be set up on usf files or can also be on the normal bluprint editor?

Do i need to do mayor changes to the unreal shaders to implement them, or is it just a normal usf file that can be called on a material?

(Not necesary but…) do you have some basic steps or small guide on how to set up this?(c++ or preferedly bluprint if it can be done)

Some forums say to set up a render target and loop on it in material but that doesnt feel right and more like a workaround for this uniform buffers, so I wanted to know more about them.  
Thanks in advanced
