Unity interthread communication.

Hey all,

I am processing some data on a separate thread (position data read asyncrously from a socket). However, I need to act on this data on the main thread (a game object’s transform can only be accessed from themain thread).

The approach I have in mind is to create a thread-safe queue and follow the producer-consumer pattern. The thread would queue the position data and the main thread would deque the data and act on it. Is there a better approach? If there isn’t, what is the best way to inform the main thread when data is queued? It seems inefficient to poll, is continously checking in a coroutine and yield return 0 if there’s no data be my best option?

Thanks in advance.

Just an FYI, I ended up creating a thread-safe queue and pumped the socket data into it on one thread while removing and acting on the data on the main thread. - multithreading - Interthread communication - Stack Overflow