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

Setting transform.hierarchyCapacity through code doesn't work

Discussion in 'Scripting' started by greengremline, Sep 27, 2018.

  1. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Hello, I am trying to prepopulate the transform memory buffer before streaming in objects. At build time, I store a list of the transforms in my streamable prefabs and then try to add that to the transform.hierarchyCapacity of the object that I am parenting the streamed object to

    Code (CSharp):
    1.  
    2. Debug.Log("Before prealloc in " + thisRoom.name + ", " + transform.hierarchyCapacity);
    3. transform.hierarchyCapacity += data.additionalHierarchyCapacityToAllocate;
    4. Debug.Log("After prealloc in " + thisRoom.name + ", " + transform.hierarchyCapacity);
    5. _instantiatedPrecombine = Instantiate(_loadedPrecombine, transform, false);
    6. Debug.Log("After instantiating in " + thisRoom.name + ", " + transform.hierarchyCapacity);
    However, the hierarchy capacity does not increase until after the instantiation, or at least it doesn't appear this way in the log statements. Any ideas? Unity docs on this method are sparse
     
    Last edited: Sep 27, 2018
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,599
    Are you doing this because you actually have a performance or memory problem, or is this just speculative optimization? If the latter, I recommend just adding all the children and letting the transform grow as usual.
     
  3. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    It's speculative, but bc it's a simple optimization I figured what's the harm
    The prefabs are pretty complex, can contain around 350 children

    You do have a point regarding actually profiling this, but because it is such an easy thing to do, I figured it would be worth adding - even if it's not, it would be good to know the reason why it isn't working for anyone else who stumbles across this thread