Hi! I was following the tutorial on Ultimate Inventory System and Ultimate Character Controller integration. I have tried to follow it 3 times and every time I get the same error.
When it triggers:
1. When trying to pickup an item with auto equip in third person view
2. After changing the perspective from FPV to TPV when having an item equiped
The error:
On pickup
Every frame after pickup:
Result:
On pickup in First person view everything works as expected. The item shows up correctly on the player
On pickup in third person view the item doesn't show on the player. The player animator is updated correctly.
Some debuging:
When it triggers:
1. When trying to pickup an item with auto equip in third person view
2. After changing the perspective from FPV to TPV when having an item equiped
The error:
On pickup
Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Items.Item.IsActive () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:648)
Opsive.UltimateCharacterController.Items.Item.set_ShowFullScreenUI (System.Boolean value) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:148)
Opsive.UltimateCharacterController.Items.Item.Equip (System.Boolean immediateEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:501)
Opsive.UltimateCharacterController.Inventory.InventoryBase.EquipItem (Opsive.Shared.Inventory.IItemIdentifier itemIdentifier, System.Int32 slotID, System.Boolean immediateEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:350)
Opsive.UltimateCharacterController.Character.Abilities.Items.EquipUnequip.ItemEquip (System.Int32 slotID, System.Boolean canUpdate) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/EquipUnequip.cs:1001)
Opsive.UltimateCharacterController.Character.Abilities.Items.EquipUnequip.Update () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/EquipUnequip.cs:665)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.UpdateAbilities (Opsive.UltimateCharacterController.Character.Abilities.Ability[] abilities) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:794)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.UpdateUltimateLocomotion () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:725)
Opsive.UltimateCharacterController.Character.CharacterLocomotion.Move (System.Single horizontalMovement, System.Single forwardMovement, System.Single deltaYawRotation) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:477)
Opsive.UltimateCharacterController.Game.KinematicObjectManager+KinematicCharacter.Move (System.Boolean manualMove) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/KinematicObjectManager.cs:237)
Opsive.UltimateCharacterController.Game.KinematicObjectManager.Update () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/KinematicObjectManager.cs:841)
Every frame after pickup:
Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Items.Item.IsActive () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:648)
Opsive.UltimateCharacterController.Character.ItemHandler.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/ItemHandler.cs:43)
Result:
On pickup in First person view everything works as expected. The item shows up correctly on the player
On pickup in third person view the item doesn't show on the player. The player animator is updated correctly.
Some debuging:
- Awake in Item.cs was called
- Item.cs lines 235-243
C#:
for (int i = 0; i < perspectiveItems.Length; ++i) {
// Initialize the perspective item manually to ensure an Object GameObject exists. This is important because the Item component will execute
// before the FirstPersonPerspectiveItem component, but the FirstPersonPerspectiveItem component may not be completely initialized.
// The FirstPersonPerspectiveItem component must be initialized after Item so Item.Start can be called and add the item to the inventory.
Debug.Log("Perspective items length - " + perspectiveItems.Length); //prints "2"
if (!perspectiveItems[i].Initialize(m_Character)) {
Debug.Log("Skipping"); //Is called once
continue;
}