Inventory.GetCurrencyComponent[T] NullReferenceException error

gas777

New member
Hello.

Getting Started with the Ultimate Inventory System

I setup according to this tutorial video. I Played game on Unity editor, then error was displayed below. Please tell me what shoud I do?
Source code is attached on last in this page.
Ultimate Inventory System 1.1.4 Unity 2019.4.15f1

NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory.GetCurrencyComponent[T] () (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/InventoryCollections/Inventory.cs:330)
Opsive.UltimateInventorySystem.UI.Menus.Shop.ShopMenu.OnInventoryBound () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Menus/Shop/ShopMenu.cs:130)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.InventoryPanelBinding.BindInventory (Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory inventory) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/InventoryPanelBinding.cs:89)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.InventoryPanelBinding.BindInventory () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/InventoryPanelBinding.cs:64)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.InventoryPanelBinding.Initialize (Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel display, System.Boolean force) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/InventoryPanelBinding.cs:44)
Opsive.UltimateInventorySystem.UI.Menus.Shop.ShopMenu.Initialize (Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel display, System.Boolean force) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Menus/Shop/ShopMenu.cs:74)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel.Setup (Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager manager, System.Boolean force) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanel.cs:129)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.SetupDisplayPanels (System.Boolean force) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:123)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.SetPanelOwner (UnityEngine.GameObject panelOwner) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:154)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.Initialize (System.Boolean force) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:112)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.Awake () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:72)


スクリーンショット 2021-02-15 22.42.56.png
 

Attachments

  • スクリーンショット 2021-02-15 22.42.56.png
    スクリーンショット 2021-02-15 22.42.56.png
    55.8 KB · Views: 1
Looking at the error it would seem that your character has a CurrencyOwner component and that this component either has null currencies or has currencies from the wrong database.

double check that you are using the correct database and reference the correct database objects in your scene.

The other thing that could cause this issue is your UI. Perhaps one of the UI components is trying to get a currency that does not exist.
Check the ShopMenu for any place where a wrong currency could be referenced

If you haven't done so yet you could press this button:
1613471750070.png
It may fix the error. What it does is scan the scene for any objects referencing the wrong database and replaces the reference by a valid one if possible.
 
Thanks for suggestions. My player character spawn 15 seconds later after game starting, because we have to wait for another player entering game. So first that error displayed, then player character spawn. Is this the reason?
 
The UI won't be initialized until a character is spawned.
If you spawn the character after the UI, you must assign a "Dynamic Panel Owner" on your character and the ID must match the DisplayPanelManager ID.

So I guess the following is happening.
You assigned the panel owner to the character in the scene or to a prefab.
The character in the scene is disabled until 15 seconds later, meaning the Inventory has not been initialized. But the UI starts initializing anyway because it has a reference to a panel owner.
And this breaks.

So two things I would do
1) on line 330 of the Inventory script add:
Code:
if (m_Currencies == null) { return null; }
This will replace the error by a warning.

2) to fix the issue completely remove the direct reference to the panel owner on the DisplayPanelManager. Instead use the IDs to get it dynamically with the Dynamic Panel Owner and Inventory Identifier components.

I hope this helps
 
Thanks a lot. It works well. Great! But I builded for iPhone, then the item on the floor isn't displayed. When player comes close to the item on the floor, pickup message is displayed. But the item on the floor isn't displayed. Please tell me what should I do?
 
Last edited:
Humm...
This could have somthing to do with the quality settings perhaps? The item might have a LOD which hides it from the camera? Perhaps it is culled from the camera? Or maybe there is a rigidbody and the item is falling through the ground but it's parent with a trigger is still in the initial position.

There can be many reason the item could disappear but non should have anything to do with the Inventory system
 
Thanks. Demo asset isn't displayed, but my own asset is displayed. Maybe it's related to the material or so. Anyway I will start using UIS.
 
Hello. Next problem! Opsive script files are recognized as Miscellaneous Files, not Assembly-CSharp files in Rider editor. So my script cannnot access method or variable in opsive script files. Please tell me what shoul I do, if you can.
 

@Justin

Thanks a lot. Rider was updated today, I challenged to import UIS again. Then Opsive scripts are recognized as Opsive.UltimateInventorySystem.Demo or so, and Rider works well with Opsive scripts and my scripts. My scripts can also access method and variables in opsive script files.
 
Last edited:
Top