Hey guys
I'm working my way through giving my new character a pistol weapon. I'm using the online documentation and the demo scene as a reference.
When I run my scene I immediately get the following stack trace:
It comes from the following UCC Inventory method:
My inventory has a size of 2 (0 - Pistol, 1- Pistol Bullet) but for some reason UCC is checking for the pistol at index (Slot ID) 2, which is outside the bounds of the array. How can I resolve this problem?
As an aside, I'm becoming increasingly frustrated with the number of NullReference and IndexOutOfRange exceptions UCC generates. I previously ran into a problem where a custom movement type did not serialize properly, putting the asset into an unrecoverable state due to null-refs.
Digging through the source code I'm discovering a surprising lack of validation. Null-refs and out-of-bounds are situations that should never make it to the end user of your product.
It's extremely tempting to add null checks and other validation here and there, but I'd hate to lose that effort when upgrading to the next version of UCC. Is there a GIT repository for submitting PRs?
Thanks in advance for any help, and apologies for the belly-aching.
I'm working my way through giving my new character a pistol weapon. I'm using the online documentation and the demo scene as a reference.
When I run my scene I immediately get the following stack trace:
Code:
IndexOutOfRangeException: Index was outside the bounds of the array.
Opsive.UltimateCharacterController.Inventory.Inventory.GetItemInternal (System.Int32 slotID, Opsive.Shared.Inventory.IItemIdentifier itemIdentifier) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/Inventory.cs:161)
Opsive.UltimateCharacterController.Inventory.Inventory.HasItemInternal (Opsive.UltimateCharacterController.Items.Item item) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/Inventory.cs:64)
Opsive.UltimateCharacterController.Inventory.InventoryBase.HasItem (Opsive.UltimateCharacterController.Items.Item item) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:136)
Opsive.UltimateCharacterController.Items.Item.Start () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:352)
It comes from the following UCC Inventory method:
C#:
protected override Item GetItemInternal(int slotID, IItemIdentifier itemIdentifier)
{
if (itemIdentifier == null) {
return null;
}
if (m_ItemIdentifierMap[slotID].TryGetValue(itemIdentifier, out var item)) {
return item;
}
return null;
}
My inventory has a size of 2 (0 - Pistol, 1- Pistol Bullet) but for some reason UCC is checking for the pistol at index (Slot ID) 2, which is outside the bounds of the array. How can I resolve this problem?
As an aside, I'm becoming increasingly frustrated with the number of NullReference and IndexOutOfRange exceptions UCC generates. I previously ran into a problem where a custom movement type did not serialize properly, putting the asset into an unrecoverable state due to null-refs.
Digging through the source code I'm discovering a surprising lack of validation. Null-refs and out-of-bounds are situations that should never make it to the end user of your product.
It's extremely tempting to add null checks and other validation here and there, but I'd hate to lose that effort when upgrading to the next version of UCC. Is there a GIT repository for submitting PRs?
Thanks in advance for any help, and apologies for the belly-aching.