- Edited
Hello, i use a dictionary as an instance property to store ref to childs nodes using a coordinate system. The dictionary is initialised as empty var dict = {}
and in the _ready
function i populate it with instantiated nodes with some coordinates as keys. When i print the dictionary it's show that it is properly filled.
The problem is that later in the _ready
function i call another function which access the dictionary to do some actions on the nodes. But at this point the get function return null and in the breakpoint the dict property is set as <null>, i don't reassign the variable at any time after the initialization.
Here is my code (i just removed non-relevant part)
extends Node3D
# some packed scenes preloaded
# some constants and static stuff to handles coordinates
# ...
var tile_dict = {}
func _ready():
var coordinates_array: Array[Vector3i] = # some coordinates
for coordinates in coordinates_array:
var instance = TilePackedScene.instantiate()
tile_dict[coordinates] = instance
add_child(instance)
instance.coordinate = coordinates
# some stuff to handle translations depending of coordinates
# ...
print(tile_dict) # show the filled dictionary, so the dict is not null
for coordinates in # som other coordinates (present in the dict)
if tile_dict.has(coordinates): # this is true
print("set mountains")
set_mountain(coordinates)
func set_mountain(coordinate: Vector3) -> void:
var tile: HexaTile = tile_dict.get(coordinate) # tile is null
print("before",coordinate,tile_dict.get(coordinate))
print("BREACKPOINT") # breakpoint here
if tile != null: # this is false, tile is null
print("real call")
var decoration: Node3D = BigMountainPackedScene.instantiate()
tile.add_decoration(HexaTile.Type.MOUNTAIN,decoration,0,true)
Here is the data at the breakpoint:
In the same time, here how it looks in the inspector: