Animator's "Slot0ItemStateIndex" parameter is the same for Equip and Unequip

arenoo

Member
As the title says, in the Animator, more precisely, in the "Upperbody Layer", whenever equipping or unequipping an item, the value of Slot0ItemStateIndex is always 4, which results in the Equipment animation to be played every time, and it is expected for Slot0ItemStateIndex to be equal to 5 when Unequipping an item.

Using Unity 2021.3.35f1.

What other information could help with troubleshooting this issue that I can provide?
 

Attachments

  • Screenshot 2024-05-08 at 21.15.14.png
    Screenshot 2024-05-08 at 21.15.14.png
    642.9 KB · Views: 1
I just tried the demo scene and the value was switched to 5 when unequpping the assault rifle. Are you immediately unequipping the item which prevents the unequip animation from playing, or did you replace the animations and missed an event?

1671 Changed Slot0ItemStateIndex to 5 on GameObject Atlas(Clone).
UnityEngine.Debug:Log (object)
Opsive.UltimateCharacterController.Character.AnimatorMonitor:SetItemStateIndexParameter (int,int,bool) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/AnimatorMonitor.cs:954)
 
Hey,

Only the animation event "OnAnimatorItemEquip" gets fired which confirms that the Unequipping animation simply does not get played, which leads me to believe this is a code issue.

The code I use to equip my item is:
"GetComponent<UltimateCharacterLocomotion>().GetAbility<EquipUnequip>().StartEquipUnequip(1, forceEquip, false);"

Edit. After some debugging I found out that when calling the above line I get 2 calls, In the first one "unequip" is true and in the second one immediately after "equip" gets true, I am not sure what is going on here. We are talking about the Update() method of the EquipUnequip class.

Edit #2. Could these lines affect what I am experiencing?
"
var itemCollection = _inventory.BridgeItemCollections.GetItemCollection(_itemCollectionName);

// These two
itemCollection.RemoveAll();
itemCollection.AddItem(weapon);

GetComponent<UltimateCharacterLocomotion>().GetAbility<EquipUnequip>().StartEquipUnequip(1, forceEquip, false);
"

Sorry for the late reply.
 
Last edited:
OnAnimatorItemUnequip won't be called if you are using a timer instead of animation event. That is consistent with your first edit.

Edit #2. Could these lines affect what I am experiencing?
Oh, you are using the inventory system? I'll tag @Sangemdoko for an idea on if RemoveAll immediately removes all of the items. From my standpoint I don't think that you would want to call that on the ItemCollection, and instead call it on the Inventory. Same with AddItem.
 
Thank you a lot for the response, I have modified my code per your advice but unfortunately it didn't lead to my issue being fixed. I am indeed using UltimateInventorySystem. It feels like this is the more correct way to write the code but I still can not figure out what I am doing wrong.

```
if (_previouslyAddedItem.Item != null)
{
_inventory.Inventory.RemoveItem(_previouslyAddedItem);
}
_previouslyAddedItem =_inventory.Inventory.AddItem(weapon, 1);
GetComponent<UltimateCharacterLocomotion>().GetAbility<EquipUnequip>().StartEquipUnequip(1, forceEquip, false);
```

Edit: The issue seems to stem from the removal line where it goes to the EquipUnequip action and calls StartEquipUnequip with immediateEquip set to true. Is there a way to somehow ignore this?
 
Last edited:
Edit: The issue seems to stem from the removal line where it goes to the EquipUnequip action and calls StartEquipUnequip with immediateEquip set to true. Is there a way to somehow ignore this?
I'm assuming that you're referring to OnRemoveItem? Within OnRemoveItem the item should already be removed at that time so calling StartEquipUnequip with an immediate removal should be ok. With that said, if for your situation it works when you set it to false then you could leave it at that.
 
"I'm assuming that you're referring to OnRemoveItem?" Yes. Unfortunately neither true nor false do not resolve the situation.
I just want to add/remove items from my inventory while equipping the newly added items, and unequipping the removed ones, and for the equipping and unequipping animations to work.

Edit: I have figured it out, seemingly when trying to remove an item from the inventory equipping gets canceled. Well, for anyone having this issue in the future here you go.
 
Last edited:
Top