I’m using the latest Tiled version in tandem with SuperTiled2Unity v1.10.7.
I’m planning on making my 2D overworld using Tiled.
But I was curious whether I should be using normal Tile Layers or Object Layers, such that when these elements end up in Unity, their corresponding LayerMask will be assigned properly.
I’ve only ever used Prefab Replacement for such things, but perhaps there’s a better and easier way? Seems somewhat labor intensive to create prefabs of every type of Overworld texture, but I’d be curious to hear other’s thoughts or opinions.
I don’t have much experience with “Custom Properties” in Tiled, but if this is the route I should take if using Tile Layers, please let me know!
I am not familiar with Unity and don’t know what a “LayerMask” is in this context, but in general, you should be using tile layers whenever possible. Object Layers are for when you need entities to be dynamic/interactive (NPCs, doors, treasure chests, enterable towns on an overworld, etc) or when you need to place tiles off-grid. For the ground, you should use Tile Layers, since that’s generally static information. If you need additional info on the ground tiles, you should use custom properties set on those tiles. Unfortunately I can’t help with accessing them via ST2U, but I’m pretty sure it’s possible.
I need my player’s movement script to be able to determine if the player is currently colliding with a tile of a specific tag (i.e. Grass, Forest, Road) but this collision does not seem to function whilst using Tile Layers which come defined with Edge Collider 2D components.
The collision does occur if I use prefab replacement, marking the Tile Object with a class of “OverworldGrass” and then swapping it for a Unity prefab with a Box Collider 2D component.
I don’t know how much of a performance hit it will be in the long run if I continue using prefab replacement, and thus every single tile in the world would have its own Box Collider 2D component… this seems inefficient. But it does currently work.
Any guidance you could provide such that I could get things working with Tile Layers and tiles with defined collision shapes? Is there perhaps a way to change whether a tile receives an “Edge Collider 2D” vs something else? The tile layers seem to chunk together, so I’m not certain every tile would have its own collider body, or if the player would simply be interacting with the larger chunk. Hoping this makes some sense.
Anywho thanks for any additional information you can provide.
I’m not familiar with Unity and can’t provide specific guidance for its collision system, but you should be able to tag your tiles (or their collision objects) with custom properties in Tiled, and load those properties when loading the map. I’m pretty sure ST2U gives you access to custom properties on tiles in a Tileset, but you’ll have to do some coding to read them and load them into an appropriate data structure when you load the map.
Alternatively, if you’re using Tiled Collisions and having ST2U turn them into colliders for you, you can tag the collision objects for each tile with different layers (via unity:layer) based on whether it’s grass, forest, road, etc, and collide against these different layers as needed.