Godot Version
4.2.1. stable
Question
I get this error:
Invalid call. Nonexistent function ‘get_tile’ in base ‘Nil’.
Here is the function:
func get_adjacent_buildings(coords: Vector2i, distance: int) -> Array[Building]:
var adjacent_buildings: Array[Building] = []
for i in range(-distance, distance + 1):
for j in range(-distance, distance + 1):
var tile = $"../TerrainMap".get_tile(Vector2i(coords) + Vector2i(i, j))
I’ve tried with unique name, @onready, even get_parent().get_node(“TerrainMap”), tried assigning it in _ready() and more:
When I do get_parent().get_node(“TerrainMap”), this error claims that Main is null:
Cannot call method ‘get_node’ on a null value.
If i put the function in TerrainMap and run it from there instead, I get:
Attempt to call function ‘get_adjacent_buildings’ in base ‘null instance’ on a null instance.
The node with the script and TerrainMap are siblings under Main. Both nodes are created at game start, but get_adjacent_buildings() is called later, after user input (placing a specific building). TerrainMap is found working fine in Remote scene tree at all times. So is Main, needless to say. The rest of the game is working fine.
Why can’t I access TerrainMap?! I’ve done it a million times before, and I’m doing it the same way here as far as I can tell…