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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question How smooth load a lot of gameobjects?

Discussion in 'Scripting' started by starock2020, Mar 31, 2023.

  1. starock2020

    starock2020

    Joined:
    Sep 14, 2020
    Posts:
    89
    Hi~

    My game is a open world. So here a lot of gameObjects and models will load at runtime.

    I load them use coroutine. But still laggy(low FPS).

    Is here any method could improve ths load processing?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,470
    Are you sure the lag is because of the loading? Usually the bottleneck is more because there are too many objects on screen.
    Did you check the profiler?
     
  3. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    490
    Is it laggy after the objects have initially loaded in or is it just during the initial load? If it's just during the initial load you could implement a loading screen to wait on things to load.

    Here are some options that can help cut down load time and processing:
    • GPU Instancing
    • Static Batching
    • Occlusion Culling
    • Fewer lights, as each light causes each material it's illuminating to have an additional shader pass.
    • Fewer colliders, as each collider causes more physics checks.
    • Using layers, CompareTag, and Physics.IgnoreCollision in combination to cut down on collision checks.
    • Fewer materials.
    • More simple shaders. Eliminate parts of shaders that aren't being utilized.
    • Fewer objects.
    • Fewer meshes.
    • More simplified meshes. Utilize tools such as the Mesh Optimizer asset or Blender's Decimate modifier.
    • Fewer uses of GetComponent. Pre-cache components when possible.
    • Pre-caching of transforms and gameobjects if they're used in scripts. Each call to .transform or .gameObject is more processing time.
     
    starock2020 and DevDunk like this.
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,588
    other alternatives:
    - asset store has some world streaming plugins
    - can use DOTS subscenes (unity megacity demo is in github and uses it)
    - can load regular scenes with additive async *but certainly still noticeable lag when object gets created(?) especially with large meshes with colliders..
     
    starock2020 and DevDunk like this.
  5. starock2020

    starock2020

    Joined:
    Sep 14, 2020
    Posts:
    89
    Thank you!