I’ve been taking some time getting acquainted with Unity. To do so, I’m making a rather simple asteroids clone. Got the ship, asteroids, movement, 2D, collisions - everything seems to be working just fine - except when the asteroids explode.
I have prefabs for large, small, and tiny asteroids. Each prefab has an “explode” script attached to it, which handles an OnCollisionEnter event. Pseudo code for that looks something like this:
for(i = 0;i < 3;i++) {
Instantiate(smallerAsteroidPrefab, pos, orient);
}
This works, except that when a collision occurs and this code exectues, the game literally halts (stalls?) for upwards of a second, then continues on to the next collisions.
I’m sure instantiating is supposed to be lightning fast (and has been in past test projects that I’ve created for effects). Perhaps it’s something about the prefabs for the asteroids or perhaps it’s the meshes themselves, somehow?
Well, I do have one other question: Is it possible to get collisions without rigid bodies? I don’t care about the physics - I just want the collision events and then promptly delete the gameObject. If I turn IsKinematic on, then I don’t get the collisions events. But perhaps this is where the slowdown is and not in the instantiate? The meshes are perhaps too detailed (using MeshColliders)? They are just what I pulled off the internet somewhere; I’m a terrible artist.
Any ideas appreciated!
Thanks.
Jeff M.