# Get 2D Array Of Tilemap

Basically, I have a tilemap with some terrain. I need it to be stored in a 2d array. I don’t know how to do that though. Any help is appreciated. TYSM!

However you do it there two common things
1- Must have an array that is 2D or more.
2- Every element of the array should be checked with nested loops. (The number of nested loops are based on your array dimension).
3-Every string or number refers to an object on that tile.

Here’s the simplest tile script I can think of:

``````using UnityEngine;
public class TileCreator : MonoBehaviour
{
public bool IsCreated;
public int[,] Tile = new int[,] {
{0,0,0 },
{1,1,0 },
{2,1,0 }
};
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
//To make it only once or the unity will eventually crash
if (IsCreated == false)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (Tile[i,j] == 0)
{
Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube),new Vector3(i,j,0),Quaternion.identity);
}
if (Tile[i, j] == 1)
{
Instantiate(GameObject.CreatePrimitive(PrimitiveType.Sphere), new Vector3(i, j, 0), Quaternion.identity);
}
if (Tile[i, j] == 2)
{
Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cylinder), new Vector3(i, j, 0), Quaternion.identity);
}
}

//break the loop
IsCreated = true;
}
}

}
}
``````

If you have any questions or problems please feel free to ask.
Hope this helps

I appreciate you responding! Sadly, I phrased the question a little weird… I meant already having a tilemap and when the game starts/i press a button in the editor. It stores it in a 2D array (And Gives An ID To Each Tile E.G if i have a tile grass15, it will make it just 15 or whatever number i want) . Is that possible? Should I just make a tilemap system of my own and build it with your script?
Sidenote: Thank you for answering me, sorry for phrasing my question weird…