Best approach for asynchronous file loading on Desktop

Hi,

I was wondering… I’m writing the umpteenth runtime file importer in my Unity development life. What’s the best/recommended approach nowadays for asynchronous loading and feedback?

Usually I add three UnityEvents: onImportStarted, onImportProgress, onImportCompleted. Then I’m able to hook basically anything into the loading process.

onImportProgress might pass a percentage float, or the absolute current value and the absolute target value (e.g. 5/23 files read; 2.345/45.000 vertices read)

onImportCompleted might pass the GameObject if it was an object that I loaded; or the JSON converted data object

But now about the asynchronous importing… for example for reading a stream line by line

  • Threaded loading? With a Coroutine polling for changes?

  • async and await, Task and Task?

  • Use a Coroutine?

I’m looking forward to your answers.

Wavy

What I tend to do if I need to do anything threaded always check if the job system can handle it first. If not, I tend to go the Task or Task route with awaits etc, sometimes using TaskFactory.

Also Task is threaded so what do you mean by “threaded loading” compared to the second point? And coroutines are neither threaded nor asynchronous. They simply yield execution to allow other bits to execute before resuming again for a bit. All main threaded.