Unity texture atlas, is it possible to use a shape other than rectangular?

Started by
5 comments, last by Scouting Ninja 7 years, 5 months ago

Using Unity's 2D tools for the first time and there is a snag that I can't find the answer to.

DWldxcB.png

Here you can see a very simple test texture atlas, however for some reason the only shape I can work with is a rectangle; I can't even rotate it. I am probably missing something simple, because if the only shape I could use for for a Multiple sprite sheet is a rectangle, then it would simply be a better option to use polygons with textures instead of sprites.

I asked a friend that uses Unity a lot and he told me to load each image in on its own and then to use the Unity sprite packer, however a quick test proved that the sprite packer wastes a lot of space.

Is there a way to use a shape other than rectangle or to rotate it?

Advertisement
According to the documentation there doesn't seem to be a different way. It's all axis-aligned rectangles.
You can use custom meshes that better fit the sprite contour, like you said, or you can rotate that angled beam to be perfectly horizontal or vertical in the texture:

 __
|  |
|  |     ___
|  |   --   --
|  |  /       \
|  | |         |
|  | |         |
|  |  \       /
|__|   --___--
Then you can rotate it back to that angle in-game.

Or buy something like TexturePacker and the plugin for Unity:
- https://www.codeandweb.com/store/texturepacker-single
- https://www.assetstore.unity3d.com/en/#!/content/16641

Then you can rotate it back to that angle in-game.

I tried this didn't help much, things like houses has a kind of z shape, so rotating does't reduce the amount of pixels wasted.

Or buy something like TexturePacker and the plugin for Unity:

I don't do 2D art that much, so buying a TexturePacker, especially when I can do it on my own, isn't worth it.

You can use custom meshes that better fit the sprite contour, like you said

When I first tried it there was a small performance hit per mesh, even when all images where on a texture atlas and the 12 meshes batched as one. Then I found the Sprite material, it's optimized for 2D use, converting my atlas material to Sprite fixed the small performance loss; a useful tip for anyone deciding to use Unity for 2D.

For now I will just keep using the workaround, I believe it wont take long for Unity to realize the limits of there 2D tools and to improve it.

Textures are rectangles; that's just how the technology works. It's not specific to Unity but about how rendering is done (and specifically how textures are sampled). In your first example it's not possible to use the same texture to render the diagonal strip and the red ball because when the renderer is reading the samples for the strip, it will find the samples for the ball.

Textures are rectangles; that's just how the technology works. It's not specific to Unity but about how rendering is done (and specifically how textures are sampled). In your first example it's not possible to use the same texture to render the diagonal strip and the red ball because when the renderer is reading the samples for the strip, it will find the samples for the ball.

True however vectors an UV maps allow as a way around this.

The thing is when I map the rectangle Unity creates a polygon with the exact same size as the rectangle map on the sprite sheet, I was hoping that I could maybe use some kind of path tool to give Unity a clear outline of how the mesh should look.

Basically that is what I am doing at the moment using Blender, but it would be nice if Unity could do it for me.

I have used a few 2D engines that has allowed none rectangular mapping, most of these engines are focused on creating assets similar to the 2D Rayman games, again they use vectors, UV and polygons. I was just hoping the 2D tools in Unity was on the same level.

Unity will give you a more complex mapping but you have to go through the sprite packer tool, which you say is wasting a lot of space. Perhaps you can write your own packing policy for it.

I browsed some of Unity's sprite code, every thing needed to build a complex atlas tool and sprite generator is in fact there; Unity uses most of it for 2D collisions. It should be possible to write my own sprite editor, I just don't have time for it maybe I will give it a go during the holidays.

This topic is closed to new replies.

Advertisement