0
\$\begingroup\$

I am trying to design the item part of my game. My original design was just to treat them as a gameobject and to give every item an item (or some derived) component, and when the item was picked up, such an item would join into the backpack as an invisible gameobject (attached to the backpack UI canvas). Then, when moving the items to the chest or some storages, it also moves the gameobject itself. However, I believe this approach is inconvenient and will be resource-consuming to some extent.

Are there any designs that could optimize the item to be purely scripted data structure? Is it common to do so? I haven't researched too many open-source games, but when I took the game design course, I did so as I described.

I was looking for an approach like:

  • be able to link the image of the item (just like the gameobject does).
  • minimizing the cost when adding or moving/removing the item from the bag

My most desired outcomes are like the bag in the MonsterHunter.

I just need some ideas to get work done.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ You may be interested in How to store Unity component after destroying GameObject. The key point: the collectible pickup object on the ground, the object owned in your inventory, and the thing you spawn when you equip/move the object don't all have to be the same object. They just need to reference some item ID, and that item ID can have the name/image/whatever you need associated with it, without all the overhead of being a full-fledged game object with a mesh or collider, etc. Ordinary object pooling can let you recycle the pickups. \$\endgroup\$ Commented Aug 28, 2023 at 5:15
  • \$\begingroup\$ Making it a scriptableObject sounds like a good idea, in fact, I did use something similar on other parts, why didn't I think about that? Anyway, I will try to do more research and give it a try, thank you! \$\endgroup\$ Commented Aug 28, 2023 at 5:29
  • 1
    \$\begingroup\$ It as well depends on your items. Scriptable Objects won't really work when your items have a range of stats that are random \$\endgroup\$ Commented Aug 28, 2023 at 6:52
  • 1
    \$\begingroup\$ @Zibelas it can if you have a deterministic RNG and you save your item as an {archetype, seed} pair. Then you can reconstruct an identical instance of the random item's parent type on demand when needed. \$\endgroup\$ Commented Aug 28, 2023 at 11:42
  • \$\begingroup\$ So if I have an item as a scriptableobject, should the amount attribute be bound with the the item or maintained by some inventory? Because I think if I simply change the amount of some item, it will change everything that references to it. \$\endgroup\$ Commented Aug 30, 2023 at 20:30

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.