Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to reduce draw batch ?

Discussion in 'Getting Started' started by narf03, Oct 22, 2016.

  1. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    I have the following Code (i only post what maybe relevant)

    Code (CSharp):
    1.  
    2.     IEnumerator fct_DrawPath () {
    3.         float fltDistance = Vector3.Distance(v3From, v3To);
    4.         int intPoints = Mathf.CeilToInt(fltDistance / fltMaxPointDistance);
    5.         Vector3 v3SectionDistance = (v3To- v3From) / intPoints;
    6.         Vector3 v3SectionAccumulate = v3From;
    7.         for(int cnt=0;cnt<intPoints;cnt++) {
    8.             v3SectionAccumulate += v3SectionDistance;
    9.             GameObject goPoint = fct_GetPointFromPool();
    10.             goPoint.transform.position = v3SectionAccumulate;
    11.             lstPoints.Add(goPoint);
    12.             yield return new WaitForEndOfFrame();
    13.         }
    14.     }
    15.  
    16.     GameObject fct_GetPointFromPool() {
    17.         if(lstPool.Count == 0) {
    18.             GameObject goInst = Instantiate(pfPathPoint);
    19.             goInst.transform.SetParent(goPoolStorage.transform);
    20.             goPoolStorage.name = "Pool " + goPoolStorage.transform.childCount;
    21.             goInst.SetActive(true);
    22.             return goInst;
    23.         } else {
    24.             GameObject goInst = lstPool[0];
    25.             goInst.SetActive(true);
    26.             lstPool.Remove(goInst);
    27.             return goInst;
    28.         }
    29.     }
    30.  
    31.  
    The pfPathPoint is basic sphere, no fancy formatting, just create gameobject->3d->sphere, but have the scales set to 0.1.

    I dont know why everytime my function draw additional sphere on the scene, it will increase draw batch, each sphere uses additional 2-4 batches. all those sphere supposed to be exactly the same, why cant unity using the same draw batch for all of them ?

    Before drawing, batches=7


    After drawing, batches=575
     
    Last edited: Oct 22, 2016