Unity Inventory Question

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?





Feedback - 18 responses

Displayed newest to oldest. Leave a comment.
does proactiv work wrote:   
This thread just blew my mind. I have to admit I got lost in the discussion. I'm just starting to learn these things and I don't think I get what Asher posted.

Patricia F. Robinson
funny news wrote:   
Your article is extremely impressive. I never considered that it was feasible to accomplish something like that until after I looked over your post. You certainly gave a great perception on exactly how this whole process works. I will make sure to return for more advice. Thanks
viagra australia wrote:   
I am extremely new to the internet and needed to review this subject. Thought it had been a great article very well written and helpful.
buy viagra online wrote:   
I would like to thank you for the efforts you have made in writing this article. I am desiring the same best work from you in the future as well. In fact your fanciful writing abilities has prompted me to start my own blog now. Actually the blogging is distributing its wings rapidly. Your write up is a fine instance of it.
buy cialis online wrote:   
Man, I truly loved reading your blogpost. You have convinced me a subscription for your blog, but how can i find the Feed?
watch movies online wrote:   
I would go with what asher said, if it doesn't feel right then don't do it
toronto seo wrote:   
Inventory management is primarily about specifying the shape and percentage of stocked goods. It is required at different locations within a facility or within many locations of a supply network to proceed the regular and planned course of production and stock of materials. Thanks.
Star sign traits blog wrote:   
My suggestion is trust intuition on this occasion, but thats due to my scorpio personality traits
plumbers north london wrote:   
Quite impressive post.Having so many information,s.
auto insurance garland tx wrote:   
You make a great place. Got good information listed here. I do think that if the best way to thought about the idea that way, they would have got a improved time comprehending the issue. Your own view is certainly anything Username enjoy travelling to much more of. Good data,
auto insurance garland tx
beecher carlson insurance services atlanta ga wrote:   
I favor them a lot. You already know what exactly you're referring to, where by others usually are from within this problem. I'm just grateful i obtained the lot of money to come across your blog. Its surely an essential difficulty not adequate consumers are talking about that i'm glad that we acquired the chance to notice many the angles.
beecher carlson insurance services atlanta ga
insurance agency gainesville ga wrote:   
It is especially stimulating to pass through the post because of it has details about these kinds of helpful feature. It's a useful course.
insurance agency gainesville ga
chase credit card wrote:   
Your article is extremely impressive. I never considered that it was feasible to accomplish something like that until after I looked over your post. You certainly gave a great perception on exactly how this whole process works. I will make sure to return for more advice. Thanks
najbolji hosting srbija wrote:   
Thanks for announcement this advantageous information. This was aloof what I was on attractive for.
David Koontz wrote:   
I think you can have 1 class on your prefab that has a reference to a 3d object (the mesh) and a 2d object (the GUITexture, or whatever). Like you were saying you toggle one off and the other on when the item switches states between being picked up and in the world. If just hiding the mesh of the 3d object causes problems (collision, triggers firing off, etc.) then you could set the actual object to be outside of your screen and just position the child object (the 3d mesh) in the scene and when it is collected you move the 3d object to the parent's location. You'll probably have to control the 3d and 2d objects independently as one is in world space and the other likely is in view space.
Hanford wrote:   
More than one class seems like a headache; every inventory prefab needs to keep track of an in-world mesh, and the in-world mesh vice versa. (Project prefabs, not Hierarchy prefabs). Ideally it's one prefab that can exist in the world, or in an inventory.

i think the best way to do this is when the item is in your inventory, we turn the mesh renderer and collider off and move it to some never-reachable part of the world.

This seems messy, but I'm going to let it stew for a while; I'm not really happy with either solution.
CC wrote:   
I agree with Asher. You want more than one class.

Think of it like this: you have an abstract Inventory Object without any display information at all, and then you have displayers of that object for different contexts. When the object is in the game world, you're using a displayer that is an object with geometry and position. When the object is in your inventory, you're using a displayer that shows a bitmap in OnGUI or something.

The above really isn't all that different than, say, displaying a health bar over your character's head and also showing health numerically in a status screen or HUD; you're just storing and displaying "objects" instead of "integers".

Alternatively, if the above is more complex than you need, you can just think of it like this: the game-world object isn't the object itself; it's an "InventoryItemGiver"; when you trigger it, it gives you an item and disappears.
Asher Vollmer wrote:   
I'm bad at explaining why I do things, but here's an example of how I would handle this:


I would create two classes.


class InventoryObjectType extends System.Object {
var name:String;
var icon:Texture2D;
var cost:int;
var prefab:InventoryObject;
}



class InventoryObject extends Component {
var lifeLeft:int; //Some instance-specific properties
}


I would create a prefab of the item I wanted to summon and add the InventoryObject component to it.

I would create a master object in the scene that just has an InventoryObjectType[] array variable exposed. And then due to Unity-Magic, all of the customizable properties of that class would pop up and be editable.


Hope that helps and isn't totally incomprehensible!

Leave a comment

Name:
Website:
Comment:

Email:
Captcha:
Please choose the atom image from below:

           

           

 

This site is mostly about

Video Game Design

User Interface Design

Creative & fun stuff

 

Your Host

I'm Hanford Lemoore. My parking skills are unparalleled.

I make things. From consumer electronics, to video games, to theme park attractions. Perhaps I can make things for you! Check out my portfolio.

When I'm not making things for other people, I'm usually experimenting.

 

Contact

Follow me on Twitter.

Message me on Facebook.

Email me using my contact form.

 

RSS 2.0

 

maquettegame.com

tikiroom.com

junkyardclubhouse.com

monolux.com

 

   


Copyright 2012 Hanford Lemoore | Blog | About | Portfolio | Contact
Powered by Olark