# Why does this code get stuck during play?

**URL:** <https://forums.unrealengine.com/t/why-does-this-code-get-stuck-during-play/1884698>\
**Category:** UI\
**Tags:** User-Interface, unreal-engine, UI, Widget, question, Blueprint\
**Created:** [June 1, 2024, 11:38pm UTC](https://forums.unrealengine.com/t/why-does-this-code-get-stuck-during-play/1884698 "2024-06-01T23:38:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bartex\_music](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bartex_music/32/1012837_2.png) [@bartex\_music](https://forums.unrealengine.com/u/bartex_music)\
**Post date:** [June 1, 2024, 11:38pm UTC](https://forums.unrealengine.com/t/why-does-this-code-get-stuck-during-play/1884698/1 "2024-06-01T23:38:12Z")

</div>

This right here is a small bunch of code that I made in 5 minutes to try and power an ‘advertisement board’ on my Main Menu UI with the use of a Common Animated Switcher. (A widget switcher that has animation transition functionality that’s available with the Common UI plugin.) It changes ‘advert’ every 5 seconds by adding 1 onto the Active Widget Index variable then resetting to 0 when the number is 3, the last widget.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/f/9/4f94b2fface325de20d452c031c804d3528e8cf0.png)

For some reason this code gets stuck at integer 2. It goes from integer 0 to 1 to 2, then just repeats 2.  
I did a logical visual review of the code, backtracking the decision making of the programme and it looks like it makes perfect sense. Why is this happening?

Any fixes are appreciated.  
Thank you!

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [June 2, 2024, 7:48am UTC](https://forums.unrealengine.com/t/why-does-this-code-get-stuck-during-play/1884698/2 "2024-06-02T07:48:59Z")

</div>

Quite possibly because you have it on tick. Tick is EVERY frame… 🙂 ( delays don’t do anything on tick ).

---

<div class="post-metadata">

**Author:** ![Nightwolf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightwolf/32/917179_2.png) [@Nightwolf](https://forums.unrealengine.com/u/Nightwolf)\
**Post date:** [June 2, 2024, 10:06am UTC](https://forums.unrealengine.com/t/why-does-this-code-get-stuck-during-play/1884698/3 "2024-06-02T10:06:01Z")

</div>

> [@bartex\_music](#):
>
> For some reason this code gets stuck at integer 2. It goes from integer 0 to 1 to 2, then just repeats 2.

Programs start numbering at 0  
so what you would call my first screen or 1 is actually 0,

> [@ClockworkOcean](#):
>
> ( delays don’t do anything on tick ).

Retrigerable delays 🙂

But more on the off by one issue you may be having  
if you have 3 images the == should be 2 ( because that’s the 3rd position from computers pov )

Might i suggest also checking out these useful videos and the whole channel as well

[Event Tick](https://www.youtube.com/watch?v=-QvPxp138qQ&ab_channel=LeafBranchGames)  
[Why not to use Delay](https://www.youtube.com/watch?v=YVW74JSRhuA&ab_channel=LeafBranchGames)

You may be able to adapt this to your delay node if you so wished and not use the Timeline, theres also other ways of making timers that are better than this.. but if you ever plan to animate it or something this timeline method could come in handy  
Change Ad

 ![Screenshot 2024-06-02 045522](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/9/b89e70b3f649711d9d3d2f9b8aad57e47c25263b.png)

Setup Timeline

 ![Screenshot 2024-06-02 045755](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/a/1/aa112cbfe33e33bb60f5223b1cdb0f93653ea396.png)

Set the Length in the timeline to however often you want it to change ADs  
 ![Screenshot 2024-06-02 050003](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/c/40c2addb45d753b534f23ac55be7c9bb64a84cb8.png)
