Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Discussion How to equip my character with more than 100 Armor?

Discussion in '2D' started by sezercanaktemur, Jan 8, 2023.

  1. sezercanaktemur

    sezercanaktemur

    Joined:
    Jun 28, 2018
    Posts:
    17
    Hello,

    I am looking for the answer at least 1 week.

    Here is the problem;

    I have more than 100 armors as a Set in my game inventory and each of them divided into 10 pieces like ArmR, LegR etc..

    Those 100 Armors all have unique names.

    Its all layer organized, psb files which is perfect.

    However I don't know what's the best way to equip it dynamically (eg. player can change the helmet, Weapon with another set of item)

    Here it is what I have done till today;

    I rigged my 2d character and built Skeleton successfully and also animated nicely.

    Option 1: Sprite Library

    I tried to use but Each of the Set of item needs to assign the bones. Yes, I copy paste the rig but bones must be assign. Its not possible for 1000 piece.

    Option 2: Using Code

    I tried to use dictionaries, for loops, change sprites bla bla bla. However when I change the sprite, It loses root bone which is expected. The reason is same on the option 1.

    I am kind of desperate, tired and don't know what to do.

    Need your helps.
     
    Last edited: Jan 8, 2023
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,222
    Managing large numbers of assets can be VERY difficult unless you organize them in advance and derive them appropriately while you're making them, perhaps by keeping their names consistent or else using prefabs and prefab variants, or putting them into meaningful indexes such as with ScriptableObjects, or other prefab collections.

    ScriptableObject-derived classes can be helpful to organize assets, such as to add metadata about the items. You would create each asset, then create a ScriptableObject asset to go with it, probably dragging the prefab into a slot on the ScriptableObject instance.

    I use these to organize a lot of my assets:

    https://gist.github.com/kurtdekker/68b3fd9d4202888b4afc17b32eed6790

    I just make one for all my gloves, one for all my hats, etc.

    These things (inventory, shop systems, character customization, crafting, etc) 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?
    - if there is an item limit, what is it? Total count? Weight? Size? Something else?
    - 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.

    Breaking down a large problem such as inventory:

    https://forum.unity.com/threads/weapon-inventory-and-how-to-script-weapons.1046236/#post-6769558

    If you want to see most of the steps involved, make a "micro inventory" in your game, something whereby the player can have (or not have) a single item, and display that item in the UI, and let the user select that item and do things with it (take, drop, use, wear, eat, sell, buy, etc.).

    Everything you learn doing that "micro inventory" of one item will apply when you have any larger more complex inventory, and it will give you a feel for what you are dealing with.
     
  3. sezercanaktemur

    sezercanaktemur

    Joined:
    Jun 28, 2018
    Posts:
    17
    Hello Kurt,

    Thanks for the great sharing.

    - Actually I built my inventory system and it works flawless. I am happy with it.

    - However when I changed my character from legacy frame by frame animation to Skeleton & Rigging, things started to get spoiled.

    - If I use scriptable objects, it changes Sprite under Sprite Renderer. When it happens, character loses all his attached bones and rigging and even If i try to recovery its old state, it making a huge mess. There is times that I re-created everything(Rigging & skeleton etc)

    So I only have one option I guess. Do not use Skeleton&Rigging.

    Its sad to see that.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,222
    Maybe you have to leave the original sprite / sprite renderer, disabling it but letting the animation continue to move its Transform.

    Then for your "skin" you would spawn new GameObjects with the desired sprites / SpriteRenderers and parent them to the ones you turned off that the animator moves.

    Try it at a small scale, I think it would allow the animation / rigging to continue to work.
     
  5. sezercanaktemur

    sezercanaktemur

    Joined:
    Jun 28, 2018
    Posts:
    17
    I give it a try but created object doesn't follow it.

    upload_2023-1-9_8-36-15.png


    However if I create under the 'Root Bones' not under the Original Layers, it works.

    However It doesn't get the weights so its not bending so on..

    upload_2023-1-9_8-38-7.png
     
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    888
    I do not follow why it is not possible to skin each piece to the bones. Could you elaborate what goes wrong?
    Also, which version of 2D Animation do you use? In 2D Animation 9.x (Unity 2022.2), we simplified the rebind of bones when swapping (if Auto Rebind is enabled). In older versions, you have to make sure each Sprite is skinned to the same bones, and in the same order.
     
  7. sezercanaktemur

    sezercanaktemur

    Joined:
    Jun 28, 2018
    Posts:
    17
    I mean 100 Armor Set in one psb file is it okay? It seems wrong to me. Also there is sprite Library. What do you think about it? Using it on this case is fine?
     
  8. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    888
    What you should take into account is that the PSD Importer does not support pages, so you might run the risk of packing too much content into one Sprite Sheet, causing PSD Importer to shrink the final Sprite Sheet to fit them all into one texture.

    If you split your art into multiple files, you can use Sprite Atlas to pack them all together. Sprite Atlas supports pages.

    I think Sprite Library is a good choice for your use case. We have a few samples where we showcase how you can switch out equipment on a character (link).
     
  9. sezercanaktemur

    sezercanaktemur

    Joined:
    Jun 28, 2018
    Posts:
    17
    Thanks for the sharing all the details.

    What if I create 100 psb for each Armor Set and assign them into Sprite Library. That looks fine for me.

    I think I can achive that without Rig and Re-weight things by duplicating one and check 'Using Use Layer Name' option.

    By the way, I looked at the document you sent but couldn't find the sample file to download and test it on my local.
     
    Last edited: Jan 9, 2023
  10. sezercanaktemur

    sezercanaktemur

    Joined:
    Jun 28, 2018
    Posts:
    17
    Okey, Here it is How i did;

    - Duplicated one good weighted and rigged Armor and Opened It in photoshop and Copied Other armors one by one.
    - I did it for 10 and all of them working great.
    - For non-joint pieces (eg. Helmet, Cape) I created empty sprite objects under the 'Bones' not in 'root' and with sprite Resolver I can change it.
    - Animations looks good, Armors can be changed through Sprite Library. ( Yes, I dragged & dropped almost 100 pieces to Sprite Library manually )

    I hope this way can not be problem for long term
     
  11. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    888
    Great that you found a solution!
    You can find that information on this documentation page.
     
  12. sezercanaktemur

    sezercanaktemur

    Joined:
    Jun 28, 2018
    Posts:
    17
    @Ted_Wikman Hello Again,

    When I was analyzing 2D animation samples, I noticed that all the weights are same with each other when you use skeleton sharing.

    How can we transfer the weights between skeletons after copying rigs? Or you just weighted it manually?

    upload_2023-1-28_17-16-10.png

    upload_2023-1-28_17-16-19.png
     
  13. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    888
    The skeleton sharing feature is just a feature to share the bones and its hierarchies to another .psd/.psd file. The skinning data will not be shared. Once you have assigned a new skeleton to a .psd/.psb file, you have to manually skin the mesh to the new bone structure in the skinning editor.
    Does this answer your question?
     
  14. sezercanaktemur

    sezercanaktemur

    Joined:
    Jun 28, 2018
    Posts:
    17
    What If I have 30 characters sharing same skeletons, Do I need to weight manually each of them? Is there any way to transfer the weights?
     
  15. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    888
    You can use the copy + paste functionality inside the Skinning Editor to transfer mesh and weight data. But usually you would want to manually skin each character, since they tend to be different.
     
    sezercanaktemur likes this.