Stopping FQueuedThreadPool threads when ending the game?

Asked this on the answer hub a couple of days ago, but since I didn’t get any response there I figured I’d try my luck here.

I’m doing some threaded work, and I’m having difficulty when stopping the game while the threads are still busy. They continue to run after clicking stop, causing the editor to crash when they try to reallocate TArrays (all related pointers are still valid at this time). I tried stopping the threads in Destroyed() on the owning actor, but this doesn’t get called in time.

What’s the proper way of ending worker threads on game end, or checking if the game has ended in these threads?

Thanks!

Sooo, the solution was using EndPlay() instead of Destroyed(), which doesn’t seem to get called at all on the actor when pressing stop in the editor.

For future reference: Actor Lifecycle | Unreal Engine Documentation