• Godot Help
  • GD3/4 Could not preload resource "res://inventory/Slot.gd"

Here is my project (tested with GD4a15). The original tutorial is GD3 for 2D but I converted to GD4 for 3D.

If anyone would like to have a look because I'm not sure if it's my coding mistake or this part of tutorial is just not compatable with GD4.

https://github.com/j3du/inventorytest

  • Slot.gd is actually attached to panel slot.

  • Slot.gd part that causes error:

    func refresh_style():
    #	PlayerInventory.active_item_slot == slot_index
    	if SlotType.HOTBAR == slot_type and PlayerInventory.active_item_slot == slot_index:
    		set('theme_override_styles/panel', selected_style)
  • Error appears at PlayerInventory.gd.
    const SlotClass = preload("res://inventory/Slot.gd")

Thanks for the help.

Looks like a cyclic reference. The scripts cannot access each other like that (one loads one, then the other loads the first one, again forever).

    @cybereality It works in 3.x so this just means GD4 not allow it anymore? What can I do to fix it.

    • I updated my github link to include relevant folders

      cybereality cyclic reference

      Yeah, those are never good.

      Gowydot It works in 3.x

      You've probably just gotten very, very lucky through sheer chance so far with it...

      Can I ask something odd... why does this const SlotClass = preload("res://inventory/Slot.gd") even exist? Just remove the line; I don't see it used anywhere in the code you've given. (NOTE: I have NOT checked the whole project). But, if there is some use to it, you can simply substitute it with some other resource, var, etc.

        No it didn't work in Godot 3 either, and most programming languages. It's probably just an error/bug in your code.

        I hope so because I wouldn't know how to change codes to fix it.

        Just checking, does my syntax look correct for GD4?

        GD3
        PlayerInventory.connect("active_item_updated", slots[i], "refresh_style")

        GD4
        PlayerInventory.active_item_updated.connect(slots[i].refresh_style)

        a month later

        So after all this time I managed to fix it by simply removing the preload and any reference to it... 🤷
        (Luckily only used to infer type)

        const SlotClass = preload("res://inventory/Slot.gd")
        #delete this
        
        ...
        
        func add_item_to_empty_slot(item: ItemClass, slot)
        #then delete  : SlotClass on functions

        I never understood why you would be preloading a script. Everything is in a global namespace in Godot, so you don't need to load anything to access other classes.

          cybereality Yeah I wouldn't know anything about that, I just want to learn some Inventory so I can use it for 4.x. I will follow the final chapter of this tutorial and see if anything will go wrong.

          I really should give a shoutout to ThinKing_2005 as he did gave the right answer for this problem 👍️ (back then I didn't understand the errors that came after deleting it)