Search Unity

Instantiate many random Objects and combine to single mesh - Performance question

Discussion in 'Editor & General Support' started by artofmining, Aug 5, 2020.

  1. artofmining

    artofmining

    Joined:
    May 1, 2016
    Posts:
    83
    Hi
    I'm writing a script that will do the following:

    Using a dummy scene that consists of a matrix of tunnels (mining related) the script will be a movebale (via controller) GO that can fly around the scene. When an assigned button is pressed this will effectively sow or seed GO's in the scene i.e. small rocks & debris objects. Basically a seeding machine that drops objects as I move around like spraying crops. There will be additional parameters to randomise sizes etc. to ensure a variant scatter.

    As the GO's are seeded they will intially have physics rigidbody attached such that they fall the ground (terrain) and settle. The code will then wait (IEnumerator) a second to allow physics to setlle the then the rigidbody and collider will be removed from the GO levaing it static.

    Once the objects have been sewn .. the next part of the script will use a free asset called "Mesh Combiner"
    Each of the sewn objects (single material) are iterrated through and are then combined to make a single mesh prefab of many smaller objects. These will then be used in the LIVE scene.

    MY KEY QUESTION:
    Will combining many objects over a wide area have any significant impact on performance? Or should I group by localisation i.e every 30 m or so? Imagine a tunnel 100m long 5m wide in which I want to scatter debris along and combine such for perforance on draw calls. All objects (in this case) will use the same texture Atlas. My guess is about 10 objects per meter (very low poly)

    I dont know if billboarding or using tree planter on terrain might be a better suited idea? These object will not have to have any physics or colliders its just asthetics to the environment.

    Many thanks
    Archy
     
  2. DiegoDePalacio

    DiegoDePalacio

    Unity Technologies

    Joined:
    Oct 28, 2009
    Posts:
    507
    Hi @artofmining,

    Unfortunately, there is no easy or quick answer to your question.

    This is because performance optimization depends on your target platform.

    My recommendation is to:
    1. Combine a lot of objects (you can even use simple cubes) until you reach approximately the amount of poly/vertex count that you expect from your tunnel + small rocks + another objects that you expect to be there;
    2. Apply the material to this combined mesh, that you plan to use in your app/game;
    3. Use the Unity profiler in both PlayMode and in a build on your target platform to check if the performance it's good enough;
    4. If it's not good enough, repeat the steps 1 to 3, decreasing the number of combined objects until you find a good enough performance;
    5. Create and combine your tunnel with the other assets in chunks that does not have more than the number of poly/vertex count that you found optimal.

    Good luck with your project!
     
    artofmining likes this.
  3. artofmining

    artofmining

    Joined:
    May 1, 2016
    Posts:
    83
    Thanks Diego
    I posted a reply but I see it never went through.
    The platform is high end PC (I7 + 1080 GPU) as it is not for market per se.
    Anyways I made the script and things seem to be working fine. It sows the objects then I combine to a single mesh via script and this gives me an asset to use which I then adjust height down slightly to make the rocks appear sunken into the terrain.



    Cheers
     
  4. DiegoDePalacio

    DiegoDePalacio

    Unity Technologies

    Joined:
    Oct 28, 2009
    Posts:
    507
    Your progress looks good so far!

    I'm glad that you have already the script and it's working fine.


    Cheers