I’m working on a top down 2D RPG and I’m using Unity’s tilemap system. One major gripe I currently have though is the custom physics shapes needed for some tiles (like water and cliffs).
The only way I know how to do this is going into the sprite editor, and suing the custom physics shape generation which has you manually dragging nodes to the right spot.
It works well but the issue is I have to do this for every tile that is just a color variation of another with the same shape, not to mention if I make a simple change to my tiles and want to reimport them I have to draw all the physics shapes again.
It’s very tedious and time consuming. Are there any alternatives to doing this? Even if it meant writing up some scripts or something, anything so I don’t have to do this constantly and so many times would be awesome.
In 2020.2 they added copy/paste
1 Like
Amazing, I’ll try upgrading from my 2019 version and seeing how it works, thank you!
Upgraded and this is much better, thanks again! Also it’s nice to have dark mode now haha
Still curious if there is any way to generate these shapes via code, so if you have a tileset of a different color for example, I can just run some code and it will generate shapes based on parameters or something like that.
Any idea if this is possible?
Or if there is a way to copy/paste an entire tilesheets’ shapes onto another?
On the Texture Importer (not within the SpriteEditor) there’s a “Generate Physics Shape” option that can be ticked on. It’ll try to automatically create a shape. They can be a bit over complex and not work in every situation.
At a lower level, you could experiment with the TextureImporter API. Unity - Scripting API: TextureImporter
This is the section of the Editor API that can be used for spritesheet generation.
However, certain options are notably absent. There’s no physics shape on SpriteMetaData (SpriteMetaData[ ] is the textureImporter.spritesheet property). Unity - Scripting API: SpriteMetaData
So, this would require something custom by editing the .meta file for your texture. If you open this file in notepad, you should be able to see the fields that are serialized. The custom physics shape data lives there.
What you’d need to do is parse the .meta file and overwrite it with the physics shape that you want then replace the .meta file with the new one. So, if you were to copy one spritesheet’s custom physics data onto a parallel spritesheet, you could do that by editing the .meta files. In doing this, the TextureImporter API might not even matter since it’s editing text files.