Adding Loot Box/Gacha Items to Inventory?

Hey, so I’ve been dabbling into Unity on and off for a while, but I’m a bit of a noob coding-wise. But I’m in the process of making a Gacha test system and have the summoning/loot box side of things done. I’ve been able to create the random GameObjects determined by their rarities, but the problem I’m having is, I’m not sure how to transfer those objects into something meaningful. At the moment, I’m basically just generating an image on the screen. I’m wondering how to transfer those objects into some kind of inventory. This is my thought process:

I create a list of every Unit/GameObject that can be summoned.
In the list, each object would be assigned an index based on where they are in the list (ex. This Player = 0, That Player = 1, and so on).

From there, when the summon happens and the GameObject spawns, I’d like the script to Find the object and somehow detect what index/position it is in the list.
Based on its findings, it would then add the Unit to the inventory list so then it can be used elsewhere in the game.

The problem I’m having is I have no idea if any of that will work. I’ve been able to create a List of the units I need, but from there, I just have no idea where to go. I don’t quite know how to make an inventory and I haven’t been able to find a tutorial that works for what I want. And to be honest, I’m not even sure if my logic would work in the first place. Maybe I’m overcomplicating things? I feel like I could make an if else statement for every unit, Find it in the scene, and add it to the inventory if it detects it, but I’d very much rather a more automated system if it’s possible.

I’m sorry for this mess of a post lol, but any help would be appreciated!

Inventories are fairly tricky hairy beasts. They contain elements of:

  • a database of items that you can possess
  • a database of the items you actually possess
  • persistence of this information to storage between game runs
  • presentation of the inventory to the user (may have to scale and grow)
  • interaction with items in the inventory
  • interaction with the world to get items in and out
  • dependence on asset definition (images, etc.) for presentation

Just the design choices of an inventory system can have a lot of complicating confounding issues, such as:

  • can you have multiple items? Is there a limit?
  • are those items shown individually or do they stack?
  • are coins / gems stacked but other stuff isn’t stacked?
  • do items have detailed data shown (durability, rarity, damage, etc.)?

Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.

Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.

Or… do like I like to do: just jump in and make it up as you go. It is SOFT-ware after all… evolve it as you go! :slight_smile:

Breaking down a problem such as inventory: