Create Melee Item

c2green

New member
I am attempting to create my first third person character and equip with an item since my upgrade to 2.0. I'm running into an issue I was hoping you could assist with. I am able to set a new scene up as well as a character. He is able to move around with no issues and the camera works as I expected. Now when I attempt to create an item I get an error back - "IndexOutOfRangeException: Array index is out of range" with the end result that the weapon shows up in the main Items list but not the Items attached to the hand.

Below is an image of the filled out builder screen - this is strictly a third person item:

ItemSwordSetup.png

The error is coming from the BuildItem method. After researching the exception is getting thrown in ItemBuilder.cs at:

var itemSetManager = character.GetComponent<ItemSetManager>();
if (itemSetManager != null && itemType.CategoryIndices != null) {
for (int i = 0; i < itemType.CategoryIndices.Length; ++i) {
var category = itemSetManager.CategoryItemSets;

CategoryItemSets is empty which is what is throwing the exception. However the category on the Item Type is correct set to Weapons:

Category.png

I have been using your demo item collection while I play with the new version to get a better understanding. I'll attempt to make my own to see if it makes a difference. Outside of that I am not sure how to move forward. Any thoughts on what is causing this issue?


Stack trace at time of exception:

IndexOutOfRangeException: Array index is out of range.
Opsive.UltimateCharacterController.Utility.Builders.ItemBuilder.BuildItem (System.String name, Opsive.UltimateCharacterController.Inventory.ItemType itemType, Int32 animatorItemID, UnityEngine.GameObject character, Int32 slotID, Boolean addToDefaultLoadout, Boolean addFirstPersonPerspective, UnityEngine.GameObject firstPersonObject, UnityEngine.RuntimeAnimatorController firstPersonObjectAnimatorController, UnityEngine.GameObject firstPersonVisibleItem, Opsive.UltimateCharacterController.Items.ItemSlot firstPersonItemSlot, UnityEngine.RuntimeAnimatorController firstPersonVisibleItemAnimatorController, Boolean addThirdPersonPerspective, UnityEngine.GameObject thirdPersonObject, Opsive.UltimateCharacterController.Items.ItemSlot thirdPersonItemSlot, UnityEngine.RuntimeAnimatorController thirdPersonObjectAnimatorController, UnityEngine.Material invisibleShadowCasterMaterial, ActionType actionType, Opsive.UltimateCharacterController.Inventory.ItemType actionItemType) (at Assets/Opsive/UltimateCharacterController/Scripts/Utility/Builders/ItemBuilder.cs:118)
Opsive.UltimateCharacterController.Editor.Managers.ItemManager.DrawNewItem () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/ItemManager.cs:275)
Opsive.UltimateCharacterController.Editor.Managers.ItemManager.OnGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/ItemManager.cs:111)
Opsive.UltimateCharacterController.Editor.Managers.MainManagerWindow.OnManagerGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/MainManagerWindow.cs:407)
Opsive.UltimateCharacterController.Editor.Managers.MainManagerWindow.OnGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/MainManagerWindow.cs:310)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)
 
So I created a new ItemCollection for the Item Types and it resolved the issue. Which is odd as I did validate that the character's ItemSetManager was pointing to the correct collection. And you use the same collection in your demos. But it now works and I can move forward!
 
Top