Hi, sorry if it was already answerd. So I am trying to make a preview for a model made from smaler parts.
func reset_weapon(part_list):
for i in weapon.get_children():
i.queue_free()
weapon.remove_child(i)
for i in part_list.size():
print(part_list[i].item)
if part_list[i].item == null:
pass
else:
var instance = part_list[i].item.model.instantiate()
weapon.add_child(instance)
if part_list[i].part_slot_parent == "Base":
pass
else:
instance.position = part_list[i].part_slot_parent + part_list[i].item.position
Problem is that part_list holds slots for parts even if they are empty(its important to be like that),
so when code gets to the slot that doesnt have any item it treats it as base of resource for parts
and crashes with error:
WeaponPreview.reset_weapon: Invalid access to property or key âmodelâ on a base object of type âGDScriptâ.
So i thought about checking if it holds any item before but both cheking for null and for resource do not work.
So the part list is just sent by signal and those two function fill them
this one creates empty slots:
func add_part_slot(type, slot_parent):
var slot = {
"item":ItemData,
"part_slot_type": type,
"part_slot_parent":slot_parent
}
slot.item == null
slot.part_slot_type = type
slot.part_slot_parent = slot_parent
if weapon_part_list.is_empty():
weapon_part_list.insert(0, slot)
else:
weapon_part_list.insert(weapon_part_list.size(), slot)
and this one ads item to empty slots:
func add_attachment(slot, item_to_add):
for i in range(weapon_part_list.size()):
if weapon_part_list[i] == slot:
weapon_part_list[i].item = item_to_add
##adding new attachment slots from part
for i in item_to_add.attachment_slots:
add_part_slot(i.type, i)
reset_weapon_prewiev.emit(weapon_part_list)
You assign ItemData class to âitemâ, which you shouldnât do in the first place. Note that using a semicolon it the dictionary doesnât do a type declaration. Inside the dictionary definition it works as an assignment, so âitemâ value will now be a reference to the GDScript object that represents the class, exactly as reported by the error message.
Then you later attempt to override it with null. This would be fine but you donât really override it because you mistakenly used the equality operator == instead of the assignment operator =:
slot.item == null
This does nothing. It doesnât assign null. Try changing it to:
C# has the == operator. Doing standalone expression that have no effect will be syntactically correct in either C# or GDScript. However the script editor can be set up to issue a warning if it encounters such a line. I think Godot in fact issues this warning by default for such expressions: