Surely there is a better way to do this?

I’m attempting to make a maze. As you can see in the image, I’ve attempting to do this with a TON of 2d objects. It’s very time consuming and i dont imagine it being very nice on the hardware. Is there a better way of doing this?


That image is not loading.

Try using tilemap. You create a black box sprite, put it in a tile palette, and paint your entire level in a grid. There will be only one gameobject, the grid.

Oh wow, duh. For some reason i even thought of that but i was like naw that wouldnt work. What would be the best way to add colliders to it though? It would be a lot of box colliders, and it seems too complex for polygon colliders.

There is a tilemap collider :smile:. It works really great with simple tile shapes like yours. Problem being, if there is some tiles that need a special behaviour, you’ll need to create two tilemaps, one for the normal tiles, and another one for those that have a special behaviour, and certainly colliders yourself for these.

If you need to modifiy the position of certain walls without touching the other walls, tilemaps can get a bit tricky.

You can create polygon colliders, most of the time it will be better than putting multiple box colliders together. You can create multiple path in one polygon collider, resulting in multiple polygons actually, you’ll have to tweak a bit the values of the points in the inspector, as when you create a new path, it will be the copy of the first path and be “invisible” as it is on top of the other.

But beware, supressing one particular path in the editor is impossible, as you can only play with the number of existing paths, you can only supress paths starting by the last you created till the first one. It is quite easy to create a code that will, once the game is launched, supress one path, then you can take the resulting gameobject and drag it into your asset folder and create a prefab from it, stop the game, then replace your old polygon by your new one that is in the prefab. Or you can create some custom editor code, which is something you will have to learn one day as it is really helpful, but is a bit more complicated.

1 Like

Could you not have one object that has a list of vertices in there for the ‘corridors’ of the maze. I did this in hell hole.