Export tilemap into PNG format in Unity
Created on: 15 Oct 21 00:19 +0700 by Son Nguyen Hoang in English
A package to export your lovely Unity tilemap into image file
This post is a re-up from my new Github repository. Long story short, I started my own game in Unity 2D but when doing the development, I want to export tilemap into seperate Image file to create prefab used in later purpose.
However, Not many useful topic & discussion regarding on this problem is good enough. Hence, I decided to create my own package to achieve this task, this one is named as FromTiles2Image. The link to the repository and the .unitypackage file can be visited here. Below are the content from README file.
FromTiles2Images
FromTiles2Images is a lightweight, drag-and-drop tool to convert Unity 2D tilemap into image format (e.g .png).
The tool is still under development, any contribution and feedback is welcomed!
- Use on tilemap with Regtangle-Grid based
- Easy & lightweight. Simple UI.
- Support four image format: PNG, JPG, EXR, TGA.
- Automatic set texture readable/writable.
- Automatically crop the texture from original tilemap.
- Provide a simple editor window to work with.
- Include a sample scene & sprite exported for demo.
Installation
- Clone this repository.
- Import the .unitypackage file (recommended)
Motivation (or Rant?)
You have a wonderful spritesheet, you create a tilemap from it but then you want to use it as a prefab. What can be your solutions?
-
You may create multiple gameObject, each with single Sprite of the tilemap, then group them into one single gameObject, then make it into a prefab? (spoil: It’s totally insane and can put you into an existential crisis)
-
You may use third-party software to creat tilemaps then export it (such as Tiled). The bad new is that not many Tilemap Editors that are free, also I tried Tiled onced and I hate it (basically give up after 10 minutes!)
-
Then you surf the internet, aha, it’s seem that there is not much of result as well.
-
Of course, leocub58 wrote a free package to solve this problem. However, several weakness can be pointed out, for example:
- Exported images are in low resolution.
- His algorithm sometime make unwanted/incorrect crop from the original tilemap.
- The script must be attached into tilemap to work.
- Comment written in Spanish?
Finally, aside from leocub58 I found no more package that can achieve the same objective. Hence, I decided to write my own custom library!
How It Works
- Open Tilemap To Image window. By default it is in the toolbar Window/Tilemap2Img
- Prepare a Grid & Tilemaps.
- Drag the tilemap (gameObject) into the Window Tilemap to Image
- Fill in the name (optional)
- Hit the “Export image” button
Demostration
Tilemap is on the Left, on the right is the exported sprite that had been re-imported into the project.
Further Development & Limitation
- Implement algorithm to work with Hexagon & Isometric Grid.
- There are often more than one tilemap be used in the same time to create layers. Current implemntation only export one tilemap into one single image.
Acknowledgement
- I used raimundonc sprite assest to create the demo in the sample scene. Original link: https://raimundonc.itch.io/platform-dcave-tileset
- leocub58: For giving me inspiration and idea to creat the package. Original repo: https://github.com/leocub58/Tilemap-to-PNG-Unity
- The package is developed in Unity 2020.3.2f1.