Dual Wield w/ option to use items in either hand

conraddu

Member
Hello,

I am hoping to be able to equip weapons to my player in a way where I can equip one-handed weapons in either just the right hand, just the left hand, or both at the same time. (Think of the standard sword and shield use case, but if shields could be right handed OR left handed, and swords could be right handed OR left handed).

I want the same item to be equipable by EITHER the left hand or the right hand. Meaning that if the item was equipped into the right hand slot, it would appear in the right hand, and if it was equipped in the left hand slot, it would appear in the left hand. And if you had two of these items, either of them could go in either slots, and you would dual wield them.

In an attempt to do this, I made a 'one-handed melee' category with parents of 'multi item' and 'left hand' and 'right hand' where left and right hands are children of 'weapon'. I did the standard multi item setup of having two prefabs (one slot 0 and the other slot 1), where the player has their inventory item set manager configured with a Category Item Set Rule for the `weapon` category where there are three rules: slot 0 one-handed and slot 1 one-handed, only slot 0 one-handed, and only slot 1 one-handed.

The result is that a one-handed weapon can be equipped in either the left and right slots, or both. However, when equipping only 1 weapon in the left-handed slot, the weapon appears in the players right hand. This is because the left-handed slot doesn't know that its supposed to use the second prefab of the multi item when the right-handed slot is empty.

How do I go about fixing this? Is `multi item` not the correct category for this use case if I want items to be equipable by either hand or both simultaneously?
 
Hi!
This is a perfect use case for the ItemSlotCollectionItemSetRule

This rule matches the equipment item collection slot with the character item slot.

Note that you can even write your own custom rules if you want to take it to the next step and have total control over how items are equipped on the character
 
Hello,

I am struggling to understand how this rule is useful, is there an example somewhere that I could see it getting used? If not, would you mind explaining it a bit more w/ my use case?

For example, in my use case I want all my one-handed items to be equippable in either the left OR right slot. Does this mean the Multi Item category is required for my one-handed items? For instance, would all my swords would have to be multi item category (a left and a right hand copy of every single sword)?

I am basically just trying to replicate a very standard RPG setup like Diablo or World of Warcraft, where you have two weapon slots that can take weapons in either slot. Eventually I will also need logic to remove one-handed weapons from the slots when a two-handed weapon is equipped.
 
Last edited:
Unfortunatly I don't have an example for this anywhere, but I'll try to explain it the best I can.

The ItemSlotCollectionItemSetRule takes the items you've equipped in your UI (The ones equipped in the UIS Inventory ItemSlotCollection) and then tries to equip them to the character within the matching Character Item Slot.

So lets say your ItemSlotCollection has 2 slots, one for Left Hand at index 0 and one on Right Hand for index 1. Then it will create an ItemSet in the InventoryItemSetManager component with the leftHand item in slot 0 and the RightHand item in slot1

You will need to have the Multi ItemCategory for all items that can be equipped in multiple slots. In UCC there is no way to equip the same item prefab in two slots, because the slot is defined on the CharacterItem component within that prefab.
(The main reason for this, is for first person view the values on the prefab between left and right hand changes drastically)
A good worflow if you have a lot of items is simply making the Right Hand version first and then make a prefab variant and change the index to have a equivalent left hand version.

As for having a logic to unequip two-one handed weapons when equipping a two handed weapon. You'll have to do this on the UIS side. This will require some custom code. But it shouldn't be too hard, it is simply replacing the CharacterItemEquipUnequip ItemAction by your own logic. And perhaps adding some ItemRestrictions on your Inventory just to be safe.

I hope that helps
 
Thank you so much for the great explanation, this helped clarify a lot of things. I now have it so that I can mix and match equipping one-handed items in either hand, which is awesome. However, there is still a missing piece to this. If I equip a one-handed item in my left hand, and have no item in my right hand, my character does not equip any item. The right hand has to be occupied with an item in order for an item in the left hand to be visible. I think it has to do with the multi item category, where the first slot isn't being used so the item in the second slot doesn't get instantiated onto the character.

What would you recommend as a solution for this problem?
 
I doubt that's the problem. The system automatically spawns items for all compatible slots when instantiated, and only activates the one that is active.

There might be something else that is causing issues. Could you send me some screenshots of your InventoryItemSetManager inspector at runtime.
Or better even, make a small video where you show how you equip your items while the inspector is opened so that I can see if anything seems off.

You can use https://streamable.com/ for sharing videos
 
Ok I created two video clips of the current situation:
Dual Wield Problem pt.1
Dual Wield Problem pt.2

The first clip shows the current item setup in both the Inventory and Character system.
The second clip shows the character picking up two one-handed items, and equipping them in the hand slots.

You can see in the second clip when only the off-handed slot has a one-handed item in it, nothing is equipped. But the item can be seen in the characters inventory within the inspector.
 
Ah I see that you are using the Character Controller V2. I was assuming you were using V3.

Looking at your setup it looks like everything is correct, so it is possible it is a bug in V2 integration.
But I looked at the code and couldn't find anything off.

Could you look open your ItemSet at Runtime when equipping just in the left hand?
(Click this)
1670583915222.png
It should tell you the item identifiers in each slot.

Also if you can, try stepping through the GetItemSetsFor function of the ItemSlotCollectionItemSetRuleObject class. To see if it exists earlier than it should.

If the ItemSet is correct but the item isn't being equipped than something else more complicated might be the issue...

Do you have any plans of upgrading to the character controller V3?
 
This is what I see when I equip just in the left hand, none of the item definition slots are populated. But this is the case for equipping anything in any hand.

1670612804012.png

In GetItemSetsFor, I can see that when I only equip an item in my off-hand, I see this at the end of the function when inspecting the itemSet:
1670613255339.png

But the Slots of the itemSet are both null:
1670613344193.png
However this is also the case for the workflows that do work, like dual wield and main-hand wield. I will have to continue debugging further into the call stack after GetItemSetsFor is called to see where things differ.

The only reason I have not updated to v3 is because of missing integrations. For instance, I don't think there is a multiplayer integration for v3 yet, and my game is a multiplayer rogue-lite. Do you think that I should upgrade to v3? It would depend on how soon the multiplayer integration is available.
 
Top