Reputation: 17397
I'm writing a plugin for a game called Rust using a modding framework called Oxide. I'm wondering if I need to be concerned about synchronization in my plugin. Are all scripts in unity (C# or otherwise) executed on the same thread?
Upvotes: 2
Views: 1372
Reputation: 2383
Yes, they're all executed on the main thread, in fact unity really doesn't like it when you try to do things off the main thread. Any Unity3D specific calls you make (anything in any of the Unity namespaces) must be executed on the main thread otherwise you will get potentially very vague errors, and when errors do occur outside of the main thread unity will not report them and will not provide a stack trace.
They way most people get around mutlithreading with Unity is to create a MonoBehaviour object that starts the processing that doesn't involve unity directly in another thread, then store it in the MonoBehaviour object when its done. The MonoBehaviour object can then check each update to see if the data it needs is ready for it to make unity specific calls with, and then do so if it is ready.
Upvotes: 2