- Home /
Changing Size of Tilemap
How do I change the size of a tilemap? I'm probably missing something really obvious here, but I can't seem to change the size of my tilemap. Currently, it's stuck 5x6 but I want to be 20x20. Is there any way to change this?
Answer by TheKnightsofUnity · Apr 19, 2019 at 03:44 PM
Hello @IamDumb !
There are a few different ways of resizing the tilemap, each comes with a different result:
1. Change the Scale or Cell Size of Grid – when you create a new Tilemap, Unity will automatically generate two game objects: a Grid with a Tilemap child. You can change the Scale field of the Grid’s transform or Cell Size in the Grid component. Changing the scale will stretch all tiles in the tilemap, whereas changing the Cell Size will leave the tiles unchanged – only the actual size of a cell will be changed.
2. Scale the game object with Tilemap component attached – this will stretch all tiles in all scaled directions,
3. Change orientation to Custom – by changing the Orientation field of Tilemap component, the Scale fields are now editable. Changing this field will resize the sprite of each tile, leaving the actual cell size untouched (this might cause tiles to overlap),
4. Change the size of the particular tiles – by clicking on a tile in a Tile Palette window will show Grid Selection in the Inspector. You can change the Scale field of a tile, which have a similar effect as step 3, but will affect only a particular tile.
We hope one of the solutions we suggested will solve your problem!
All the best,
The Knights of Unity
Answer by Atimlotus · Nov 24, 2019 at 05:58 PM
Hello @IamDumb,
I was trying to manually set the size of a tilemap today and the values I was getting from the script API just weren't making sense to me.
tilemap.cellBounds, tilemap.size, tilemap.localBounds were all showing me dimensions that didn't match what I was seeing in my scene.
What I found was that enabling "Debug Mode" allowed me to view and change the size of the tilemap in the inspector. Debug mode can be enabled by clicking the dropdown button next to the lock icon at the top right of the inspector window.
One thing I noticed after doing this was that painting tiles in the scene will automatically change the size of the tilemap if you go outside of the defined bounds of the tilemap. So if you have your 20x20 size tilemap and you paint in a tile one space to the right of the right bounds the tilemap will resize to 21x20.
So how did you fix this? How does one make the tilemap smaller back again?
Thanks
@Gothbag From what I can see in testing Tilemap.size does not automatically resize itself when you erase tiles in the scene view.
There does appear to be a function that will automatically resize the bounds of the tilemap based on it's current contents. In script you'd call Tilemap.CompressBounds(). To use the same function in the inspector/editor the inspector needs to be in debug mode. In the scene hierarchy select the game object that has the tilemap component you're trying to resize. In the inspector go to the Tilemap component and open the component settings by clicking on the 3 stacked dots on the far right side of the component's titlebar. At the bottom of the menu that opens you should see "Compress Tilemap Bounds".
Your answer
Follow this Question
Related Questions
2D tilemaps - separation of view and data, prototyping doubts 0 Answers
How can I modify the sprite of a particular Scriptable Tile in a Tilemap? 2 Answers
How to reference a float from a specific tile? 1 Answer
Making 2D Tilemap Areas Impassible During Runtime? 0 Answers
How to get which Tile in a tilemap another GameObject collided with? 0 Answers