Custom 2d meshes

So it would be good to have 2d meshes for non-rectangular sprites and custom meshes.

I can generate a mesh for terrain etc using the 3d Mesh object and add a 2d collider but the z coordinate is wasted and using a 3d mesh creates ordering issues - I only seem to be able to place 3d objects either in front or behind the 2d stuff by adjusting the z coordinate. I can’t layer within the 2d because it’s not a sprite

Even for 2d sprites you still have to pass in a vertex which is 3 floats, you don’t save anything by having it be a 2d mesh. the hardware is still 3d and still needs 3d vertices.

Yes I know but 3d and 2d are distinct in Unity so I don’t think I can layer the 2 properly with the built in Mesh class.

No they’re not. There’s no real 2D; everything is 3D and lives in 3D space. For 2D meshes, just use the Mesh class as usual.

–Eric

You can use this extension for layering a mesh correctly:
https://github.com/nickgravelyn/UnityToolbag/tree/master/SortingLayer

2 Likes

And how do I layer this mesh between 2d sprites?

Yes that works if I also use a transparent shader (e.g Sprites/Default) on the mesh thanks Viktor.