- Home /
unity locks up when loading prefabs
Greetings!
Im pretty new to unity so bare with me if this problem has already be dealt with somehow, but my search did not turn up with much information.
My problem is as follws: I instantiate 32x32x32 Cubes with a script in my scene as soon as its loaded. Now all cubes are the same so i dont think there should be a problem with too many draw calls, but anyhow the performance goes from nearly unbearable to not existent.
Do you know what the problem is?
Beyond is the code im using:
public GameObject prefab; public float gridX = 5; public float gridY = 5; public float gridZ = 5; public float spacing = 2.0F;
public GameObject closeTileDepth;
void Start () { for (var y = 0; y < gridY; y++) { for (var x = 0; x < gridX; x++) { for (var z = 0 - gridZ; z < 0; z++) { var pos = new Vector3(x, z, y) * spacing; GameObject obj = (GameObject)Instantiate(prefab, pos, Quaternion.identity); } } } }
Answer by Tzan · Oct 08, 2010 at 05:17 PM
When you instantiate 32,768 objects you have that many draw calls if they are all on the screen. You can drop this number by merging meshes that use the same materials. http://unity3d.com/support/documentation/ScriptReference/Mesh.CombineMeshes.html
When running in the Editor did you open the Stats panel? Button at top right of player window. The top line shows draw calls.
The recommended max is around 400-500 in Unity 2.6 on a machine several years old.
Which version of Unity are you using? If you are using Unity 3 there is batching. If it batches everything then the draw calls should be very low.
Discussion about Batching in Unity 3 http://forum.unity3d.com/threads/62714-Batching-HOWTO?highlight=batch But there are a lot of things that break batching.
thank you, that solved my issue... combining the meshes works like a charm :)
Your answer
Follow this Question
Related Questions
Instantiate problem for game editor 1 Answer
Lagspike when using instantiate in coorutine 0 Answers
Huge Framerate Drop 0 Answers
Checking if object intersects? 1 Answer