Widgets not updating until full completion of C++ loops

Hello,

I am having a problem with my widgets apparently not updating at the correct time. I will describe below my intended behavior and what I am currently seeing.

The problem I am currently having involves a calendar user widget where I simulate through the days on the calendar. When a day completes, it is marked as complete by becoming “greyed out” and depending on certain events that may or may not occur on that day, other text is added to the day box.

Current behavior:
The problem I am having is that when simulating through stretches longer than a day, the code completely finishes then the widget will update at that point. So if I simulate 10 days, it won’t grey out those 10 days one by one, but all at once when my code is completed.

Wanted behavior:
If I simulate through 10 days, or a whole year, I want the widgets to update as they are completed.

I think my code is correct, as in the order of the updates - the code structure generally looks like this

  1. Click a button on the widget to start the simulating.
  2. In C++, code runs that begins the simulation. When I simulate more than one day, this means that a while loop is used, which decrements the amount of days left to simulate as it goes.
  3. Inside the while loop, when a day is completed, an event delegate is called that results in a function call on my calendar widget (in blueprints) to update the day as completed.
  4. Steps 2-3 continue to occur until the days left to simulate have completed.

When I add breakpoints to my calendar widget inside the function that is called when a day is completed, the editor obviously pauses. During this pause my behavior is as intended! I can see each day greyed out as they go. But this is the only time it works as intended where I want the days to update as they are completed, rather than all at once when the code is finally completed.

I’m wondering if it has something to do with the event delegates and if they are essentially completed last once the rest of the code is completed, but when using breakpoints it allows any accumulated to complete. I’m not sure about this though, because in that case the widget blueprint functions would not have their breakpoint hit until every day in the loop completed. I am also wondering if it has something to do with all of this executing on one thread, but I don’t know much about that.

This isn’t anything gamebreaking, but I would eventually like to be able to have the user click a button to stop the simulation if they notice something occur. As it stands, you click “simulate all” and there is no chance to stop halfway in. (If I could figure out this bug/behavior, I could theoretically add some type of boolean in the while loop simulation that would exit if the user wished).

I found a workaround that works for me!

Instead of using a while loop, when I complete the simulation of a day, I check against a boolean to see whether I should recall the “Simulate Day” function. Essentially still a while loop, but not in form. Furthermore, I also use a timer to call the “Simulate Day” function. I’m guessing that the completion of the code + widget update is allowed to complete while the timer waits to be called.