Hello, why am I getting ‘null instance’ error in following script? My scene includes main 2d Node and its children Player( CharacterBody2d) and Terrain (Tilemap)
extends CharacterBody2D
var dir = Vector2.ZERO
var cell_size
@onready var world = get_tree().get_root().find_parent(“World”) @onready var tilemap = world.find_child(“Terrain”)
get_tree().get_root() returns the root node.
You attempt to find a parent of the root node which has as name “World”.
Since it is the root node, it doesn’t have any parents by definition so the find_parent function returns null.