peter-kish / gloot

A universal inventory system for the Godot game engine.
MIT License
660 stars 28 forks source link

Extending InventoryGridStacked class, inspector is unusable #244

Closed TheYellowArchitect closed 2 months ago

TheYellowArchitect commented 2 months ago

I made a class AvatarInventory which extends from InventoryGridStacked Works all fine and good until I try to add/remove items in the inspector. It seems the Editor UI for that doesn't take into account that the InventoryGridStacked doesn't exist and to check for ancestor for these functions

Below is the output console

res://addons/gloot/ui/ctrl_inventory_grid.gd:177 - Invalid access to property or key 'contents_changed' on a base object of type 'Node (AvatarInventory)'.
  res://addons/gloot/ui/ctrl_inventory_grid_basic.gd:129 - Invalid access to property or key 'contents_changed' on a base object of type 'Node (AvatarInventory)'.
  res://addons/gloot/ui/ctrl_inventory_grid_basic.gd:219 - Invalid call. Nonexistent function 'get_items' in base 'Node (AvatarInventory)'.
  res://addons/gloot/editor/gloot_undo_redo.gd:18 - Invalid call. Nonexistent function 'serialize' in base 'Node (AvatarInventory)'.
  res://addons/gloot/editor/inventory_editor/inventory_editor.gd:30 - Invalid access to property or key 'size_changed' on a base object of type 'Node (AvatarInventory)'.
  res://addons/gloot/ui/ctrl_inventory_grid.gd:177 - Invalid access to property or key 'contents_changed' on a base object of type 'Node (AvatarInventory)'.
  res://addons/gloot/ui/ctrl_inventory_grid_basic.gd:129 - Invalid access to property or key 'contents_changed' on a base object of type 'Node (AvatarInventory)'.
  res://addons/gloot/ui/ctrl_inventory_grid_basic.gd:219 - Invalid call. Nonexistent function 'get_items' in base 'Node (AvatarInventory)'.
  res://addons/gloot/editor/inventory_editor/inventory_editor.gd:30 - Invalid access to property or key 'size_changed' on a base object of type 'Node (AvatarInventory)'.
  res://addons/gloot/ui/ctrl_inventory_grid.gd:177 - Invalid access to property or key 'contents_changed' on a base object of type 'Node (AvatarInventory)'.
  res://addons/gloot/ui/ctrl_inventory_grid_basic.gd:129 - Invalid access to property or key 'contents_changed' on a base object of type 'Node (AvatarInventory)'.
  res://addons/gloot/ui/ctrl_inventory_grid_basic.gd:219 - Invalid call. Nonexistent function 'get_items' in base 'Node (AvatarInventory)'.
peter-kish commented 2 months ago

Could it be that you're missing a @tool attribute in your script (AvatarInventory)? Inventory is defined as @tool so that the inventory editor can run within the Godot editor. I'm guessing this does not automatically translate to derived classes.

TheYellowArchitect commented 2 months ago

You are correct. Thanks!

I leave this issue open because it's a Godot bug for an inherited class to not inherit the tool annotation (I assume InventoryItem extension has the same problem)

peter-kish commented 2 months ago

Turns out the Godot developers don't consider this to be a bug: https://github.com/godotengine/godot-proposals/issues/754#issuecomment-629504506 but it looks like there will be a warning for these kinds of problems in Godot 4.4.

Anyways, I think the documentation might need to be updated to make this clear.

peter-kish commented 2 months ago

Anyways, I think the documentation might need to be updated to make this clear.

Done in d5423f4c0e18ace7d6002bdc5dcbeca824d912ac