What's an "ID" in tilemap & A*?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By edgyneer

I’ve been exploring the documentation for a while now, and some of the commands use something called “id”.

Here are some examples:

  • void add_point(id: int, position: Vector3, weight_scale: float = 1.0)
  • void remove_point(id: int)
  • void set_point_disabled(id: int, disabled: bool = true)

What exactly is “id”? I tried to use Vector2() coordinates, but it wanted an integer value instead of Vector(). Is it possible to retrieve the “id” value of a tile, and if it is how do I return it?

Thanks in advance.

id is your unique identifier for the tile. gdquest has an example here that may be useful: Pathfinding and path drawing · GDQuest

spaceyjase | 2023-06-09 14:24

:bust_in_silhouette: Reply From: rakkarage

can use astar2d.get_available_point_id to get an id and not worry about it, or generate your own using an algorithm like this:

enter image description here

to generate your own ids and easily convert between id and position.

func _index(p: Vector2i, w: int) -> int: return p.x + p.y * w

func _position(i: int, w: int) -> Vector2i: return Vector2i(i % w, int(i / float(w)))

func _tileIndex(p: Vector2i) -> int: return _index(p, _tileMap.get_used_rect().size.x)

func _tilePosition(i: int) -> Vector2i: return _position(i, _tileMap.get_used_rect().size.x)