Daily Unreal Column #89 - FScopedSlowTask
Following up on the previous post, this is another way to provide accurate feedback to your user whenever something is happening and its taking some time.
FScopedSlowTask is a structure that is very easy to use and provides great feedback to the user. It displays a progress bar with an optional message about what is currently happening. Let’s have a look at an example where we will be processing an array.
First thing we need to do is create a variable.
TArray<FSomeData> MyData;
FScopedSlowTask MyTask(MyData.Num(), FText::FromString("Processing data..."));
Notice that I defined an instance of the struct passing two parameters. First one, MyData.Num() defines how many units of work we are going to be processing. In our example, we will be processing array elements, so the number of units of work is equal to the number of the array elements. The second parameter is just a text that will be displayed on a progress bar.
Then, we just need to update the our task notifying it how many units of work we are planning to process at a given time.
for (int32 Index = 0; Index < MyTask.Num(); Index++)
{
MyTask.EnterProgressFrame(1.0f);
...
...
...
}
And that’s it. We don’t need to worry about notifying the task that we have finished processing because it will wrap things up itself as soon as it runs out of the scope.