# How to limit how far a ++ or -- function can go?

**URL:** <https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519>\
**Category:** Blueprint\
**Tags:** unreal-engine, question\
**Created:** [October 1, 2025, 8:01pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519 "2025-10-01T20:01:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soaron](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Soaron](https://forums.unrealengine.com/u/Soaron)\
**Post date:** [October 1, 2025, 8:01pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/1 "2025-10-01T20:01:20Z")

</div>

I have a music track switcher function that works like this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/f/d/3fd9e6438dc7c60edb08a4b8d94c0df10fa90ba0.png)

The music list looks like this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/8/a/68af4f2dfba491f55229bab855440145e8bd3740.png)

Works well, but unfortunately, if I keep pressing ‘next’ track, it will go on forever, and each button press registers a ‘next track’ even though it doesn’t exist after 5. So when you want to go back to a previous track, I have to press as many times as I pressed next until it actually goes back to the previous track.

I added a CLAMP INTEGER function to be 0-5 before the ++ and – but that didn’t work. How do I hard-limit the range so the ‘next’ and ‘prev’ buttons stay within 0-5?

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [October 1, 2025, 8:13pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/2 "2025-10-01T20:13:13Z")

</div>

You could use the wrap (integer) node to wrap around the values once you hit the max.

---

<div class="post-metadata">

**Author:** ![Soaron](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Soaron](https://forums.unrealengine.com/u/Soaron)\
**Post date:** [October 1, 2025, 8:55pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/3 "2025-10-01T20:55:07Z")

</div>

thank you for that! you rock! this is how I ended up:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/b/5/0b5025e691b8b7ebcfb73db91575b81514f54f0d.png)

worked like a charm!

---

<div class="post-metadata">

**Author:** ![nande](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nande/32/1057698_2.png) [@nande](https://forums.unrealengine.com/u/nande)\
**Post date:** [October 1, 2025, 9:33pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/4 "2025-10-01T21:33:49Z")

</div>

i think if you wanna clamp it, there could be something like max and min or clamp.

---

<div class="post-metadata">

**Author:** ![Rev0verDrive](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rev0verdrive/32/907214_2.png) [@Rev0verDrive](https://forums.unrealengine.com/u/Rev0verDrive)\
**Post date:** [October 1, 2025, 10:36pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/5 "2025-10-01T22:36:40Z")

</div>

I’d go with Clamp. Wrapping literally wraps. If the input value exceeds the maximum, the value “wraps around” from the beginning of the range.

For example, if the range is 0-100 and the input is 101, the output is 1. If the input is 110, the output is 10.

0-5 … 5.2 = 1, 8.0 = 3

---

<div class="post-metadata">

**Author:** ![nande](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nande/32/1057698_2.png) [@nande](https://forums.unrealengine.com/u/nande)\
**Post date:** [October 2, 2025, 2:12am UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/6 "2025-10-02T02:12:23Z")

</div>

thanks, understanding the diff between clamp and wrap is important.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [October 2, 2025, 6:15am UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/8 "2025-10-02T06:15:58Z")

</div>

In the case of music though going to the next track after the last logically would go to the first track again, otherwise you would constantly be playing the last track once you hit it.

I think context of the situation would suggest a loop, as it mirrors how digital music players work when shuffle is disabled.

---

<div class="post-metadata">

**Author:** ![Rev0verDrive](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rev0verdrive/32/907214_2.png) [@Rev0verDrive](https://forums.unrealengine.com/u/Rev0verDrive)\
**Post date:** [October 2, 2025, 8:18am UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/9 "2025-10-02T08:18:54Z")

</div>

I was just defining Clamp over Wrap. Personally I’d conditional check the Track and manually set as needed.

Next: If (Track == 5) { Set Track 1 } Else { Increment (Track) }  
Prev: If (Track == 1 ) { Set Track 5 } Else { Decrement (Track) }

---

<div class="post-metadata">

**Author:** ![Soaron](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Soaron](https://forums.unrealengine.com/u/Soaron)\
**Post date:** [October 2, 2025, 6:48pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/10 "2025-10-02T18:48:37Z")

</div>

I appreciate the detailed look into this. For me both options are good to understand and think about. I might have to use clamp sometime anyway. And yes, @3dRaven the wrap worked nicely here because it does mimic the way digital players work 📀

---

<div class="post-metadata">

**Author:** ![RedGrimnir](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/redgrimnir/32/1054683_2.png) [@RedGrimnir](https://forums.unrealengine.com/u/RedGrimnir)\
**Post date:** [October 2, 2025, 8:21pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/11 "2025-10-02T20:21:14Z")

</div>

Just wanted to drop this , exactly stepper logic like mentioned above.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/6/9/469c6be330d03c6f2d4a67b1865a2c4e1b5c31e0.png)

You can just change function in the end to play a new track on loop or set parameter to cue.

---

<div class="post-metadata">

**Author:** ![Rev0verDrive](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rev0verdrive/32/907214_2.png) [@Rev0verDrive](https://forums.unrealengine.com/u/Rev0verDrive)\
**Post date:** [October 2, 2025, 10:47pm UTC](https://forums.unrealengine.com/t/how-to-limit-how-far-a-or-function-can-go/2661519/12 "2025-10-02T22:47:41Z")

</div>

You can go even further by putting the code in a function and providing an input of Fwd/Bwd to control switch logic.
