The inventory system tutorials ive seen all use some kind of container to store some kind of inventory_slot scenes, which are then modified depending on whats added. For i in items, instantiate a new inventory slot, set its data to whatever, etc
I guess what im asking for might be silly, but is there a way to skip the inventory_slot step?
Because the items in themselves already have set dimensions, cause when theyre not in the hypothetical inventory list theyre in a grid. So the item has a height and a width in pixels.
So wouldnt it be easier to just add them as children to my VBoxContainer inventory, and have it arrange them?
Inventory should work without even thinking about how these items should be displayed in the game or in the UI. In most cases, the Inventory is just a Dictionary[Item, int] where keys are the item types, and values are the amounts, but it can be more complex than that of course.
What you’re asking about is how the Inventory UI should look like - and there is no one solution fits all, and there is also no limit to what you can do with it.
The thing about this is that items during the game are structured in a specific way - usually an Area2D with CollisionShape2D and Sprite2D children, but of course could be more complex or different than that.
And you also want to have it look and structured in a specific way when displayed in the Inventory UI - e.g. a clickable Button with a border around it, you don’t need it to have any collision, etc.
You can’t combine these 2 concepts in any meaningful way, that’s why you usually have 2 templates for your items - one to display it in the gameplay (Area2D or something) and another one to display it in the Inventory UI (Button or something). And the latter is just an inventory slot.
You could do that, but your items most likely derive from Node2D type, which don’t combine well with Control nodes. That’s why it’s best to have some kind of Control derived template to make it easier to work with in the UI.
Thank you for the quick reply! That was already quite helpful.
I shouldve been more clear about what these items are. Because its all UI, there isnt any area2Ds or collision or whatnot. The only thing these items do when they are not sitting in an inventory, the vbox, is sit in a grid, which is really just a different type of inventory instead.
I could just make the inventory also a grid and have no issues, its just that that adds a needless element of inventory management when all they need to do is sit on top of each other.
But yeah, it probably is still easier to just generate inventory slots to be arranged instead.
If the item in the game and in the UI is Control derived, then you might not need any inventory slots, just reparent it to any container you like. Unless you want it to be displayed in a different way, e.g. as I mentioned with a border, different background, etc. then it’d be best to have a different template / inventory slot for the Item to display in the Inventory UI.
The item isnt Control derived, but i dont really see any reason it couldnt be. Ill try to do that, and if it doesnt work for some reason i’ll just do the regular thing. Thanks for the insight!