+2 votes

I'm working to port over a project of mine from GameMaker Studio 2 to Godot 3 currently, and one thing I developed by hand in that studio was the inventory system.

What I wish to accomplish is a dynamic inventory system that sets up individual panels within the UI based upon inventory slot count. It works similarly to how Minecraft does it - click an item and a ghost of the item will hover around the cursor. From there, you can switch the position with another item, change its position or drop it. Note that it's possible to store the items anywhere on the grid and reorganize to one's content.

The UI system with the other engine... I had no other choice but to hack in object elements onto the screen to pose as UI entities.

Making the inventory items themselves is easy, they're just dictionaries with things like weapon name, damage, fire rate, projectile name, display image, world image, etc.

I've been having trouble finding ways on getting this to work and most inventory tutorials are not very helpful. The UI system is highly confusing and has proven to be a bit painful in terms of adapting, so I've deleted my efforts and am starting from scratch again.

Does anyone have any ideas on how to get the above image going? A push in the right direction would be fantastic right now and I'm not having any luck finding much in terms of tutorials.

in Engine by (14 points)

2 Answers

+2 votes

Let's start with Canvas. Take a look at docs about Canvas Layers and Custom drawing in 2D. Having that in mind, you can create array of slots that are located within Canvas so they will match user resolution. You can also use mouse position and check where user clicked. Create one node that will act as "picked inventory item". If player clicked inside canvas, one of inventory slots, check if that slot is empty or contains item. If slot is not empty, get item texture, attach to node "picked inventory item" and make that node follow mouse cursor. Again, check where user clicked, if outside inventory panel, drop item, if it's inside and on slot, check if that slot is empty, if so, place item there, hide "picked inventory item" node, remove item from previous slot (make array[slotindex] empty). If slot is not empty, make temp variable that contains that item data, remove that item from clicked slot, place new item, set old slot to temp (item from clicked slot).


Here is repo with example: Godot-Inventory

by (378 points)
edited by

I somehow completely forgot I even asked this. Unfortunately I've forgotten most of what I learned and have to go back over and relearn everything. Do you have any good tutorials I could use to catch me up to speed? I.e. I've forgotten how to 'attach things to a node' and what not.

How would I check to make sure it's appropriately spaced and all?

You can check my Inventory that I made using HTML5 Canvas and TypeScript.
CanvasInventory (Working example).
Consider that code as pseudocode that you have to implement using GDScript.
I'll try to create inventory prototype using Godot in free time.

That would be appreciated. I made one in GameMaker Studio 2 already, but the problem is adapting it to Godot with the UI and all. I know the gist behind it, it's just I need to figure out the specifics of how to do it in Godot now. The UI system is... kind of hard to figure out.

Check my edit, linked repository with example scripts and scene.

Thanks for sharing your code example on GitHub. It's a really AWESOME starting point for building an inventory system. Cheers!

0 votes

Hi. I am also working on a Inventory and want to share some of the things I learned about Godot.

1.) Godot can make empty scripts, that are classes. To do this go to the script editor-> File ->new
I deleted the "Extends Node" part as it isn't needed.

2.) These classes can be loaded into a other scripts with: preload("res://") allowing the developer to create a "item" class that can be used by the inventory.

3.) One scene can find a object in any other scene if you know the path. This also works partly dynamically.
For example my object is in: get_node("ScrollContainer/GridContainer/MarginContainer/TextureRect") but I only need to use

4.) I use a single dynamic array, a empty slot is also an item. A 4 slot Inventory looks like this: [EmptySlot, Item, EmptySlot, EmptySlot]

That way I can use a For loop to update the Inventory

If you want, I will probably finish it by tomorrow and will be able to share the prototype.

by (1,434 points)

If you are still working on that, check my example code linked in my answer, hope that helps.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.