I don’t understand Instantiating.
When I do this I get few draw calls.
if (i < 10) {
GameObject temp = (GameObject)Instantiate (sprite1, transform.position, transform.rotation);
} else if (i < 20) {
GameObject temp = (GameObject)Instantiate (sprite2, transform.position, transform.rotation);
} else if (i < 30) {
GameObject temp = (GameObject)Instantiate (sprite3, transform.position, transform.rotation);
} else {
GameObject temp = (GameObject)Instantiate (sprite4, transform.position, transform.rotation);
}
But when I do this I get a lot of draw calls.
if (UnityEngine.Random.value < 0.25) {
GameObject temp = (GameObject)Instantiate (sprite1, transform.position, transform.rotation);
} else if (UnityEngine.Random.value < 0.25) {
GameObject temp = (GameObject)Instantiate (sprite2, transform.position, transform.rotation);
} else if UnityEngine.Random.value < 0.25) {
GameObject temp = (GameObject)Instantiate (sprite3, transform.position, transform.rotation);
} else {
GameObject temp = (GameObject)Instantiate (sprite4, transform.position, transform.rotation);
}
The difference is only the random choice of Instantiate.
I am trying to generate a List<> of Creatures and then attach prefabs to each one. I am reusing some prefabs and I don’t want extra draw calls, but all my creature prefabs are randomly selected.
So far when I generate 40 creatures I get either 13 draw calls or 30+ depending on which of the above I use but I just don’t understand why.
The rest of the script is like this
public class GameData : MonoBehaviour
{
public List<Creature> Creatures = new List<Creature> ();
public void Start ()
{
int creaturelimit = 40;
for (int i = 0; i < creaturelimit; i++) {
Creatures.Add (new Creature (){ });
// Instantiates go here
}
}