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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Performance and Static?

Discussion in 'General Discussion' started by James_Initus, May 31, 2018.

  1. James_Initus

    James_Initus

    Joined:
    May 26, 2015
    Posts:
    75
    Hi everyone, I had a questions regarding scene objects.

    I have about 2000 objects in a scene, all random variations of 10 different models (just larger or smaller, different rotations etc)

    What would be the most efficient way to load them in the scene?

    I've considered placing all 2000 under a single empty game object and made them all static (they wont be moving) - There is significant lag at startup
    I've placed them each by loading them from prefabs then instantiating them where they belong (works well no lag) and I have not added "static" to the object properties.

    Having so many variations of the same models, what way would you suggest I load them at the beginning of the scene?
     
  2. verybinary

    verybinary

    Joined:
    Sep 23, 2015
    Posts:
    373
    Maybe put up a "now loading" gui texture, load up your objects, and get rid of the loading screen?
     
  3. James_Initus

    James_Initus

    Joined:
    May 26, 2015
    Posts:
    75
    Well there is no loading screen at all, at the moment I just dropped all 2000 objects in the scene as static, I start the scene and there are some moments of lag.

    However if I load and instantiate each object, it seems to run fine and the objects are not static.

    Either way, instead of experimenting I was hoping I could get guidance on the best method to do so? any thoughts?
     
    Last edited: May 31, 2018
  4. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,605
    Don't instantiate all 2000 objects at a time then, from your findings, you've found that it causes lag. Do groups at a time or single ones at a time
     
  5. James_Initus

    James_Initus

    Joined:
    May 26, 2015
    Posts:
    75
    Hmm, I think I may have a different problem. So... the scene starts with none of the 2000 objects in view, the player object is in view, then the camera turns towards the objects and when that happens there is this immediate lag for a moment.. maybe 30 seconds of lag happening. The objects are low poly but higher textures, I imagine I could benefit from LOD models etc.. but the lag completely disappears after that initial time..
     
  6. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    2,980
    Consider using DrawMeshInstanced instead of 2000 game objects.
     
    landon912 and James_Initus like this.
  7. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,433
    Test this in a build on the target device, the editor and a final build might not have the same lag spikes. Unless it's game breaking and can't be somehow hidden (loading screen etc.) I would worry more about drawcalls and framerate than the initial lag for loading. If you go for individual non-static objects, make sure instancing works. This would be a good usecase for it.
     
    Peter77 likes this.
  8. James_Initus

    James_Initus

    Joined:
    May 26, 2015
    Posts:
    75
    Cool thanks, however I see this mentioned

    "Note: You can only draw a maximum of 1023 instances at once." is that per mesh or total?
     
  9. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    2,980
    That limit is per call to the DrawMeshInstanced command. If you have more than that many, you will need to do more than one call of the command.

    If you have 2000 objects in a scene and they are all random variations of 10 different models, you will need to call the DrawMeshInstanced command once per unique model anyway. (10 calls) If you have 200 instances of each unique model, you would call DrawMeshedInstanced 10 times and supply each call with the 200 instances. Each instance would have its own position, rotation, and size data.
     
    angrypenguin and Martin_H like this.