- Home /
more efficient = gameObject w. Material[5] or 5x GameObject w. material[1]
take 200 instantiatios of a prefab with 5 textures.
if you use renderer.material to set your material, you get 200 instances of materials
If you do 5 different renderer.sharedMaterial you get one material maximum for all 200 instantiations, the last one applied.
you can't easily change texture on a prefab at all in code if you want to be computationally efficient. it seems impractical, you have to create five copies of the prefab with each material and then copy those copies. and if you do that, you have to instantiate new objects for the sake of duplicating the material even though you don't need them in the game to begin with. which is impractical.
So it seems simpler to make 5 prefabs all with different textures, and yet that's a long way around.
I think I have to make a new GameObject for each texture in code, and Instantiate different game objects.
in what way should a small number of textures be applied to many copies of a GameObject?copies of copies? make multiple root GameObjects? use multiple materials for each GameObject and then go through them with an array sharedmaterial?
Answer by Eric5h5 · Oct 14, 2012 at 04:36 PM
An object with 5 materials is no more or less efficient (from a rendering standpoint) than 5 objects with one material each. It's can be more efficient to deal with in code, though, since you only have to move one object around instead of 5.
Could you please tell me how to apply the multiple materials?
In start function i put this:
cubePrefab.renderer.materials[0].mainTexture =sw1;
cubePrefab.renderer.materials[1].mainTexture =su1;//[0]...[9]
what is the syntax to set a shared$$anonymous$$aterials from materials[]: in Update on different cubePrefabs?
thankyou!
var materials = new $$anonymous$$aterial[9];
materials[0] = x; // and so on
cubePrefab.renderer.materials = materials;