Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice
  2. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

Performance issues on loading several scenes

Discussion in 'Project Tiny' started by SteveLawbirth, Aug 4, 2021.

  1. SteveLawbirth

    SteveLawbirth

    Joined:
    Nov 12, 2015
    Posts:
    8
    Hi.
    I have a complex project where I need to load and unload eight scenes (game levels).

    I noticed that as the levels progressed, FPS goes down, especially on mobile.
    Note that due to the project structure, there are some objects in the main scene, many within the scenes and the few entities that are instantiated are also always destroyed.
    The scenes are obviously loaded one at a time and the performance problem is not in a particular scene, if I load one of the last scenes first it works fine.

    Having said this,

    Doing a bit of research and debugging, I noticed that the number of entities increased every time I unloaded a level compared to the previous time.
    The only solution I was able to implement is the following:
    1. I take all the entities at the start of the game in a persistent native array
    2. Whenever I unload a level, I destroy all entities except the initial ones, some that have a particular component (Those that are in the main scene) and those that have LightingSetup component (It gives an error otherwise)
    In this way it seems that everything is working correctly, there are no drops in performance as before (tried without particles emitters)
    But particle emitters have a problem when I reuse them in the second level (Particle emitters stay in the main scene, emit rate changes during level)

    Code (CSharp):
    1. Uncaught RuntimeError: unreachable
    2.     at il2cpp::os::CrashHelpers::CrashImpl() (<anonymous>:wasm-function[12789]:0x234d5b)
    3.     at il2cpp::os::CrashHelpers::Crash() (<anonymous>:wasm-function[12783]:0x234bf0)
    4.     at tiny::vm::Exception::Raise(char const*) (<anonymous>:wasm-function[12755]:0x233207)
    5.     at tiny::vm::Exception::Raise(Il2CppException*) (<anonymous>:wasm-function[12756]:0x233249)
    6.     at Assert_IsTrue_m3C5A0F83FECD21D5195ABD90373471E8D8CA2A8D (<anonymous>:wasm-function[10775]:0x19bb3b)
    7.     at ParticleSpawnSystem_U3COnUpdateU3Eb__4_0_m581D0A39D2A86382F8ACF758DEF7EBCF6EEDFA21 (<anonymous>:wasm-function[10960]:0x1ab88d)
    8.     at U3CU3Ec__DisplayClass_OnUpdate_LambdaJob0_Execute_m163EADC35D9B784CC379F68EAFCEAC89F31C8881 (<anonymous>:wasm-function[10987]:0x1aeb2a)
    9.     at JobChunkExtensions_RunWithoutJobs_TisU3CU3Ec__DisplayClass_OnUpdate_LambdaJob0_tE45AC0DCF37BA34C1FA9795D6033933A5190D933_m5815B66E49519E9949DCCEAED3449E0EDEF5846B (<anonymous>:wasm-function[5369]:0xb1b8c)
    10.     at U3CU3Ec__DisplayClass_OnUpdate_LambdaJob0_RunWithoutJobSystem_m215B857CEF210D13261C8BEB6942914F442ADA5A (<anonymous>:wasm-function[10963]:0x1abd0e)
    11.     at JobChunkRunWithoutJobSystemDelegate_Invoke_mF3C01361028D5316B77E4B9CBF661776FB02446D (<anonymous>:wasm-function[10392]:0x184eb1)

    How can I fix this error?
    Or better yet, is there a more correct way to unload levels without remaining useless entities causing performance problems?
     
    Last edited: Aug 5, 2021
  2. dallin_unity

    dallin_unity

    Joined:
    Dec 18, 2019
    Posts:
    38
    Hi, can you tell me how you destroy all the entities? I tried to use
    SceneSystem.UnloadParameters.DestroySubSceneProxyEntities
    but still doesn't fix the problem
    Thanks for your help
     
  3. djsell

    djsell

    Joined:
    Aug 29, 2013
    Posts:
    77
    I don't remember doing anything other than unloading the scene. The trick was making sure everything was tagged with the right scene id. This meant anything spawned as part of a scene must be created with a prefab from the same scene. Meaning if you have a prefab in scene A and a spawner in scene B, you're not going to have the expected result if you destroy scene B as all the spawned things belong to scene A.
     
  4. dallin_unity

    dallin_unity

    Joined:
    Dec 18, 2019
    Posts:
    38
    Thanks for your reply
    I did unload scene before loading a new scene, I have no problem loading character customization scene and lobby scene, but after lobby scene, on ios mobile browser, instead of loading new scene, the entire page reload, I don't know why this happens, I think it has something to do with the unload function that doesn't do very well.
     
unityunity