This package is not for everyone. Threads are very difficult to use in Unity since you cannot directly access any of the objects in your scene from any external thread. Think about that for a moment, if you switch to another thread then the only things you can easily do on another thread are file reads/writes, data processing, and any networking that doesn’t use the www object. That’s not a very long list. If you’re just looking to move an object across the screen do not use threads to do that! Unless your object is moving according to some very complicated logic threads will only slow things down and introduce potential errors.
In order to get around the limitation where you can’t access objects in your scene from an external thread there are two main structures that you can implement. Saving the current state of the game to disk in the background is an excellent application for MEC Threaded. You can also use MEC Threaded for swarming.
In order to save your game in the background using this plugin you would
- Start a MEC coroutine
- Serialize the data that you need to save into a local variable
- Switch to an external thread
- Perform the file IO
In order to implement swarming you would
- Run a MEC coroutine in a while loop that executes the following steps every frame
- Read the current position of the object(s) that you are operating on into a local variable
- Switch to an external thread
- Perform calculations on the data that you read and save the results to a local variable
- Switch back to the main thread
- Update the position of the object(s) based on the value stored
An example implementation of both of these structures are included in the project.