Multithreading for unity iphone feasible ?

Greetings all,

Looking for some advice on a performance related topic. I have very low load times and I have an app that is very similar to a car garage in a racing game a. la project gotham etc....

One of the things I am doing to help the load out is that I do a heavy setup cost on the Start() call of a bunch of models. The cost of this function is significant and depending on which part is turned on the load hit for turning on the model for the first time can be anywhere from 1-5 seconds. This isn't the biggest deal but it would be nice to have an animated waiting state for the few seconds instead of a static pause.

With any other engine I would normally just put this load work onto its own thread, and have the app 'locked' until the thread returns with the work done. How feasible is this in unity ?

Can I do carPart.gameObject.SetActiveRecursively(true)... such that its Start() call on the scripts are in their own thread ??

1 Answer

1

You can use System.Threading, but no Unity functions are thread-safe, so you can only use thread-safe Mono functions. This is still good for heavy calculations, since those generally don't involve Unity-specific functionality anyway. You can use System.Math instead of UnityEngine.Mathf, or use your own functions (for example, see here for various Lerp replacements that are faster than the built-in ones anyway).