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 Jordanske · Aug 07, 2017 at 04:48 PM · gameobjectscriptableobjectinventory systemscriptable objectadvice

Need some advice for my inventory system

Hello,

I am fairly new to Unity and am working with 2 other people on a new game. I try to program it in a way so that the other 2 people I am working with can easily create new inventory items as they are no programmers. The thing is I am not sure if this is the way I should do it, or if there is a more obvious way to handle this.

First, the way I want my inventory system to work:

It will be pretty simple, items that can be picked up are placed in the scene by us, not randomly spawned or anything. When you pickup the item the item will be moved to your inventory. You can click the item in your inventory to "equip" the item in your hand and use it on something else (for example: use a key on a door).

What I have now:

(check the bottom for links to a couple of images and the code)
I have an abstract Interactable class which can be extended to make different interact types. I now have an InteractableButton (just a simple button) and an InteractablePickup, the InteractablePickup accepts an InventoryItem asset and on interact the InventoryItem gets placed in the inventory.

InventoryItem is a scriptableobject, with a name, description, sprite and prefab. Name, description and sprite is used for the inventory gui, the prefab is the object that will be instantiated in the hand.

At first I had 2 gameobjects, one that is placed in the world, which had a collider and the InteractablePickup script. The second one is used for the item held in hand. This way you had to create 3 things for every inventory item, 2 gameobjects and one InventoryItem asset. The 2 gameobjects look the same, but the only difference is that one had the InteractablePickup component (and maybe in the future other components what the object for the hand doesn’t need). I really didn’t like the idea of having 2 gameobjects which essentially have the same model and texture etc.

The way I fixed this is by making 1 prefab which doesn’t have the InteractablePickup script and collider. And in the scene I made an empty gameobject which have these 2 components and added my prefab as a child.

So the process to create an inventory item is as follow:

  1. Make a new prefab, with the model and texture etc.

  2. Make a new InventoryItem asset

  3. Drag prefab into the InventoryItem asset

  4. Create a new empty gameobject in the scene (I will probably make a prefab with the InteractablePickup script already attached)

  5. Add the InteractablePickup script and a collider to the “empty” GO.

  6. Add the prefab (from step 1) as a child

  7. Drag the InventoryItem asset to the InteractablePickup component on the empty GO.

The part that I need an empty gameobject with the prefab as child still bugs me, and I wonder if there are some unseen problems that will arise later on. It is possible that I am totally overthinking this, but I wonder what you think of this and what I can do to improve this.

You can find a couple of images here http://imgur.com/a/aIVaV
And the code can be found here https://gist.github.com/jordanske/a4a4dd51015c1e5daabc5b1e07dabdad

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

0 Replies

· Add your reply
  • Sort: 

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

93 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

Related Questions

Scriptableobject List and Instantiating objects from it 3 Answers

Need opinions on handling Scriptable Objects 1 Answer

Instantiate with random scriptableObject 2 Answers

How to Instantiate objects that are Scriptable Objects 0 Answers

How to serialize scripts in Unity? 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