Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make background thread in unity3d

I have wp7 app whith two background threads: 1. Planing of time 2. Play different sound samples by planed time (Possible few samples in same time).

How to repeat this logic whith unity3d engine? Is it possible?

like image 525
xander27 Avatar asked Jun 19 '26 14:06

xander27


1 Answers

Unity will not allow you to access its APIs from any thread other than the main one; you can't use locking primitives to get around it.

You can use the standard .NET threading APIs to start threads that do not interact directly with the Unity API, though. You could calculate samples and buffers on an extra thread, but your main thread would have to call AudioClip.SetData to submit the calculated samples to Unity.

Note that since Unity 2018.1, the Job System has been introduced which allows certain kinds of computation tasks to be performed on background threads (for example, setting transform positions). The tasks that can be performed are being gradually opened up over time.

like image 125
Superpig Avatar answered Jun 21 '26 14:06

Superpig