Having problems building an inventory, need some guidance

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By scarletred012

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?

Thanks!

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.

:bust_in_silhouette: Reply From: AuthorSan

Can you share the image of your inventory scene?

:bust_in_silhouette: Reply From: gioele

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.

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.

scarletred012 | 2020-08-28 15:49

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.

scarletred012 | 2020-08-28 15:59

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.

gioele | 2020-08-28 16:08

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

scarletred012 | 2020-08-28 19:37