Argument is out of range

nitrox32

Member
I just added a shield to my character and set it up for duel wield with the sword. At runtime I get the error: ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index. Everything seems to function correctly. I'm just curious what this is.
 
For these type of errors if you can follow the bug reports format that would be great so I can understand what is going on.
1) Create Item Type "MyShield" and Item to MyItemCollection (created from video tutorials)

2) Create New Item with these First Person attributes:
Name "MyShield"
Item Type "MyShield"
Character "Nolan"
Add to Default Loadout checked
Animator ID 25
First Person Base "NolanFirstPersonArms"
First Person Visible Item "Shield"
Item Parent "Items" (from left arm)
Animator Controller "None"

Third Person:
Third Person Visible Item "Shield"
Hand "Left"
Animator Controller "None"
Action Type "Shield"

3) Press Build

4)Add "MyShield" to Slot 1 in Item Set 2 (The Bow is item set 0, the Item Set 1)

5) Change Animator Movement Set ID to 1 (on MyShield)

5) Press Play

I get the error: ArgumentOutOfRangeException: Argument is out of range.
 
Last edited:
What is the full error? Are you switching to the shield? Based on those repro steps it doesn't look like the shield is ever activated.
 
Last edited:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[Opsive.UltimateCharacterController.Inventory.ItemSet].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
Opsive.UltimateCharacterController.Inventory.ItemSetManager.IsItemSetValid (Int32 categoryIndex, Int32 itemSetIndex, Boolean checkIfCanSwitchTo) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/ItemSetManager.cs:265)
Opsive.UltimateCharacterController.Inventory.ItemSetManager.SetDefaultItemSet (Int32 categoryIndex) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/ItemSetManager.cs:395)
Opsive.UltimateCharacterController.Character.Abilities.Items.EquipUnequip.OnPickupItem (Opsive.UltimateCharacterController.Items.Item item, Single count, Boolean immediatePickup, Boolean forceEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/EquipUnequip.cs:223)
Opsive.UltimateCharacterController.Events.InvokableAction`4[Opsive.UltimateCharacterController.Items.Item,System.Single,System.Boolean,System.Boolean].Invoke (Opsive.UltimateCharacterController.Items.Item arg1, Single arg2, Boolean arg3, Boolean arg4) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/InvokableAction.cs:225)
Opsive.UltimateCharacterController.Events.EventHandler.ExecuteEvent[Item,Single,Boolean,Boolean] (System.Object obj, System.String eventName, Opsive.UltimateCharacterController.Items.Item arg1, Single arg2, Boolean arg3, Boolean arg4) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/EventHandler.cs:497)
Opsive.UltimateCharacterController.Inventory.InventoryBase.AddItem (Opsive.UltimateCharacterController.Items.Item item, Boolean immediateEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:142)
Opsive.UltimateCharacterController.Items.Item.Start () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:254)

I'm not switching. It occurs right away.
 
This looks like it's related to the default ItemSet being set to an incorrect index, rather than with the shield itself. Thanks for letting me know, try updating ItemSetManager.GetDefaultItemSetIndex to:

Code:
        public int GetDefaultItemSetIndex(int categoryIndex)
        {
            if (categoryIndex == -1) {
                return -1;
            }
            // Protect against out of bounds errors.
            if (m_CategoryItemSets[categoryIndex].DefaultItemSetIndex >= m_CategoryItemSets[categoryIndex].ItemSetList.Count) { // NEW
                return -1; // NEW
            } // NEW

            return m_CategoryItemSets[categoryIndex].DefaultItemSetIndex;
 
This is what the new code looks like:

public int GetDefaultItemSetIndex(int categoryIndex)
{
if (categoryIndex == -1) {
return -1;
}
// Protect against out of bounds errors.
if (m_CategoryItemSets[categoryIndex].DefaultItemSetIndex >= m_CategoryItemSets[categoryIndex].ItemSetList.Count)
{ // NEW
return -1; // NEW
} // NEW

return m_CategoryItemSets[categoryIndex].DefaultItemSetIndex;
}

The functionality is the same. This is the error:

ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[Opsive.UltimateCharacterController.Inventory.ItemSet].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
Opsive.UltimateCharacterController.Inventory.ItemSetManager.IsItemSetValid (Int32 categoryIndex, Int32 itemSetIndex, Boolean checkIfCanSwitchTo) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/ItemSetManager.cs:271)
Opsive.UltimateCharacterController.Inventory.ItemSetManager.SetDefaultItemSet (Int32 categoryIndex) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/ItemSetManager.cs:401)
Opsive.UltimateCharacterController.Character.Abilities.Items.EquipUnequip.OnPickupItem (Opsive.UltimateCharacterController.Items.Item item, Single count, Boolean immediatePickup, Boolean forceEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/EquipUnequip.cs:223)
Opsive.UltimateCharacterController.Events.InvokableAction`4[Opsive.UltimateCharacterController.Items.Item,System.Single,System.Boolean,System.Boolean].Invoke (Opsive.UltimateCharacterController.Items.Item arg1, Single arg2, Boolean arg3, Boolean arg4) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/InvokableAction.cs:225)
Opsive.UltimateCharacterController.Events.EventHandler.ExecuteEvent[Item,Single,Boolean,Boolean] (System.Object obj, System.String eventName, Opsive.UltimateCharacterController.Items.Item arg1, Single arg2, Boolean arg3, Boolean arg4) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/EventHandler.cs:497)
Opsive.UltimateCharacterController.Inventory.InventoryBase.AddItem (Opsive.UltimateCharacterController.Items.Item item, Boolean immediateEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:142)
Opsive.UltimateCharacterController.Items.Item.Start () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:254)
 
Hmm.. Can you attach the scene file? I should then be able to exactly reproduce what you are seeing. You only need to upload the actual scene - I should have the rest.
 
Thanks - can you also upload your item collection script? After that I should have enough to reproduce the error.
 
Can you download the latest release and see if you are still getting the error? I wasn't able to reproduce it but this release has many improvements and this one may happen to have been fixed. If not I think that I'll need one more file - the meta file for MyItemCollection. This will associate the correct GUIDs.
 
Even with the update the problem persists. Here is the meta file.
 

Attachments

  • MyItemCollectionMeta.asset.zip
    298 bytes · Views: 4
There we go! On line 261 of ItemSetManager.IsItemSetValid change:

Code:
            if (itemSetIndex >= m_CategoryItemSets[categoryIndex].ItemSetList.Count) {
to:
Code:
            if (itemSetIndex == -1 || itemSetIndex >= m_CategoryItemSets[categoryIndex].ItemSetList.Count) {
 
Opps, now it's back again.

This is what I have with the change:

public bool IsItemSetValid(int categoryIndex, int itemSetIndex, bool checkIfCanSwitchTo)
{
if (itemSetIndex == -1 || itemSetIndex >= m_CategoryItemSets[categoryIndex].ItemSetList.Count)
{
return false;
}

It appears to be the same error under the same conditions:

ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary`2[UnityEngine.Material,Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader+OriginalMaterialValue].Add (UnityEngine.Material key, OriginalMaterialValue value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader.InitializeCharacterFadeRenderers (UnityEngine.Renderer[] renderers) (at Assets/Opsive/UltimateCharacterController/ThirdPersonController/Scripts/Camera/ObjectFader.cs:602)
Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader.OnShowProjectile (UnityEngine.GameObject projectile, Boolean show) (at Assets/Opsive/UltimateCharacterController/ThirdPersonController/Scripts/Camera/ObjectFader.cs:625)
Opsive.UltimateCharacterController.Events.InvokableAction`2[UnityEngine.GameObject,System.Boolean].Invoke (UnityEngine.GameObject arg1, Boolean arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/InvokableAction.cs:132)
Opsive.UltimateCharacterController.Events.EventHandler.ExecuteEvent[GameObject,Boolean] (System.Object obj, System.String eventName, UnityEngine.GameObject arg1, Boolean arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/EventHandler.cs:425)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.DetermineVisibleProjectile (Boolean forceDisable) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:809)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.Equip () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:456)
Opsive.UltimateCharacterController.Items.Item.Equip (Boolean immediateEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:386)
Opsive.UltimateCharacterController.Inventory.InventoryBase.EquipItem (Opsive.UltimateCharacterController.Inventory.ItemType itemType, Int32 slotID, Boolean immediateEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:328)
Opsive.UltimateCharacterController.Character.Abilities.Items.EquipUnequip.ItemEquip (Int32 slotID, Boolean canUpdate) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/EquipUnequip.cs:849)
Opsive.UltimateCharacterController.Character.Abilities.Items.EquipUnequip.Update () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/EquipUnequip.cs:460)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.UpdateAbilities (Opsive.UltimateCharacterController.Character.Abilities.Ability[] abilities) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:622)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.UpdateUltimateLocomotion () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:549)
Opsive.UltimateCharacterController.Character.CharacterLocomotion.Move (Single horizontalMovement, Single forwardMovement, Single deltaYawRotation) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:455)
Opsive.UltimateCharacterController.Game.DeterministicObjectManager+DeterministicCharacter.FixedMove () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/DeterministicObjectManager.cs:146)
Opsive.UltimateCharacterController.Game.DeterministicObjectManager.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/DeterministicObjectManager.cs:589)
 
That's a different error - when I run your scene I don't receive that error so can you list the steps to reproduce?
 
Top