I made a prefab to be instantiated in game.
But because I wish it to be instantiated "behind the scene", which means, create all those multiple copies of prefabs "while the player is doing something else".
So I put the code generating the prefab "in another thread".
But the Unity told me that "Load can only be called from the main thread."
I tried to move the code into a coroutine, but unfortunately coroutine runs in the "main thread"!
Or maybe I should say, they don't do multiple coroutines "parallely and concurrently"!
So could somebody please be so kind and teach me what should I do!?
Much appreciated!
Codes: (In case needed, even though I don't think it would do any good)
void Start()
{
Thread t = new Thread(Do);
t.Start();
}
private void Do()
{
for(int i=0;i<1000;i++)
{
GameObject RaceGO = (GameObject)(Resources.Load("Race"));
RaceGO.transform.SetParent(Content);
}
}
Resources.LoadAsyncResources.Loadfrom a thread or run it on a thread. Most of Unity's API can only be used in the main thread. You should change the title because this is the answer to your title actually ;)