Cammin / LDtkToUnity

Unity importer for the LDtk level editor
https://cammin.github.io/LDtkToUnity
MIT License
381 stars 38 forks source link

Can't select Grid prefab for project #10

Closed Kyle0654 closed 3 years ago

Kyle0654 commented 3 years ago

I'm trying to use a different grid prefab for my levels, but the selector for Grid Prefabs isn't showing any assets, not even the default LDtkDefaultGrid. I'm guessing it can't see the prefabs because they're a GameObject and just contain a Grid, whereas the asset picker is filtering for type Grid.

Cammin commented 3 years ago

Yeah, that is a reasonable point. In the next update, I'll make these Grid fields into GameObject fields so that the asset picker can list all the prefabs as expected. Here's how it'll look: image

For now, you can assign your grid fields by drag & dropping prefabs from the Project window into the Grid fields. I'll update you here when the next update comes 👍

Kyle0654 commented 3 years ago

Thanks! It'd also be great to be able to select a different grid prefab for the IntGrid grid and AutoLayer grid. =)

Cammin commented 3 years ago

I pushed the new update, however, the previous references of the grid prefabs will be lost, so they will need to be reassigned as GameObject prefabs.

Also, got the new documentation website set up with this update :) https://cammin.github.io/LDtkUnity/

I was wondering if you could explain your new question some more; for being able to select different grid prefabs for IntGrid and AutoLayer? Sorry, I just didn't catch what it meant exactly 😅

Kyle0654 commented 3 years ago

Basically, I load a level from ldtk, and I get this:

image

My LDtk Project asset has this:

image

What I defined in ldtk was this:

image

So I'm able to assign grid prefabs for the original ldtk-defined layers, but I get some additional layers. Floor and Breakables appear to be my int layers, Floor_AutoLayer_0 and Breakables_AutoLayer_0 are their corresponding autolayers (and appear to use the grid prefabs I defined for the int layers), and Walls_0 is the autolayer I had named Walls in ldtk (would be nice if that was at least named the same).

Also, it looks like I'd just have to define my own tiles to match the IntGrid tile values if I wanted to be able to look up those values at runtime? Any chance of including or generating some default assets for IntGrid tiles so I don't have to manually set those up? Also, any chance of getting some data attached to the game objects so I can look up the original layer they came from? I'm trying to do some basic tilemap modification in Unity, where I'd find what IntGrid value was on a tile (from an IntGrid layer), change that tile, then also change the automap above it. It's a bit difficult to accomplish at the moment (at least without relying entirely on what the layers happen to end up being named) =/.

Cammin commented 3 years ago

This question asks multiple ones, so I'll break these down. 👍

So I'm able to assign grid prefabs for the original ldtk-defined layers, but I get some additional layers. Floor and Breakables appear to be my int layers, Floor_AutoLayer_0 and Breakables_AutoLayer_0 are their corresponding autolayers (and appear to use the grid prefabs I defined for the int layers), and Walls_0 is the autolayer I had named Walls in ldtk (would be nice if that was at least named the same).

The concern in this question is that the GameObject's names are unexpectedly named differently (by Adding "_AutoLayer" or "_0"), which can hurt the ability to find these game objects by name to cross-reference with other objects. Yeah, the objects are named with extra numbers. This is done because LDtk's tile layers can have multiple tiles in the same space, which requires multiple tilemap objects. (see the corner shadow) image
Because of this, Multiple tilemap Objects need to be made, which means making extra game objects. However, I discovered a way of fitting multiple tilemaps in the same game object, so I'm going to use that instead since it's cleaner, but also consistent naming for the Gameobject with the LDtk's Layer identifier by allowing them to stay the same.

But also, the other issue brought up in this question is that the auto layer GameObjects via int grid were using the same grid prefab for them both. To solve this problem, I can try adding a second field for the same int grid layer (if the int grid layer has an auto layer). This is definitely something for me to look into.

Also, it looks like I'd just have to define my own tiles to match the IntGrid tile values if I wanted to be able to look up those values at runtime? Are you referring to the int grid values from the JSON? I'd like to discuss this one specifically more. I am interested in what you are trying to do so that I can make this specific process easier to work with.

Any chance of including or generating some default assets for IntGrid tiles so I don't have to manually set those up? Unity offers simple Sprite asset creation for the IntGrid value collision. To easily create some collision sprites, go to Assets > Create > 2D > Sprites. There are plenty of simple shapes to choose from to use for tile collision. (I should add this tip to the documentation 😅)

Also, any chance of getting some data attached to the game objects so I can look up the original layer they came from? I'm trying to do some basic tilemap modification in Unity, where I'd find what IntGrid value was on a tile (from an IntGrid layer), change that tile, then also change the automap above it. It's a bit difficult to accomplish at the moment (at least without relying entirely on what the layers happen to end up being named) =/.

Yes, I'm exploring some ways of having easy reference to other objects that have associations. It's not directly on my to-do list right now, but I'd be happy to take some technical ideas on how this would be done in order to allow for the highest flexibility while also maintaining simplicity. That is to say, I'd like to find a perfect solution the first time, though I'm open to making iterative changes to try out.

The overarching subject with these questions is about the ability to reference the JSON with the game object hierarchy more easily, and I'm planning to add some more serialized information into the level's hierarchy that would otherwise only be accessible through the JSON.

My end goal with this subject is to have the full ability to use every piece of data that the Json offers, without directly digging into the JSON. I'm thinking about ways to serializing this data into the Gameobjects, but I'm also open to some technical design suggestions 😃

Cammin commented 3 years ago

Grid Prefabs are "samey" for autolayer made by intgrid layers

Cammin commented 3 years ago

add sprite creation help for intgrid value sprites

Kyle0654 commented 3 years ago

Also, it looks like I'd just have to define my own tiles to match the IntGrid tile values if I wanted to be able to look up those values at runtime?

Are you referring to the int grid values from the JSON? I'd like to discuss this one specifically more. I am interested in what you are trying to do so that I can make this specific process easier to work with.

I'm basically trying to use the int grid for logic, since I've defined it such that it's effectively a simplified collision map (e.g. tiles with 0 are blocked, whereas tiles with 1 are walkable). Right now I'm trying to replace tiles in a location based on the int grid value at that location. However, I'd also like to do things like pathfinding based on that simplified grid. I'm sure I could manually define sprites with that data on them to use for those tiles, but it'd be nice if that data was just available directly.

It sounds like that's somewhat your aim (make the LDTK data available through the generated objects in Unity). Unfortunately, I haven't used Unity enough in my career to know the "right" way to accomplish things. I've used C# for most of my career, and have worked on engines similar to Unity in the past, but haven't dug in deep enough to have a strong recommendation for a pattern. My initial inclination would be to have a component on the generated objects with the data available, but that might not be the right way to do things in Unity.

Cammin commented 3 years ago

I believe I have a solution concerning int grid values. I've been exploring Unity Tilemaps API more and discovered that Tiles utilize an inherited TileBase, which essentially means that any sort of custom scripting could be set up for tiles, whether it's art, creating game objects, collision shape via sprite, even animated tiles. 😃
Unity docs for inheriting from TileBase here.

Also, to help allow JSON data to be communicated to the tiles during the level building process, I'm going to experiment with either an extra layer of inheritance (ex. LDtkTile) or using interfaces (ex. ILDtkTileColor, ILDtkIntGridValue). If this idea doesn't work out then I'll try something else.

I'm going to add this TileBase field when I get around to it and see how it works out. It's not on my agenda right now but something I want to add to the project pretty soon. It might even show up next update; we'll see as time tells.

I believe this will help out with achieving your own goals with int grid value tiles. It lends itself to a more "open nature". 🙂

Cammin commented 3 years ago

Make IntGrid values a TileBase field instead of a sprite field

Cammin commented 3 years ago

I pushed a new major update which entirely changes the level building process to using ScriptedImporters. Check out all of its details here: https://github.com/Cammin/LDtkUnity/blob/master/Assets/LDtkUnity/CHANGELOG.md

The IntGrid value fields now use a new special tile called LDtkIntGridTile (creatable in the asset menu), which has different customization options, including a game object field to allow for creating anything at a tile. image
image

Let me know what you think, or if you still have any issues with the new system that may appear lacking in the context of this conversation. 🙂

Cammin commented 3 years ago

I'm leaving this issue as resolved, but feel free to reopen (or post new different issue) if necessary 🙂