I want to create a class called Pawn
that is always a child of a TileMap
. Inside this class I want to create a variable called map_pos
which is very handy to store the tile on which the node is standing. However, when I try to get the parent node, I can't call any method of the TileMap class, throwing an error when getting the map_pos
. It says:
Invalid call. Nonexistent function world_to_map
on base Nil
.
Complete code:
extends Node2D
class_name Pawn
var map_pos: Vector2 setget, get_map_pos
onready var grid: TileMap = get_parent()
func get_map_pos() -> Vector2:
return grid.world_to_map(position)
Thank you very much for reading it all, any bit of help is appreciated :)