Search Unity

Keeping an array of Renderers in a script causes long load times

Discussion in 'Scripting' started by coquifrogs, Dec 19, 2012.

  1. coquifrogs

    coquifrogs

    Joined:
    Jan 17, 2012
    Posts:
    16
    If I make a script with a public member variable with a reference to a few renderers under it in the hierarchy (assigned in the inspector) and apply that script to many objects in the scene (with different renderers in each), for a few hundred objects, the load time goes up tremendously versus not having the array at all. From about 5 seconds to 3-4 minutes.

    I created a script that only has an array of Renderers and does nothing. Same thing. Seems to also happen with an array of Transforms. I'm guessing this is some overhead in the object creation process due to the dependency? For now I'm going to just access the renderers by index through the child transforms. I'll also check other methods of getting these like GetComponentsInChildren, etc.. I figured setting them in the inspector would be the fastest way.
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Renderers are references, so that should not be your problem. Is it possible that something else is causing your problem?
     
  3. coquifrogs

    coquifrogs

    Joined:
    Jan 17, 2012
    Posts:
    16
    No, this has to be the problem as I can easily replicate it with an unused array. It also happens with an array of Transforms. Like I said, it's only on load and it happens if I have the array regardless of whether I use it or not. Eliminating the array eliminates the load delay. GetComponentsInChildren may work better since it's not done at the time the object is instantiated.