Cannot convert argument 1 from Object to NodePath ... Working with Tilemap

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

Using raycasts to detect tiles with static bodies attached, I am trying to get a reference to the tilemap I am using through the collision of the raycast. Whenever it detects a tile, however I get the error, “Invalid type in function ‘get_node’ in base ‘StaticBody2D (BasePlayer.gd)’. Cannot convert argument 1 from Object to NodePath.”
The error points to the line of code “var collider = get_node(x.get_collider())” where x is a reference to the raycast.
I have almost identical code that works when used to detect objects outside of a tilemap, so it seems to be the tilemap that’s the problem. Is there another easy way to get a reference to the tilemap through raycasting?

:bust_in_silhouette: Reply From: Zylann

According to the doc: RayCast — Godot Engine (3.1) documentation in English

get_collider() returns an Object, not a NodePath. That object is usually the body that the raycast detected. In the case of a tilemap, it will be the TileMap node itself.