I am working on a 2D tile-based game and while refactoring I wanted to make the jump to Godot 4's terrain system as I think that will help me.
While writing the function to save and load to file I iterate through the tiles and store their information. But I found that I can't retrieve the index of the terrain on the terrain set... which is very weird. There seem to be no functions to do this. Am I missing something is there like a LUT table or something holding this information? I think I could still go back to retrieving the position on the autotile but this throws away the whole point of terrains.

What am I missing and is it possible to extract the terrain from a point?
Edit:
I found the problem, I am using the wrong functions. The following does work.
<code>var terrainIndex = self.get_cellv(Vector2(i,j))
var terrainType = self.get_terrain_at_pos(Vector2(i,j))
</code>

Manage to find the answer while tweaking. It's simply from the tilemap calling get_cell_tile_data(layer, position). The object that is returned is a TileData resource which includes all the information for terrain