unity is crashing when i press play button (fixed)

hi guys. when i press “play” button, my unity wait for 1 minute. increases the ram from %60 to %95 and then it is crashing. can anyone tell me why :smile:. it is happend 4 times only today. and i updated the unity yesterday. (btw my ram is 8gb)

edit: i increased my virtual ram. still crashing

edit2: when i press play button size of unity in ram is increasing from 500mb to 6 gb - lol -

edit3: when i undo changes in my project thanks to collab, it is fixed. idk i only added some box colliders to some prefabs. :smile:

edit4:
i can’t do changes that i want. i just added box colliders to my prefabs (prefabs are roads in my game). according to collider’s size, the prefabs will be added end to end. so i will obtained an endless map.

when i changed the script file (road maker) it is not crashing. when i added the colliders and pressed play button the game is crashing as i said above (look at the edit3).

the first script file: http://txt.do/1pkb2
the second (last) script file: http://txt.do/1pkbv
i just changed these parts:
transform.GetChild(0).transform.localScale.z
to
GetComponent().bounds.size.z

pls help me guys.

edit: i fixed it. i was should use GetComponent().size.z

You’ve got While loops which I suspect are running thousands of passes each frame for every instance of this script, assuming they reach their exit condition at all. Plus you’re doing Instantiate and GetComponent inside these loops. You could potentially be running millions of Instantiate calls within just minutes.

Add some Debug.log statements there. This just doesn’t look right to me at all. Not something that should be in an Update call.

So first thing you should do is verify you are actually reaching the exit condition within all your While loops, within the number of loops you expect. Assuming you always do, you need to figure out how many of these GetComponent and Instantiate calls you’re actually doing every frame. These are slow calls (well GetComponent is pretty quick, if you’re dealing with a pretty small number), so if it is a large number you should head back to the drawing board.