How to store the same information in different tiles (Referenced)

Godot Version 4.3 Beta 1

Question

The video shows 4 tiles, each tiles has one additional animation tile. I know that you can store data in a tile using CustomDataLayers, but then you will store different objects in each tile. I need the top left tile to store the object itself, and the other 3 tiles to store a reference to the object.

Conditionally speaking, imagine that this is not a set of multicolored cells, but a texture of a stove, drill, chest or other functional 2D block. Let’s say that this chest, stove, drill should have an inventory and you can put and take things there.

I was thinking of using StringName since it has a reference type, but I don’t know how to do it.

I write in C# and here you can use references too, but I don’t know what to do.

So, how could it be realized?

Don’t save that kind of data into a TileSet. Separate the data from the visuals and keep them synced.

1 Like

Well, I have one idea for implementation. I’ll leave it as a solution.

Suppose the size of the structure is 3x3 tiles (or any other), in this case, we take as the main tile its upper left corner (or the same tile itself if the size is 1x1).

Suppose we click on any tile of the structure, let it be tile 4 (see screenshot), then in order to find the main tile we can get the atlas coordinates of tile 4, and then subtract from the world coordinates of tile 4 its atlas position, thanks to which we can find out what position is the main tile of the structure.

Now having a way to find the main tile of the structure, it remains to realize its functional part. To get data about the structure, we can create a dictionary that accepts a key of Vector2I type, i.e. the position of the main tile of the structure, and returns a custom class on the received value.

I think that’s all, you can do anything you want with the custom class, put data, pictures, other classes there.

Good luck to everyone!

изображение