The logic behind equipping item models

Hi all! Alright so I have a little bit of a head scratcher trying to get an equipment system up and running for my game. I’ve got everything needed for the whole thing, except the visuals. And that is throwing me for a loop.

I’ve got a player prefab that spawns in as a prefab, and on the model of that player I have all the armor and weapons models attached, but turned off. I want to make it so when I equip a piece of armor or weapon the correct model turns on. But I’m not sure how I would grab a reference to the correct item.

My equipment logic uses scriptable objects. Works really well actually. I can get the player model pretty easily, the one that spawns in, but I’m not sure how to go in and find the correct model to turn on.

I know one method would be to use a line like “transform.getchild(x).getchild(y).etc” but there would be several getchild calls making it very confusing, and also makes it not very modular at all if I want to add or remove equipment later.

So any help? How can I get the correct model on a spawned player prefab (that is already a child of said player prefab)

Corva, I wish I could help you pal… but I can give you some insight into what all you might be up against… these things are hairy…

These things (character customization, inventories, shop systems) are fairly tricky hairy beasts, definitely deep in advanced coding territory. They contain elements of:

  • a database of items that you may possibly possess / equip
  • a database of the items that you actually possess / equip currently
  • perhaps another database of your “storage” area at home base?
  • persistence of this information to storage between game runs
  • presentation of the inventory to the user (may have to scale and grow, overlay parts, clothing, etc)
  • interaction with items in the inventory or on the character or in the home base storage area
  • interaction with the world to get items in and out
  • dependence on asset definition (images, etc.) for presentation

Just the design choices of an inventory system can have a lot of complicating confounding issues, such as:

  • can you have multiple items? Is there a limit?
  • are those items shown individually or do they stack?
  • are coins / gems stacked but other stuff isn’t stacked?
  • do items have detailed data shown (durability, rarity, damage, etc.)?
  • can users combine items to make new items? How? Limits? Results? Messages of success/failure?
  • can users substantially modify items with other things like spells, gems, sockets, etc.?
  • does a worn-out item (shovel) become something else (like a stick) when the item wears out fully?
  • etc.

Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.

Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.

Or… do like I like to do: just jump in and make it up as you go. It is SOFT-ware after all… evolve it as you go! :slight_smile:

Breaking down a large problem such as inventory:

“Combining a bunch of stuff into one line always feels satisfying, but it’s always a PITA to debug.” - Star Manta on the Unity3D forums

Thankfully I have most of the systems you mentioned already in place it’s been a very long project lol. But it’s all coming together!

Right now I’m basically just working on a system to hard code which cosmetic pieces are turned on. Not thr best, but it does work lol

I usually spawn equipment visual objects at runtime and attach them with a “socket system”, but it sounds like you have all the models on the character already and want to simply set active to true/false?

Maybe I missed something in your question, but it sounds like this would do the job:

  • Give every equipment cosmetic piece a ID (I would use a string for simpler debugging, machines are fast enough these days, even mobiles), you can either set the cosmetic model game object name to this ID or make a component where you enter the ID)
  • Your character has a component where you drag all the child models to a list (you can make a context menu where it finds all the child models to fill the list, then you don’t have to do it by hand)
  • The component will then convert the list to a dictionary in Awake, using the equipment cosmetic piece ID as key
  • Your actual equipment item will have a property for the equipment cosmetic piece ID
  • When you equip a new item you simply use the equipment cosmetic piece ID to look up the model object and set it active
    (same during unequip to deactivate the object)

You could even use a list of piece IDs if you want to change multiple pieces per item

Im not sure what you mean with “hardcode which cosmetics are turned on” but in some way you have to “hardcode” which item enables which cosmetic models, for example by telling the system which cosmetic ID, there is no way around it.