Godot Version
Godot Mono 4.7
Question
I have a TileMapLayer grid with tiles, some empty & some not. I’m trying to check whether neighbouring cells of a particular co-ordinate contain tiles or not. I’ve tried the below options yet they both return (-1,-1) & -1 respectively (checked using GD.Print(…))
for(int k=0; k < surroundingCells.Length; k++)
{
if(GetCellSourceId((Vector2I)surroundingCells.GetValue(k)) != -1)
{
neighbours.SetValue(surroundingCells.GetValue(k), k); //add to neighbours
neighbourCount++;
}
if(GetCellAtlasCoords((Vector2I)surroundingCells.GetValue(k)) != new Vector2I(-1,-1))
{
neighbours.SetValue(surroundingCells.GetValue(k), k); //add to neighbours
neighbourCount++;
}
}
I am fully certain that the tiles being accessed aren’t empty - to clarify, this for loop runs for each cell in my tilemap and my tilemap gets randomly generated at runtime, so in-game it usually looks like this:
Yet GD.Print("at cell " + (Vector2I)surroundingCells.GetValue(k) + ": " + GetCellSourceId((Vector2I)surroundingCells.GetValue(k))); gives
…and so on.
I’m really stuck on this and have exhausted my attempts at troubleshooting this so I’d be very thankful for any/all responses ![]()

