Reputation: 705
My game has a home scene and two game scenes (SceneA & SceneB). Editor freezes when moving from Home Scene to SceneA with SceneManager.LoadScene().
So, I checked the code of SceneA. Then I noticed that the editor was frozen in one place.
The following code is for scene A.
//SceneA Script
[SerializeField]
float range;
[SerializeField]
GameObject obj;
void Start()
{
Spawn();
}
void Spawn()
{
for (int i = 0; i < 99; i++)
{
Instantiate(obj, new Vector3(Random.Range(-range, range), 0.5f, Random.Range(-range, range)), Quaternion.identity);
}
}
If I remove Spawn(), it will not freeze. But I need to create 99 obj objects. Suddenly it started to freeze even though it was done a while ago.
Also, SceneB was loading normally until this problem occurred, but now when you try to SceneManager.LoadScene(SceneB) after this problem, it freezes.
Is this a Unity bug? Is the player setting involved? The reason that SceneB cannot be read is that there is a problem with terminating the editor task when it freezes in SceneA?
I'm really in trouble because I don't see any errors. somebody help me please.
Upvotes: 0
Views: 451
Reputation: 705
I caused this problem by one small mistake. Perhaps this question is useless for others who get Unity frozen by SceneManager.LoadScene().
My failure:
There was a mistake in the script for objects created by Instantiate().
//freeze code
void Start()
{
StartCoroutine("Load");
}
IEnumarator Load()
{
yield return new WaitFOrSeconds(2);
while(true)
{
//Something heavy processing
}
}
It is natural to freeze.
Upvotes: 0