#Referencing a custom class causes error in unrelated area of codebase (VERY FREAKY BUG!!!)

1 messages · Page 1 of 1 (latest)

warm rampart
#

So this is actually so crazy I have no idea what is causing this.

The setup: I have a script called weapon.gd, which I use to store this variable:
static var held_weapon_data: Dictionary[WeaponType, HeldWeaponData]
containing certain data about the weapons in my game. Here's weapon.gd:

class_name Weapon
extends RefCounted

enum WeaponType {
    SWORD,
    HAMMER,
    DRILL,
}

static var held_weapon_data: Dictionary[WeaponType, HeldWeaponData] = {
    WeaponType.SWORD: preload("res://src/entities/weapons/sword/sword_held_data.tres"),
    WeaponType.HAMMER: preload("res://src/entities/weapons/hammer/hammer_held_data.tres"),
    WeaponType.DRILL: preload("res://src/entities/weapons/drill/drill_held_data.tres")
}

This has been working fine for months, no issues. But today I've been trying to implement a COMPLETELY DIFFERENT system in the game, saving and loading persistent data. I re-iterate, I'm like 99.99% sure that these two systems in my game do NOT intersect whatsoever, and neither has any syntax errors in their associated scripts.

The persistent data system is used for tracking certain repetitive things between scenes, like which enemies have been killed, doors that have been opened, etc... it is a class called PersistentData

I've just been trying to implement this system on my Enemy class, but for some reason, including a reference to the PersistentData class anywhere in my enemy.gd script causes the following errors:

weapon.gd:17 @ @static_initializer(): Attempted to assign an object into a TypedDictionary.Value, that does not inherit from 'GDScript'.

weapon.gd:17 @ @static_initializer(): Unable to convert value at key "0" from "Object" to "Object".

And then the error which actually causes the crash:

Player._ready: Out of bounds get index '0' (on base: 'Dictionary[int, HeldWeaponData]')

Simply from trying to access Weapon.held_weapon_data???

I have no idea what is causing this ;_:

#

If the enemy.gd class includes a reference to the type PersistentData anywhere in its script, this crash happens. If I remove the reference, it doesn't crash

#

And even more baffling is that there's not even any instances of the Enemy class being created upon launch, so I don't know how it could be affecting weapon.gd

#

especially since Weapon.held_weapon_data is a static variable

#

Also another weird thing is that this crash only happens when enemy.gd references PersistentData. If another script in the game references it, it's fine