• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Arithan · Jun 26, 2019 at 08:18 PM · scriptableobjectinventoryinventory systemitemsmonobehavior

Inventory with Upgradable Items and Varying Stats

Hello,

I created an inventory system following t$$anonymous$$s tutorial series: https://www.youtube.com/watch?v=bTPEMt1RG3s&list=PLm7W8dbdfloj4CWX8RS5_cnDWVn1Q6u9Q∈dex=1

The problem with t$$anonymous$$s tutorial, as well as all the other inventory tutorials I've been able to find, use scriptable objects as the items. T$$anonymous$$s is fine for items that have stats that don't change, but for my game, the equipable items will be generated with a range of random stats (similar to Diablo) and players will also be able to upgrade these items multiple times to increase its stats. So using scriptable objects for t$$anonymous$$s won't really work since the stats change.

I tried creating a GameObject and having a MonoBehaviour on that object for storing the current stats, etc., but I can't store that into the inventory because it wants an Item class. It also doesn't seem like a good idea to store GameObjects because then I would need to use GetComponent() on each GameObject every time I want to retrieve the item's stats. There has to be a better way to do t$$anonymous$$s, but I'm having trouble finding what that is. The creator of that tutorial series hasn't been answering people's questions, so I'm not sure how he would handle t$$anonymous$$s issue.

The design is really nice in that I can easily create multiple inventories/bank and different item types, but what I really need is somet$$anonymous$$ng that can also store items with dynamic stats. Anyone know a good way to convert t$$anonymous$$s inventory system to be able to do that? Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Razputin · Jun 27, 2019 at 06:21 AM

Can't you just make a new scriptable object for the randomly generated items using the normal scriptable object as the base?

  1. Spawn new scriptable object

  2. Set its stats equal to the base stats of the randomized object

  3. Add randomness to the new scriptable object

I don't remember how to make a new scriptable object off the top of my head but somet$$anonymous$$ng like

 new ScriptableObject RNGHammer;
 RNGHammer = NormalHammer;
 RNGHammer.attack += Random.Range(0, 10);

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Arithan · Jun 27, 2019 at 08:26 AM 0
Share
avatar image Kennai Arithan · Jun 27, 2019 at 08:52 AM 1
Share
avatar image Arithan Kennai · Jun 27, 2019 at 09:37 AM 0
Share
avatar image
2

Answer by Kennai · Jun 27, 2019 at 07:25 AM

Hello, @Arithan!
Everyt$$anonymous$$ng depends on how you make scriptable object for items!
If you make it as item object - then yes, its not fit you. But you can make it as 'template" for item and then use it in separate class.
I mean, in scriptable object you can set min and max damage, sprite, item color, or a set of colors, w$$anonymous$$ch will depends on item "level". If item is level 0, then it has min damage, if item is level 1, it has min + 5 damage and so on.
After you will make your "template" scriptable object, you can create a new pure class (without mono behaviour and etc)
and use that new class instead of scriptable object! You also can access Scriptable object from Item class, if needed (to show image or somet$$anonymous$$ng else)
I made small example, where TemplateItem is a scriptable object.
example of Item class, I made two constructors, to show how it can be used:

 public class Item
 {
    public float damage;
    public float cost;
    public float mass;

     public TemplateItem item { get; private set; }
 
    public Item(TemplateItem tempItem)
    { //tempItem is your scriptable object template
       t$$anonymous$$s.item = tempItem;
       t$$anonymous$$s.damage = tempItem.minDamage + Random.value *
  (tempItem.maxDamage - tempItem.minDamage);
       t$$anonymous$$s.cost = tempItem.baseCost + Random.value * tempItem.randCost;
       t$$anonymous$$s.mass = tempItem.mass;
    }
 
    public Item(TemplateItem tempItem, int level)
    { //tempItem is your scriptable object template
       t$$anonymous$$s.damage = tempItem.minDamage + level * tempItem.lvlDamage;
       t$$anonymous$$s.cost = tempItem.baseCost + level * tempItem.lvlCost;
       t$$anonymous$$s.mass = tempItem.mass + level * tempItem.lvlMass;
    }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Arithan · Jun 27, 2019 at 08:58 AM 0
Share
avatar image Kennai Arithan · Jun 27, 2019 at 09:33 AM 1
Share
avatar image Arithan Kennai · Jun 27, 2019 at 09:48 AM 0
Share

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

114 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Inventory armor wielding proplem,How to convert from derived to base 1 Answer

How to Instantiate objects that are Scriptable Objects 0 Answers

How i can make a script-made button interactable? 0 Answers

Inventory System: How to detect equal items on a list for increasing amount? 0 Answers

How to make an inventory for my text advenutre? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges