Hey!
I have a GameObject prefab (Empty except for some scripts) that has a single child object (a cube, also a prefab).
I can instantiate the main prefab in my level and then instantiate the cube hundreds of times and I get 5 draw calls.
However, if I repeat the same exact thing, I end up getting thousands of drawcalls (one for each cube). Any ideas?
GameObject tempCubeset = ( GameObject ) Instantiate( cubeSetPrefab , new Vector3( 0.5f , -11.5f , 0.5f ) , Quaternion.Euler( 0 , 0 , 0 ) );
tempCubeset.transform.GetChild( 0 ).gameObject.renderer.material = new Material( Shader.Find( "Transparent/Diffuse" ) );
for ( int i = 0 ; i < 500 ; i++ )
{
tempCubeset.GetComponent<CubeSet>().AddCube( new Vector3(0.5f, -11.5f, i+1.5f) );
}
//repeat (this forces a draw call per cube?)
tempCubeset = ( GameObject ) Instantiate( cubeSetPrefab , new Vector3( 2.5f , -11.5f , 0.5f ) , Quaternion.Euler( 0 , 0 , 0 ) );
tempCubeset.transform.GetChild( 0 ).gameObject.renderer.material = new Material( Shader.Find( "Transparent/Diffuse" ) );
for ( int i = 0 ; i < 500 ; i++ )
{
tempCubeset.GetComponent<CubeSet>().AddCube( new Vector3( 2.5f , -11.5f , i + 1.5f ) );
}
Any ideas what is causing this?
For context: I want to dynamically create “layers” of these cubeSets and be able to have several cubeSets each containing several cube children of their own. I am looking for a way to change the material/color of all cubes inside of a given cubeSet at runtime without having to step through every child individually. I am trying to use renderer.sharedMaterial to do this which seems to work great with one cubeSet, but not two?