Hello Guys. So I’m trying to delete my FAsyncTask after it has completed, but I’m not able to find any documentation specifying how.
I previously used a FAutoDeleteAsyncTask, but had to switch to a normal FAsyncTask since I needed a way to make sure that the current task was done before creating another one. As far as I know there’s no way to do this on FAutoDeleteAsyncTask, but FAsyncTask has the “IsDone()” function which is very useful.
I have found code examples where they do a:
if (MyAsyncTask->IsDone())
{
delete Task;
}
But I get an error saying that ‘Task’ is an undeclared identifier.
Any help regarding this would be much appreciated!
Best Regards,
-Sven
Edit: doing “delete MyAsyncTask;” crashes the game.
Hi, thanks for the reply! That could also work:) The workaround I found was to use MyTask->EnsureCompletion(false); before deleting MyTask.
EnsureCompletion() pauses the GameThread until the task is fully completed. IsDone() seems to return true before all the memory allocations have been fully freed up, causing the crash.
EnsureCompletion() can cause lag in the game though if done for multiple finishing tasks or during an active task. So I limit my code to only use it once per frame and I’ve put it inside of a “if(MyTask->IsDone())” statement like previously.