Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by Zodd · Oct 17, 2017 at 04:34 PM · inventory systemitemsrandomly

Best approach for inventory system with randomly generated items?

I have seen a lot of tutorials out there on creating inventory systems, but they are all using static databases of static items. I want to have randomly generated stats for my items, so that approach doesn't seem to work too well. I've had a couple of ideas for how to approach it, but just curious if anyone knows of any proven approaches for doing so?

My initial idea was to instantiate a prefab for each item when you enter a shop or whatever. At start, it will randomly generate the stats for that item. If you purchase/pickup the item, it will make the item a child of an Inventory parent item in the scene, with sprite renderer, and other components that are unnecessary in an unequipped state disabled. Then when you equip it, it moves it becomes the child of an equip slot instead. That way the random attributes of each item are preserved. This way seems easiest to me, but I wonder how it would work resource-wise. Especially if you are fighting enemies that also have inventories etc.

The only other idea I have is to have an inventory script that stores item details in a two dimensional relational array, so for example:

Inventory[0][Type] = Gun,

Inventory[0][Name] = Laser Cannon,

Inventory[0][Damage] = 50

Etc... And then when you equip the item, it will instantiate it in the scene. I would think this would be more resource friendly, but would it be enough so for the extra work?

Any other ideas are also appreciated!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BusyRoots · May 17, 2018 at 07:49 AM

1. My first piece of advice would be, to build at first an inventory system according to this Unity Inventory Tutorial. This is a really solid basis and gives you a lot of things you need e.g. your own type "Item" with customisable preferences and stats (keyword: "ScriptableObject). All these preferences are not static and you can easily generate random items. I use this inventory system approach my self.

2. If you really need multiple true inventories, create yourself a parent class for this, for example:

    public abstract class Inventory : Monobehavior { ... }

And all your inventories for the enemies, player, ... are inherit from this parent class "Inventory", like

 public class Enemy : Inventory {...}

For further background information about inheritance in C# and Unity see for example this nice tutorial.

3. To handle single items in a scene I distinguish two cases:

Case One: Items that are in my inventory consist only of two types: the mentioned Item type (consists of multiple types like int Amount, string Name, sprite, ...) and an int for the amount in my inventory. And both are stored in arrays (one for each). So only "pure" data and no "physically" (inspector visible) GameObject.

Case Two: If I want to drop "physically" an item in my scene, lets say a piece of wood that can be picked up from somebody else for example, I instantiate a new Item GameObject and assign the corresponding values from Item (sprite, name, ...) and int amount according to the inventory to the created Item GameObject. This GameObject Item can be transformed as child to anything you want.

On the side: To increase the readability of your post you can create an empty line using:

 <br/><br/>

Just as nice meant hint :)

Hope I could help ;),

Bredjo

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

71 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

Related Questions

Parse different types of objects from Json 1 Answer

I need to find inventory and item system, and to save them 0 Answers

Decorator pattern for inventory item class 0 Answers

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

Is it good practice to keep a reference to an GO to avoid having to instantiate it? 1 Answer


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