Cannot resolve - cyclic reference for a dictionary in an autoload

Godot Version

4.4

Question

I’m trying to setup an entity base that setup the entity stats from an autoload dictionary. The idea being that on various enemy classes than inherit from this base I would pass in the enum type to the setup function to initialise the stats. I haven’t even used the function yet but even trying to run the game it keeps giving the following error:

Parser Error: Could not resolve member “enemy_type_data”: Cyclic reference.
on this line:
health = EnemyStatsGlobal.enemy_type_data[enemy_type][“health”]

Entity Base

extends CharacterBody3D
class_name EntityBase

var health : int
var damage : int
var move_speed : float
var rotate_speed : float

enum EnemyType {
BASIC,
TURRET,
THING
}

func setup_enemy_stats(enemy_type : int) → void:
health = EnemyStatsGlobal.enemy_type_data[enemy_type][“health”]
damage = EnemyStatsGlobal.enemy_type_data[enemy_type][“damage”]
move_speed = EnemyStatsGlobal.enemy_type_data[enemy_type][“move_speed”]
rotate_speed = EnemyStatsGlobal.enemy_type_data[enemy_type][“rotate_speed”]
pass

My global / autoload enemy_stats

extends Node
class_name EnemyStats

ENEMY MODEL DICTIONARY

var enemy_type_data: Array[Dictionary] = [
{
“scene”: preload(“res://scenes/enemies/enemy_basic.tscn”),
“health”: int(10),
“damage”: int(2),
“move_speed”: float(1.0),
“rotate_speed”: float(0.5)
},
]

I’m very much learning Godot so if there is a better way to do this I’'m all ears.

Don’t preload your scene in enemy_stats. Consider simply including the scene’s path, and load the scene when needed.

Thanks TokyoFunkScene.

Rewrote it to a getter function in the class to pass the dictionary back for the enemy type and removed it from autoload.

func setup_enemy_stats(enemy_type : int) → void:
enemy_stats = EnemyStats.new()
var stats_block : Dictionary = enemy_stats.get_stats(enemy_type)
health = stats_block[“health”]
damage = stats_block[“damage”]
move_speed = stats_block[“move_speed”]
rotate_speed = stats_block[“rotate_speed”]
pass