Does unity slow down the longer it is frozen?

Hi :slight_smile: I am a mac if it makes any difference…

Anyways, I have a bit of procedural generation code :slight_smile: It operates two iterations over sixty thousand vertex points, both of those operate intensely with many sets of math and also operate intensely with terrains. They take about 13 seconds to run, and then Unity unfreezes.

If I add ONE MORE iteration, which only does a tidbit of addition (basically, it removes about 6 faces from an array of 120,000 faces)(3 quads from an array of 60,000 quads so to speak), the run time immediately jumps to somewhere between five minutes and one hour (I was away from the computer for an hour and when I came back it was ready. Tested it again, and I waited about 5 minutes before giving up and shutting Unity down.

This doesn’t seem right… I added a very unintensive loop which should add only HALF of the total time (Note that the 13 seconds includes several other iterations that I have no control of and that I did not mention, which are responsible for doing noise calculations blah blah bla) but instead it multiplies my time by at LEAST 30 fold! This is very disturbing, and I am not sure how to get around it. I have tried c# multithreading, but that throws instantiation issues. I have also tried StartCoroutine, but I cannot use more than one method, as StartCoroutine does not support return values.

I’m stumped here, I really don’t know what to do. I can’t get the thing to run multithreaded so as to break up the frozen time, but not doing so seems to be fatal… I’m looking for a magic solution. A way to do some sort of multithreading, or a way to fix the utter LAG that I am encountering. Thankyou :slight_smile:

Start Coroutine may not support return values, but it does support the out-keyword for arguments. Define a function that returns IEnumerator and takes parameters that are modyfied with the out-keyword, and then set the parameters in the body of the Coroutine function. Then you can split this over several frames and get rid of the freezing.

If that’s not an option, and you really want to get to the bottom of what’s going on in your code to slaughter your runtime like that, you’re gonna have to post the code, I’m afraid. :-/ Then we can take a look at it together.