0 votes

Hi! I've currently nearly completed my inventory system, but having problems figuring out how to display correctly.

I created two classes for inventory. One for each individual item (item, then quantity of that item), and one for the entire inventory itself.

I then created a scene that utilizes this script. The scene contains a panel and a grid container.

I instanced this in an autoload singleton so the player's inventory will always be available.

Just so you're aware, the "inventory" part of the game works. As in all items are successfully stored. The problem is when I need to display the players inventory I'm not sure how to do this.

Since the scene instance of the stored inventory is saved in an autoload singleton, how can I then display / show that exact scene whenever I want?


P.S. I have tried stupid things like PlayerData.player_inventory.show() but that didn't seem to work. Not sure what else I could do.

in Engine by (39 points)
edited by

2 Answers

0 votes
Best answer

It seems that your problem is just displaying the user interface of inventory.
I am not sure it is necessary to load the GUI as an autoload.

I would add a canvas layer with a panel (with your GUI inside) in your game scene (hidden) and then you could call a function like show() to display it. You pause the action on main game and yield for panel close to await for inventory operations.

If you use completely separate scenes for game and inventory, you will have the problem of reloading data every time you switch from game action to inventory and viceversa.

by (218 points)
selected by

Then I may be thinking about this incorrectly.

From what I've seen, to instantiate an object and use it you have to instantiate a scene using that script right? That's what I did.

I am trying to instantiate the inventory as an autoload so the user's inventory persists throughout. But to do that I need some sort of scene to go along with it right?

Therefore I instantiated the scene as an autoload and put the user's inventoty into it.

Unless there's a much better way.

Okay I think I hit a "eureka" moment lol. I think it would be wise to have the inventory scene and script separate from the gui and render the inventory on the gui whenever I need it.

This seems to have been my problem.

Basically you always have a main scene loaded when you play your game.

But a separate scene can be loaded inside another one as a node. Your GUI will be basically a separate scene because it will help managing the complexity of the project, but you will show it as a node inside the main game scene.

I usually always start sketching a concept with a unique scene and then when complexity starts growing I use right click on the scene tree and I instantiate a branch as a separate scene.

Thanks so much for your help! I managed to get it working!

0 votes

Can you share the image of your inventory scene?

by (134 points)
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.