Index out of range exception on Pick Up Item

zambii

New member
Hello, it's me again with another question I seem not to be able to find the answer to. ?

I was able to update to the newest UCC version and it's great! Everything had a smooth transition and is working perfectly fine.
There is only one thing that, for some reason that I can't figure out, is not working correctly.

When my character picks up the item pick up and then goes to pick up another item pick up, it will throw this IndexOutOfRangeException when that ability detects another item pick up. It's like it doesn't clear the previous pick up and tries to access that one instead?

It does not happen on the demo scene but it happens when I create a new character. I see no difference between my setup and the demo setup but clearly, I'm missing something?

IndexOutOfRangeException: Index was outside the bounds of the array. (wrapper stelemref) System.Object.virt_stelemref_class(intptr,object) Opsive.UltimateCharacterController.Character.Abilities.PickpUpWeapon.ValidateObject (UnityEngine.GameObject obj, System.Nullable`1[T] raycastHit) (at Assets/_Assets/Scripts/Player/Abilities/PickUpWeapon.cs:153) Opsive.UltimateCharacterController.Character.Abilities.DetectObjectAbilityBase.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/DetectObjectAbilityBase.cs:225) Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:2166)
 
It looks like that exception is coming from a custom ability so I would set a breakpoint and start debugging there.
 
It looks like that exception is coming from a custom ability so I would set a breakpoint and start debugging there.
It is a 'custom' ability but all I did was duplicate PickUpItem.cs and rename the class to PickUpWeapon so there should be no reason why one throws an error and the other one does not.

I also added this couple of lines inside CanStartAbility():

C#:
ItemDefinitionBase pistolDefinition = m_PickupItemDefinitions[0];
            ItemDefinitionBase revolverDefinition = m_PickupItemDefinitions[0];
            for(int i = 0; i < m_PickupItemDefinitions.Length; i++)
            {
                if(m_PickupItemDefinitions[i].name == "Pistol")
                    pistolDefinition = m_PickupItemDefinitions[i];

                if(m_PickupItemDefinitions[i].name == "Revolver")
                    revolverDefinition = m_PickupItemDefinitions[i];
            }
            IItemIdentifier pistolIdentifier = pistolDefinition.CreateItemIdentifier();
            IItemIdentifier revolverIdentifier = revolverDefinition.CreateItemIdentifier();

            if(m_AvailableItemPickups[0].GetItemDefinitionAmounts()[0].ItemIdentifier == pistolIdentifier)
            {
                return m_Inventory.GetItemIdentifierAmount(pistolIdentifier) < 2;
            }

            if(m_AvailableItemPickups[0].GetItemDefinitionAmounts()[0].ItemIdentifier == revolverIdentifier)
            {
                return m_Inventory.GetItemIdentifierAmount(revolverIdentifier) < 2;
            }

but I don't see how that would affect it in any way, and I added the same lines in the same place to the PickUpItem class and it works fine.

So both classes are identical but one throws an error and the other does not. This is where I'm lost.
The reason I duplicated the ability and customized the duplicate is that I don't want to change any of the files that come with the asset so I can keep updating the asset without a worry of losing any progress.
 
Hard for us to help without knowing exactly what's in your custom ability (specifically line 153, referred to by the error log).

Also, you may want to subclass PickUpItem instead of duplicating it. This means your custom ability script can be a smaller file, and if PickUpItem ever gets changed in a future update, your ability will automatically get those updates too (apart from any parts you've overridden, of course).
 
Hard for us to help without knowing exactly what's in your custom ability (specifically line 153, referred to by the error log).

Also, you may want to subclass PickUpItem instead of duplicating it. This means your custom ability script can be a smaller file, and if PickUpItem ever gets changed in a future update, your ability will automatically get those updates too (apart from any parts you've overridden, of course).

I see that is actually a better idea, but because some of the information I needed is private I refrained from doing any changes to the scripts so instead, I did an external workaround which is working just fine.

I did what you said about subclassing them, can't believe I didn't think of it thanks for that!
There is one other thing that is buggin' me though and this has happened before the update and was hoping that a clean install from the updated version would make it go away but it did not.

What happens is, when the player picks up the first item, everything works fine and it equips it, but for some reason, the UI does not get updated?

Before picking up:
1613548401731.png
After picking up:
1613548466290.png
After picking up another one:

1613548529659.png


I'm wondering if there is some sort of setup that is needed to be done in order to get that pick up to work correctly?
 
Each item's UI Monitor ID must match with the Slot Item Monitor ID that you want to use to display that item. In the demo scene, there are two pistol items - one for each slot - and they use different UI Monitor IDs so that they are each displayed in a different Slot Item Monitor. It looks like you're using just one pistol item in both slots, so you won't be able to have them appear in two separate Slot Item Monitors.
 
This is how the item setup is:
1613659437173.png
and they both seem to have the correct UIMonitor ID (0 for right and 1 for left):
1613660624934.png
1613660602992.png
 
I also noticed that when I start it adds two additional itemsets at the bottom for some reason:
1613661233265.png
and if I pick up the item when no item set is active then the UI is updated correctly:
1613662077792.png
 
Last edited:
I'm assuming those two Body items in the Item Set are for "Fists" and "Kicks" and that those items have been assigned to the appropriate slots.

Since you've got 2 separate Body items, one in each slot, then your Item Set setup will need to be a bit different than the demo scene. I think you'll need at least these sets: (I'll refer to Body0 and Body1 as the Body items for slots 0 and 1)

- Body0 + none
- Body0 + Body1
- None + Body1
- Pistol0 + none
- Pistol0 + Body1
- None + Pistol1
- Body0 + Pistol1
- Pistol0 + Pistol1

The reason those two extra Item Sets are getting added I believe is because Body0 and Body1 could be equipped independently and you didn't have those Item Sets setup, so it made them.
 
I'm assuming those two Body items in the Item Set are for "Fists" and "Kicks" and that those items have been assigned to the appropriate slots.

Since you've got 2 separate Body items, one in each slot, then your Item Set setup will need to be a bit different than the demo scene. I think you'll need at least these sets: (I'll refer to Body0 and Body1 as the Body items for slots 0 and 1)

- Body0 + none
- Body0 + Body1
- None + Body1
- Pistol0 + none
- Pistol0 + Body1
- None + Pistol1
- Body0 + Pistol1
- Pistol0 + Pistol1

The reason those two extra Item Sets are getting added I believe is because Body0 and Body1 could be equipped independently and you didn't have those Item Sets setup, so it made them.
Didn't know that was a requirement, thanks! This helped with the itemsets activating the correct one.
For the UI issue, I found out that while the pistols had the correct monitor to them, the kicks did not and that is what was toggling off the UI when picking up the new weapon. Thanks a lot for your help!
 
Top