Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Instancing many GameObjects With same components Bad?

Discussion in 'General Graphics' started by robertolodongo, Nov 27, 2023.

  1. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    Does instancing something like 5k game objects with same components is bad for performance?
    vs
    Creating 1 mesh with same number of tris vertices?

    So 1 game object with x amount of verts and y amount of tris, vs 5k GameObjects with same components, and same amount of verts/tris as the single mesh?
     
  2. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    763
    When either are fully on screen then the single mesh will render much faster but if either are only partially (50%) on screen then the instanced objects should render faster.

    Instancing always puts more strain on the CPU and so if you have a relatively slow CPU and a fast GPU then it may be better to disable instancing and merge everything into a single mesh.

    Although when you merge everything into a single mesh you lose the benefit of LODs.

    It's complicated and it partly comes down to how your objects are situated as to whether you should merge them or not.
     
  3. raytheonly

    raytheonly

    Joined:
    Jul 7, 2018
    Posts:
    1
    Both of these approaches are mainly about "how do I reduce drawcalls", but the scenario is to generalized to give concrete advice imo.
    zulo3d already gave good pointers.

    At the end the consensus is: everything you put into the game is bad for performance, as everything has impact on processing.

    Both approaches have their advantages and disadvantages, but it highly depends on: what kind of assets are they, how dense are they, how many material slots do they have, what is their gameplay purpose, do you have the CPU or GPU as bottleneck, what platform is targeted (PC, VR, mobile,...), and a lot more.

    Also, you might want to have a mixed approach as just going one route for everything will not help most often than not, as you have to spread your resources. (if the CPU draw thread needs 20ms per frame, it doesn't matter how fast everything else is. So you have to be smart about where you put what).

    So how do you go about making a decision like this? Profile test cases:

    Create different development builds and hook up the unity profiling tools
    Then create an empty build (that measurement is your base truth).
    And then create test cases for each of the possibilities above. I also recommend to create three captures for each:
    A single thing, a reasonable amount, and an crazy unreasonable amount.

    I further suggest that you then monitor the performance of you application throughout development, so you can see when performance gets better.

    With that you can learn what these things impact in your application and help you make educated decisions later on instead of having the phenomena (which I also had often in the past) of "But I learned that generally A is bad and B is good. Why is suddenly not true in my project?".
     
  4. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    I tried both approaches and it happens exactly as u said, the mesh doesn't reduce the vertices/tris if its partially on screen but the GameOjects do, which is intuitive, i was wondering if there's something else under the hood(I'm a newbie don't know much) that I'm not considering, for i saw almost the same fps for both cases in my project, which kind of surprised me, because of the general recommendation of not instancing game objects I've seen.

    I didn't try it with combine mesh tho, im gonna try, thanks for the suggestions.
     
  5. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    Yes, in my particular case both have ups and downs, so is abit difficult to decide since it really comes to fps drops in my case, a mixed approach seems to be the way, gonna to try it, thansk.