Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug unity is crashing when i press play button (fixed)

Discussion in 'Editor & General Support' started by nostklay, Sep 17, 2020.

  1. nostklay


    Aug 19, 2020
    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 :D. 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. :D

    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:
    the second (last) script file:
    i just changed these parts:

    pls help me guys.

    edit: i fixed it. i was should use GetComponent<BoxCollider>().size.z
    Last edited: Sep 18, 2020
  2. Joe-Censored


    Mar 26, 2013
    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.
    Last edited: Sep 17, 2020