Should I work on the Godot Import Plugin from Tiled or make a custom Tiled Export Plugin for .scene and .tres files (.tmx and .tsx accordingly)?
This question arose because the existing plugin has performance issues and crashes the editor.
For more details about the situation please read below till the end.
I’ve used Tiled through the years for small web games mainly with Phaser.
Over the last 2-3 months I’ve been playing with and loving Godot 3 so instinctively I went for Tiled as a tilemap and a level editor.
An issue came up with importing the .tmx and .tsx files in the Godot editor.
The existing plugin for TMX import to Godot is: https://github.com/vnen/godot-tiled-importer.
It works but…
- It’s made some time ago and after import, it creates tilesets with Single Tiles - this results in tilesets with 500+ tiles for a regular 16x16px sprite sheet (704x196 sized image) which makes the Godot editor crash on import.
This can be avoided by setting the project settings in Godot:
Message Queue -> Max Size Kb-> 102400 (or other big value by default it’s 1024)
But we all know that this is a workaround and not a solution.
- The existing plugin parses the .tmx / .tsx files and creates Scene files and Tilemap nodes in Single Tile mode. At some point during the Godot Engine development, a new Tileset mode was added - Atlas mode which has far better performance.
At the moment, if you try to import a tilemap through the plugin with a size bigger than 500 x 500 tiles, the Godot editor crashes with no error or log message…I suppose it just runs out of memory.
I’ve made some performance tests with a Tilemap made in Godot Engine with Atlas mode and a map of 2300x1000 tiles and it doesn’t even sweat running on 60fps. The same experiment with the imported .tmx file and Single Tiles dropped the frame rate to 20fps with a map of 812x215 tiles (both maps are 16x16px tiles) so surprise surprise - Atlas is faster.
The Tiled Editor does a far better job of drawing, layering and editing maps. Maybe in the future Godot will have all the cool features built-in but for the time being it doesn’t. Building complex tilemaps with several layers is cumbersome.
So to fix my problem I see two paths:
I can try to edit the Godot import plugin and make the changes to import the .tmx file with the new Atlas mode.
To write an export plugin using the new JS API for Tiled 3.2 which will export the tilesets to .tres files which Godot uses, and the .tmx to .scene files.
Both Godot files are text-based formats. More info about the .tscn: https://docs.godotengine.org/en/3.2/development/file_formats/tscn.html
So as I already looked through the Godot plugin code and all the XML equilibristics (500+ rows of code) I’m more inclined to make a Tiled export plugin since it looks simpler and less error-prone.
As I see the first things should be:
Exporting a tileset as .tres with all the tiles with their position and collision and reference to the image sprite sheet.
Exporting a .scene file with Tilemap node and the Tilemap position of each tile and its collision polygon if such a polygon exists.
For each layer form Tiled, a new sub-scene will be created
Other features may come later one by one once the basics are working.
Features like custom properties, navigation maps and so on.
This long post was born after more than a month of struggle with Godot TileMaps.
This topic is published as-is in the Godot Forum/Reddit as well because I will really appreciate any recommendations regarding the process of creating 2D maps and levels, and the general support of both Godot and Tiled communities.