Extending the Tilemap Properly

Godot Version



Howdy howdy!

I’ve set my mind to replicating the game Stuck in Time in Godot as a learning challenge. I am familiar with Godot in general, but actually extending the editor itself is something I’ve barely touched upon.

I would like to maintain data on a per-tile basis relating to a tile’s “base costs” and “familiarity,” ideally while being able to easily select and modify those values within the inspector itself. For example, having a generic “Enemy” tile that has an “attack cost” value is easy enough to set up using Custom Data Layers, but having a bit of data that keeps track of how many times an individual Enemy has been defeated looks to be beyond the base functionality of the TileMap.

Taking a look at this post on Game Dev Stack shows me how to easily extend the class and add additional parameters, but I would like to see if there’s anyone who’s had experience in extending the editor so that the tools becomes easier to use. Any tips on where to begin learning how to do this correctly, or advice on what to do/not do to avoid bashing one’s head against a wall?

Thanks for any advice!

i do believe the enemy and player should be outside Tilemap as different type of node, can be characterbody2d , in general

what kind of tool are you referring to? Tilemap? also that question and answer is for Unity, not godot

…holy carp I can’t believe I’ve been overlooking that mistake for a while now. >< Apologies for that.

Ideally I was hoping to be able to extend the TileMap tabs so that custom data for a selected tile shows up in the inspector. So, for example, tiles at (0,0) and (0,1) might have the same tiledata, but different values for a custom “familiarity” value. I know I can maintain a Dictionary with Vector2i keys and store data on a separate object that way, but it would certainly be much more convenient to be able to simply click on a tile location and have access to the custom data that way.

The more I’m looking into it, though, the more it seems like such an extension isn’t super feasible without breaking into Godot’s source code, and that is something I’m hoping to avoid.

then this is just check the click location of the tilemap and convert it with local_to_map then you get the tile position, then use get_cell_tile_data to retrieve the custom data layer
in the get_cell_tile_data’s documention example show how to do that

I’m afraid I’m not explaining myself properly.

Let’s say I have a “grass tile” in my TileSet. If I stamp down two of those grass tiles side by side and get the TileData from either one of them, it will point to the exact same data. Even if I add a bit of CustomData to the TileSet, I can only set custom data for the generic “grass tile” and it will be shared between all other grass tiles.

Now this is useful for something like BaseMovementCost, since that is expected to remain constant. However, wanting to have a “Familliarity” property that changes each time the player interacts with that particular “grass tile” at that specific location cannot be done in this way.

so this is the problem of how to set unique custom data for each tile (even of the same tile)
there’s a workaround by mapping the tiles from get_used_cells with its current map tile location, these values can be saved in either dictionary or an Array

1 Like

Hey, thank you! I’ll take a look at trying to work with that. If I could find a way to detect which tile location was just clicked from within the editor itself then I could probably make a companion tool that would make editing those values more convenient. Either way, thank you again!