I’m following the tutorial “Making an FPS Weapon Manager in Godot 4” (around 13:00 in https://youtu.be/dTW9jIIdbPU?t=765) and i’m having problems with empty “start_weapons” and “_weapon_resources”. I did filled these variables in the editor as the first image shows and the second one shows the error. The code bellow is from weapons_manager.gd (linked with weapons_manager node)
@export var _weapon_resources: Array[Weapon_Resources]
@export var start_weapons: Array[String]
var weapon_list = {} # all game weapons
var weapon_stack = [] # current held weapons
var current_weapon = null
func _ready():
Initialize(start_weapons)
func Initialize(_start_weapons: Array):
for weapon in _weapon_resources:
weapon_list[weapon.weapon_name] = weapon
# add starting weapons
for i in _start_weapons:
weapon_stack.push_back(i)
current_weapon = weapon_list[weapon_stack[0]]```
My guess is that those resources you have added only pertain to the scene they are added to. (The player scene?)
If you didn’t save them in the base manager scene its code will fail like it did for any other scene, or if the weapons_manager is dynamically instantiated elsewhere.
So you should probably add safety checks before indexing the arrays.
Exported values should be set after _init() is called so I don’t know what else it could be, other than it’s another copy of the weapon_manager that you forgot about.