Trying to find valid spawn point based on TileMapLayer cell

Godot Version

v4.4.1.stable.official [49a5bc7b6]

Question

I'm having issues getting a function to return whether or not a selected TileMapLayer cell is a valid place to spawn an enemy. The code below always prints (-1, -1), which as far as I'm aware means that it's not registering any cells at that spot. If someone could point me in the right direction that would be great!

func is_valid_spawn():
	var invalid_spawns : Array = [
		Vector2i(-1, -1),
		Vector2(1, 0)
	]
	var local_coords = $PrototypeLevel/TileMapLayer.get_local_mouse_position()
	var selected_cell = $PrototypeLevel/TileMapLayer.get_cell_atlas_coords(local_coords)
	print(selected_cell) 

You’ll need to convert the local position in pixels you get with get_local_mouse_position() to the map grid with TileMapLayer.local_to_map()

1 Like

Ahh I see. Just to clarify, converting it this way returns a Vector2 of only integers pointing to a cell on the TileMap?