Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Big Delay Between Scenes when generating GameObjects on the fly

Discussion in '2D' started by czzplnm, Aug 11, 2019.

  1. czzplnm

    czzplnm

    Joined:
    Jul 16, 2019
    Posts:
    28
    From my 'Main Menu' Scene to my 'Select Level' scene to my 'Game Level' scene I generate a lot of game objects on the fly and am experiencing quite a big delay when transitioning 10-30 seconds.

    My 'Select Level' scene generates 1,000 buttons being Level 1 to Level 1000 and places them in a Sliders content. On my phone from the 'Main Menu' to 'Select Level' this can be 30+/- seconds. Is it really that slow to generate Game Objects on the fly?

    The slider on this Scene is also very laggy on my phone.

    Also, the 'Game Level' scene will generate a random level based on the difficulty (level #) and this can be 10 +/- seconds also.

    Is there a better way to do this?
     

    Attached Files:

  2. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    410
    You appear to have pages set up with 5 levels (buttons) per page. Have you tried disabling all other pages except the active page? I don't know what else you have running in the background either that's eating memory. If you're not changing scenes, then you may not be destroying game objects. For all I know, you're constantly generating new content for same levels without destroying old used content? There are many possibilities, especially if you're using particle trails-noise or other memory hog functions.
     
  3. czzplnm

    czzplnm

    Joined:
    Jul 16, 2019
    Posts:
    28
    Well its a slider so there is only 1 page, but I can try and figure out what is visible and have those be 'Active' and all others inactive?
     
    MisterSkitz likes this.
  4. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    723
    Have you set up remote Player profiling yet? If you're developing on mobile, it will be a big help.

    I've noticed from profiling my own project that setting up a Canvas can take a while. I'm not familiar with why this happens, but I suspect that this is what is causing your hang. Another thought is that if there is a unique texture for each object, then loading the textures could take lots of time, but I'm guessing that isn't the case here.

    Have you tried using only 5 button objects and changing their content based on the current page number? I think we'll have a hard time justifying 1000 buttons for this.
     
    MisterSkitz likes this.