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
1
Question by LucasMeijer · Aug 07, 2011 at 07:02 AM · inventorypickup

How to implement pickups that can go in a inventory

So I want to have a pickup that exists in the world, and when you pick it up, it goes into your inventory. My question is, what's the best way to represent this in Unity?

Ideally I'd like this inventory item to be a prefab that I can drop in the world. That's all well and good, but my issue comes up when the player picks it up.

When it's in the player's inventory, there's no object in the world anymore, its just stored in an array for inventory objects. Of course, if the player drops it, it will again be in the world.

This feels like it will use two different kinds of objects, a GO with a mesh (etc) and a non-mesh object (not sure what that's called?) when it's in your inventory. BUT I DONT LIKE THIS ROUTE. It doesn't feel right to me. Id prefer it to be one thing, although, if I can't have it that way, I understand.

Any suggestions on how to handle this?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by LucasMeijer · Aug 07, 2011 at 07:06 AM

There are many ways to skin this cat. One way would be:

write a MonoBehaviour called "InventoryPickup". make it check if the player is closeby. if it is closeby, have it set the .enabled of the gameobject that has the MeshRenderer to false.

at the same time, it could call a function on a global "InventoryManager" object to notify it that the item was picked up. Something like:

 GetPlayer().GetInventoryManager().ItemGotPickedUp(this);

the inventory can then maintain a list of "InventoryPickups", and refer to that list whenever it wants to check if a certain item is in the inventory, or when the inventory needs to be visualized in some way. Lets say there is a 2d on screen visualization of the inventory. In such case, the InventoryPickup script could have a

  public Texture2D icon;

where you could assign the 2d icon to be used in the interface.

Comment
Add comment · Show 1 · 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 hanford2 · Aug 07, 2011 at 07:27 AM 0
Share

Thanks Lucas. I have the basics of an inventory down, it's just the turning of a real-world object into a "in memory only" object that's screwing me up.

Sounds like your suggestion is to leave the pickup GO where it is, just turn its physical properties (mesh, collider) off?

avatar image
0

Answer by Waz · Aug 07, 2011 at 07:07 AM

Keep it in the world, just inactive. Then you can manipulate it (use up charges, use it's component's properties, etc.), and have that persist if the player drops it. You might even just move it well off-screen, that way it can still have an Update, etc.

Comment
Add comment · Show 2 · 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 hanford2 · Aug 07, 2011 at 07:28 AM 0
Share

So if in code I have a reference to it, but I deactivate it, I can still access it from code?

avatar image Waz · Aug 07, 2011 at 02:56 PM 0
Share

Yes. You cannot use Send$$anonymous$$essage, and GetComponentsInChildren defaults to ignoring it (but has an option). Plus, as stated, it does not Update (but you'd probably not want it to either).

But otherwise, you can interact with it freely from code.

avatar image
0

Answer by FTheCloud · Aug 07, 2011 at 07:07 AM

Why don't you just instantiate another one when the player picks it up and that'll be what the player will hold. When the player puts it down just destroy the one that you instantiated when the player picked it up and the one in the inventory would drop down into the world. It would all be seamless.

Comment
Add comment · Show 1 · 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 Waz · Aug 07, 2011 at 07:11 AM 0
Share

That's sufficient if the item doesn't have changeable properties.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Pick up gameobject and go to inventory, 1 Answer

Pick Up objects when crosshair is over object 1 Answer

adding inventory items is half-working 0 Answers

Inventory adds an item only once. 0 Answers

I wanna make a simple inventory system that can hold three objects But I can't get it to work. 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