Home > Mobile >  Instantiate Freezes Unity Game
Instantiate Freezes Unity Game

Time:05-03

I am having trouble with unity freezing every time I run my game. My game right now is very simple. I found out that my game freezes when I run this code:

void Start () 

     {
        for(float i = -10.5f; i < 10.5; i  ){
            for(float l = -10.5f; l < -0.5; l  ){
                Instantiate(prefab, new Vector3(i,l,-0.2f), new Quaternion(0,0,0,0));
            }
        }
        
     }

What I am doing here is generating an array of my prefab(a grey sprite) into my scene. From my research if something is not running it is because there is something overloading or there is an infinite loop going on. Whenever I run it, in order to continue working I need to use task manager and end task. Any help is appreciated, thanks!

Update: Found out that is the instantiate if that can help any problem solvers.

CodePudding user response:

I think the code code that you write has no problem at all.

I copied your code and run in empty scene and it works well.

(I assigned default Cube gameobject in variable prefab)

I guess there is some problem in script that you are going to instantiate.

CodePudding user response:

sorry everyone, I think I had assigned the script to the prefab soooooo that was an issue lol.

  • Related