The only timer (OR DELAY IDK) in the widget is somehow duplicated when this widget is spammable

hi. there is a very unpleasant bug with delay or timer idk in Unreal Engine 4.27 Blueprint.
In general, there are 2 buttons:

  1. the first opens the “Clicker”
  2. the second opens the “Market”
    The Clicker and the Market are two separate windows, the buttons of which are located on one common widget.

In the Clicker, before starting the game, there is a preset (part of the code), and then the second part of the code with the timer starting. These two parts are connected via a Retrigger Delay (1 second).

When you press the Clicker and Market buttons, they cover each other (the first button covers the Market, and the second button covers the Clicker, respectively).

(blue numbers are remained seconds)

The problem is that when you spam the buttons back and forth, the delay in Clicker doesn’t reset, but continues to work, causing the delay to trigger multiple times during spam, resulting in the counter subtracting numbers not in seconds as intended, but in 1 second, 2 seconds, 3 seconds, and so on, as the delay causes the counter to activate multiple times and overlap.

I could assume that the problem is that when you spam with buttons, the old clicker widgets are not deleted, which is why

I have a check to see if the Clicker or another is running.
Also. the timer clears when the Clicker is closed.
But for some reason, if I do a Print String, the timer event is triggered multiple times when I spam the buttons.
I’ve even tried blocking spam buttons (turning them off for a few seconds and then turning them back on), but it doesn’t work.
It’s very strange!

1 Like

Wow, I didn’t look at all that code, but I will mention, that you can’t use delays in for loops.

The moment the delay node is reached, the system will go onto the next item in the loop, and does not wait…

If it seems like a logical way to do things ( and you actually need a delay before the next loop item ), you can edit a copy of the for loop macro and put a delay in.

If you want the loop to continue, but also have the code after the delays to run, then you will need a more fancy system. Two methods for that are

1 Arrays of variables and timers

2 Spawning separate widgets with delays in each

The only delay and timer are in the Custom Event “StartBottleTimer”, which doesn’t have any loops. and it’s not called in a loop either. This is the problem, and I don’t see the exact cause of the bug.:rofl: :smiling_face_with_tear:

1 Like

A miracle has happened! I’ve fixed the bug, but there’s still a problem.

Well, now the timers don’t overlap, because originally, in Clicker, the click and remaining seconds variables were located in the parent widget, which meant they were shared among the duplicate timers, causing the timer on the screen to malfunction.
I’ve made the variables local within the widget, and now they’re not affected by other timers, and everything works as expected.

However, through Print String, it can be seen that the timers are still duplicated when the buttons are spammed, and my assumption is that the old Clicker widgets are not removed when switching, but remain functional but invisible.

How can I properly remove Children from parent widgets?

I have tried using a for each loop to Remove Children, as well as Clearing the array with Children and attempting to Remove all children. I have also attempted to Remove From parent in a loop.
However, none of these methods have yielded results, and I still see a collection of widgets in Print String.

they are removed just not destroyed until GC gets them, although its possible something like a timer prevents GC.

so what you want to do is create an event where you ‘clean up’ the widget before you remove it.

ie on Event Destruct ClearAndInvalidateTimer