godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.13k stars 92 forks source link

Allow custom data for individual tiles in a TileMap #6606

Open Fenreliania opened 1 year ago

Fenreliania commented 1 year ago

Describe the project you are working on

A procedurally generated 2D side-scrolling survival game.

Describe the problem or limitation you are having in your project

Populating terrain with meaningful decorations and resources in the correct places requires analysing tiles for their context, and assigning them properties that affect what can be placed there, e.g. a free tile beneath a ceiling that isn't against a wall. Additionally, pathfinding for ground-based entities also requires analysing tiles and tagging them, such as whether a tile is below a ledge, indicating how the ledge may be jumped onto.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Allow the TileMap to store custom data in tiles, independent of the predefined data from the TileSet. This keeps all information about a tile and the TileMap in the same place, and allows this meta-information to be accessed in the same way all other tile information is accessed. It allows extension of the TileMap to suit arbitrary needs without adding additional specific features.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

TileMap will have an additional parameter for custom data layers, like TileData has. Custom data can be painted onto a TileMap in the same way it can be painted onto a TileSet in the TileSet editor, with the same UI.

TileMap will have additional functions;

If this enhancement will not be used often, can it be worked around with a few lines of script?

It is likely to be used often, as people currently work around it, and additional uses are likely to be found with the feature readily available. The issue can currently be worked around by keeping a Dictionary of tiles and their custom data, but it does require an amount of code to maintain and access the data that may be more than "a few lines". Further, storing this data alongside a saved scene/map requires a lot more work on both design and implementation. Hand-assigning this data via the editor would require much more work to write an editor extension.

Is there a reason why this should be core and not an add-on in the asset library?

Information associated with a tile in the TileMap would best be accessed through and associated with the TileMap. Additionally, this is a relatively simple addition, but one with a very generic implementation that adds a great amount of flexibility to the TileMap system. Adding any of this information with an add-on would require accessing the information from somewhere other than just the TileMap, and add-ons are better suited to specific tasks. It would make more sense for an add-on to use this system to analyse a map and tag it for the pathfinding I described above, as part of a specialised pathfinding solution, rather than an expansion of the TileMap's capabilities.

Calinou commented 1 year ago
nion-ne commented 1 year ago

One workaround I've seen is the use of another tilemap that functions as a data layer.

The data layer can then be accessed similar to the way you describe.

Fenreliania commented 1 year ago

One workaround I've seen is the use of another tilemap that functions as a data layer.

The data layer can then be accessed similar to the way you describe.

Thanks, this workaround does work for some use cases, but it's not very granular or modular - You have to manually define every value you might want to use, in every increment, plus if you have even 3 different things you want to track, you either need 3 extra tilesets, or one very bloated tileset with every combination of 3 values on it. It also means that if you change anything about the tilemap, like the tile size, you have to make sure you update all additional data-holding tilemaps too.

So, this is useful for anyone trying to achieve some of these things right now, but I think the drawbacks from a workaround like this are a good example of why it would be so useful to support the feature properly. It is a good look into how the feature could function, though.

FreedomHolland commented 10 months ago

Is there a way nowadays to get custom data of any block is below a player ? For example, we use rayCast, and it can just return the custom data of a tile ?

deniszholob commented 6 months ago

Was searching around how to set tile data programatically and found this proposal. My use case is a mining game (like minecraft for example), each tile cell is a minable block. I was thinking setting each tile cell with a certain hp value that goes down with each hit by the damage value of a pickaxe, and when the hp reaches 0 the tile gets removed (block breaks) and gives you ore or whatever the drop data is.

It sounds like based on the OP's description i would need to make a separate dictionary/array with cell location values as keys and the hp (or whatever other data) as the value insdtead of being able to query the value directly

Furthermore when generating the map i cannot dynamically set these values either. I was thinking of having a modulate Color for different ore blocks with a base white sprite, instead it seems like i need a sprite for every ore...

kbkmn commented 3 months ago

Much needed feature

AThousandShips commented 3 months ago

@kbkmn Please don't bump without contributing significant new information. Use the :+1: reaction button on the first post instead.

miruji commented 3 weeks ago

The proposed functions described by the author really solve the problem. I see it as when you can pass several individual parameters to one tile without changing its copies. In addition, it would be better if this could be the behavior when initializing a tile. In addition, adding the function of duplicating the atlas and then changing the texture can also help solve some problems in this matter.