0

I have a Unity project in which I have the necessary code to create a texture anywhere from 2x2 to 512x512 and fill it with perlin noise. I am using this texture to populate a map of blocks (think minecraft) .

The map generates correctly, but Unity starts lagging with that many cubes?

Sample Image

This is an image of the generated map, 256x256.

Any leads in the right direction would be appreciated, I'm just stumped on how to get passed this.

This is the method to populate the map

private void GenerateMap ()
{
    for (int x = 0; x < creator.resolution; x++) {
        for (int z = 0; z < creator.resolution; z++) {
            Object newCube = Instantiate (cube, new Vector3(x, Mathf.Round (texture.GetPixel (x, z).b * 10), z), Quaternion.identity);
            newCube.name = "Cube: " + x + ", " + z;
        }
    }
    Debug.Log ("Finished generating world");
}
Randy Levy
  • 22,566
  • 4
  • 68
  • 94
user1801067
  • 133
  • 2
  • 12

2 Answers2

1

Probably you should try to load them dynamically as minecraft does to not having to process all the cubes on each tick.

cris
  • 11
  • 1
  • I'm just using the Instantiate method to create the new blocks. Whats the easiest way of dynamically creating each block? – user1801067 Jul 10 '15 at 17:54
0

You cannot have that many gameobjects in scene. Should create mesh chunks (so one mesh piece basically replaces hundreds of cubes)

Browse through the huge minecraft-thread in unity forums: (plenty of explanations and samples too) http://forum.unity3d.com/threads/after-playing-minecraft.63149/

Or just search for unity minecraft terrain, there are many tutorials for it.

mgear
  • 1,333
  • 2
  • 22
  • 39