Instantiate Performance

I was wandering if there is a real tidy way of instantiating lots of objects (Enemies with scripts attached) whilst keeping the performance high as if i get to around 30 enemies and up it starts to lag a bit and because everything is run by Time.deltaTime things start to skip frames. This si just a Q so no need for examples of scripts and what not just a general Question.

Thanks

PS. lol the script does contain 2 arrays if that’s of any help?

I had the same problem in the past, just use a coroutine. Write a function that implements IEnumerator, that function will do the instantiation. I wrote an example of this in another question:

http://answers.unity3d.com/questions/170089/using-asyncoperation-for-our-own-services.html

Here is a C# example. :P

private GameObject myEnemy = new Enemy();

// use a higher instantiation rate to make them come
// faster, but you risk reducing performance.  A number too
// high might make the game choppy or even freeze.
private int instantiationRate = 5;

public void Update() {
    if (itIsTime())
        // when necessary
        StartCoroutine(myCoroutineFunction());
}

public System.Collections.IEnumerator myCoroutineFunction() {
    for (int j = 0;j<100;j++) {
        Instantiate(myEnemy,somePosition,someQuaternion);
        if (j%instantiationSpeed == 0)
             yield return "";
    }
}

PoolManager is an instance pooling solution for Unity that has preloading so instances don’t need to be created during game play, or destroyed and created again. Very fast.
http://poolmanager.path-o-logical.com

For full disclosure, I’m a developer here.