# Issue with Loop Behavior in Niagara HLSL with CPU Particles

**URL:** <https://forums.unrealengine.com/t/issue-with-loop-behavior-in-niagara-hlsl-with-cpu-particles/1927567>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [July 5, 2024, 1:58pm UTC](https://forums.unrealengine.com/t/issue-with-loop-behavior-in-niagara-hlsl-with-cpu-particles/1927567 "2024-07-05T13:58:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loux\_xavier](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/loux_xavier/32/1201519_2.png) [@Loux\_xavier](https://forums.unrealengine.com/u/Loux_xavier)\
**Post date:** [July 5, 2024, 1:58pm UTC](https://forums.unrealengine.com/t/issue-with-loop-behavior-in-niagara-hlsl-with-cpu-particles/1927567/1 "2024-07-05T13:58:30Z")

</div>

Hello everyone,

I’m encountering a strange issue with a loop in my Niagara HLSL Expression, and I’m hoping someone can help me understand what’s going wrong.

I created a Dynamic Input that is used to set a parameter in the Particle Update section of my FX.

Here’s a simplified version of the code:

**Example 1**

```auto
int Num;
InteractionIndices.Length(Num); // Out 6

ReturnValue = Num;
// Here, ReturnValue is equal to 6, which is expected because InteractionIndices is an Array of 6 int32.

```

**Example 2**

```auto
int Num;
InteractionIndices.Length(Num); // Out 6

ReturnValue = -1;
for (int k = 0; k < 6; ++k)
{
    ReturnValue = k;
}
// Here, ReturnValue is equal to 5, which is expected.

```

**Example 3**

```auto
int Num;
InteractionIndices.Length(Num); // Out 6

ReturnValue = -1;
for (int k = 0; k < Num; ++k)
{
    ReturnValue = k;
}
// Here, ReturnValue is equal to 0, but I expected it to be 5.

```

In the third example, `Num` is supposed to be 6, just like in the first example. However, `ReturnValue` ends up being 0 instead of 5, which is confusing.

This happens only when the simulation target is set to CPU.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/5/5c5635367b1f61ec37232aaa3f32c4ef32e8c7da.png)

I also tried to set the `Num` value with a Length Node, an input parameter from Map Get, and a Make Int32. Only the Make Int32 Node works; for the others, I get the same problem.

I feel like Niagara HLSL with CPU does not support dynamic parameters in loop behavior. I searched the documentation but did not find any specific information specific to Niagara HLSL.

Any help would be greatly appreciated!

Thank you.

---

<div class="post-metadata">

**Author:** ![cAyouM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cAyouM](https://forums.unrealengine.com/u/cAyouM)\
**Post date:** [July 2, 2025, 2:38pm UTC](https://forums.unrealengine.com/t/issue-with-loop-behavior-in-niagara-hlsl-with-cpu-particles/1927567/2 "2025-07-02T14:38:49Z")

</div>

Hey @Loux_xavier, did you find a solution for that? I’m also struggling with this issue… Thanks!

---

<div class="post-metadata">

**Author:** ![Loux\_xavier](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/loux_xavier/32/1201519_2.png) [@Loux\_xavier](https://forums.unrealengine.com/u/Loux_xavier)\
**Post date:** [July 3, 2025, 1:39am UTC](https://forums.unrealengine.com/t/issue-with-loop-behavior-in-niagara-hlsl-with-cpu-particles/1927567/3 "2025-07-03T01:39:38Z")

</div>

Hey @cAyouM Sadly no 😕 For CPU FX I avoid to used HLSL now. I not tried it since.

---

<div class="post-metadata">

**Author:** ![cAyouM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cAyouM](https://forums.unrealengine.com/u/cAyouM)\
**Post date:** [July 7, 2025, 8:25pm UTC](https://forums.unrealengine.com/t/issue-with-loop-behavior-in-niagara-hlsl-with-cpu-particles/1927567/4 "2025-07-07T20:25:18Z")

</div>

In my case it doesn’t even work with GPU particles…were you able to make it work?

---

<div class="post-metadata">

**Author:** ![Loux\_xavier](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/loux_xavier/32/1201519_2.png) [@Loux\_xavier](https://forums.unrealengine.com/u/Loux_xavier)\
**Post date:** [July 11, 2025, 7:11am UTC](https://forums.unrealengine.com/t/issue-with-loop-behavior-in-niagara-hlsl-with-cpu-particles/1927567/5 "2025-07-11T07:11:51Z")

</div>

I not tried since
