Search Unity

How to clean the cash which is created by app during game play?

Discussion in 'Scripting' started by bekiryanik, Jul 2, 2015.

  1. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Hello everyone,

    I have realized that i have a lag problem with my game when i restart the main game screen after the character dies. When the user of the game hit the "Restart" button, the button calls
    Code (CSharp):
    1. Application.LoadLevel("MainGame");
    and on second time of playing, game becomes little bit laggy. To prevent this situation, i have found this code
    Code (CSharp):
    1. Caching.CleanCache ();
    but it seems that this code didn't work on what i want to do with it. I think i need to clean the cash of the app if the restart button beign hit. How can i do that?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    are you using much of the WWW class to load in asset bundles? because that's what that function helps clean up. If you aren't it's not going to help you
     
  3. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    No i don't use any WWW class. So, how can i clean up the cash of the game on restart of the scene?
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    if you're not using the WWW class you don't have a cache to clean up... the issue must be elsewhere. Going to need to know a lot more about your project to help there.

    Have you used the profiler to see where the issues are? unity devs did a training video on it in the last week or so if you've not used it before, you'll find that on youtube and probably links somewhere in the teaching section.
     
    Kiwasi likes this.
  5. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    This is probably due to the garbage collector being called when you reload the level ( you are releasing a whole scenes worth of memory and then aquiring a lot of new memory) cant be helped to be honest. It should stop lagging when the GC finishes.
     
  6. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    I haven't use profiler before because of i don't have Unity Pro.

    I will look for running garbage collector correctly. This seems like a way to solve my lag problem.

    Thanks for your answers!