Fairly new to Unity as a whole, and while making a prototype game I came across the issue of setting up an inventory system. So far, I've been stuck on what sort of structure it should have, given:

  • Each "Mob" (player, enemy, NPC, etc.) has its own inventory
  • Objects can have children attached, which should be saved (e.g. Gun -> Attachment Manager -> Magazine/Rail/etc.)
  • Simpler items (ammunition, etc.) are stackable
  • An inventory has "pouches" which are available only for certain objects (magazines, health items, etc.) and have a certain volume

At first, I simply made a Mob -> Inventory Manager -> Pouch -> Item system where everything was a child of its respective parent, but obviously even with colliders/sprites disabled that's possibly hundreds of transforms per mob being shifted around each update. Right now, I'm just parenting each mob's inventory system to a static "Inventories" object to get past the issue of that many transforms, but is there a better long term solution that takes into account saving/loading and scene transitions?

Right now, I'm considering:

  • Turning each item with children (guns with attachments) into a prefab and saving it (not ideal)
  • Using an ID system to instantiate objects on load by loading the root object (gun), then the children (attachments) given certain parameters (but the variables, like the rounds loaded into a magazine, would be tricky to load)
  • Having different prefabs for items depending on whether or not they're equipped, on the ground, or in an inventory, and switching between them as needed
  • \$\begingroup\$ Are you using GameObjects to represent data? Things like ammunition or the number of health items in a pouch should be represented using variables in scripts, not using GameObjects. \$\endgroup\$ – Kevin Jun 25 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.