Godot 4 stable : Getting error in Tilemap getting neighbour tiles.

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

The following code gives the following error and I’m not sure why or what its implying. I’m using a square so think that there should only be eight neighbours but when I loop over just 8 I only get 4 neighbours returned.

Regards

E 0:00:01:0740 TilemapTest.gd:19 @ _input(): Method/function failed. Returning: p_coords
<C++ Source> scene/2d/tile_map.cpp:3490 @ get_neighbor_cell()
TilemapTest.gd:19 @ _input()

extends Node2D

var tilemap

func _ready():
tilemap = $TileMap

func _input(event):
if event.is_action_pressed(“PlaceTile”):
var mouseposition = get_global_mouse_position()
var tile = tilemap.local_to_map(mouseposition)
var checkCell = tilemap.get_used_cells(0)
if !checkCell.has(tile):
var neighbors =
for i in 16:
var getNeigbor = tilemap.get_neighbor_cell(tile, i )
neighbors.append(getNeigbor)
for i in 16:
tilemap.set_cell(0, neighbors[i], 0, Vector2i(0,0))
tilemap.set_cell(0, tile, 1, Vector2i(0,0))
else:
print(“Tile already here”)