UIS Setup with a prefab player

liquidsht

New member
i bought UIS yesterday and am having troubles with the initial setup.
When I setup Character and Inventory, it unbinds each time I close the setup window and would not let me bind the currency owner at all. I tried to bind it with the player prefab and it did add the Inventory, Item User, Item Hotbar Owner, Character Equipper scripts to my prefab. How would I setup UIS with player prefab? Thanks.

I am also getting these errors:
The component "Category Tab Control (Opsive.UltimateInventorySystem.UI.BoxDisplay.ItemGrid.ItemCategoryTabControl)" on the "Category Tab Control (UnityEngine.GameObject)" GameObject has objects that are not part of the active database. Please run the 'Replace Database Objects' script by right-clicking on the folder with the affected prefabs, scriptable objects, or scenes.
UnityEngine.Debug:LogError(Object)
Opsive.UltimateInventorySystem.Core.InventorySystemManager:CheckIfComponentIsValidWithLoadedDatabase(IDatabaseSwitcher) (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/InventorySystemManager.cs:259)
Opsive.UltimateInventorySystem.UI.BoxDisplay.ItemGrid.ItemCategoryTabControl:Awake() (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/BoxDisplay/ItemGrid/ItemCategoryTabControl.cs:23)

NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory.GetItemInfos[T] (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo[]& itemInfos, T filterParam, System.Func`3[T1,T2,TResult] filterFunc, System.Int32 startIndex) (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/InventoryCollections/Inventory.cs:668)
Opsive.UltimateInventorySystem.UI.BoxDisplay.ItemGrid.InventoryGrid.GetFilteredAndSortedItemAmounts (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo[]& itemAmounts, Opsive.UltimateInventorySystem.Core.ItemCategory itemCategory, System.Int32 sortIndex) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/BoxDisplay/ItemGrid/InventoryGrid.cs:391)
Opsive.UltimateInventorySystem.UI.BoxDisplay.ItemGrid.InventoryGrid.SetCategoryPageCounts () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/BoxDisplay/ItemGrid/InventoryGrid.cs:337)
Opsive.UltimateInventorySystem.UI.BoxDisplay.ItemGrid.InventoryGrid.BeforeDrawing () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/BoxDisplay/ItemGrid/InventoryGrid.cs:324)
Opsive.UltimateInventorySystem.UI.BoxDisplay.GridBase.Draw () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/BoxDisplay/GridBase.cs:170)
Opsive.UltimateInventorySystem.UI.BoxDisplay.ItemGrid.InventoryGrid.SetInventory (Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory inventory) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/BoxDisplay/ItemGrid/InventoryGrid.cs:200)
Opsive.UltimateInventorySystem.UI.InventoryMenu.OpenInternal () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/InventoryMenu.cs:53)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel.Open (Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel previousPanel, UnityEngine.UI.Selectable previousSelectable, System.Boolean selectDefault) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanel.cs:132)
Opsive.UltimateInventorySystem.UI.MainMenu.OpenMenu (System.Int32 index) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/MainMenu.cs:118)
Opsive.UltimateInventorySystem.UI.MainMenu.Initialize () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/MainMenu.cs:83)
Opsive.UltimateInventorySystem.UI.MainMenu.Open (Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel previousPanel, UnityEngine.UI.Selectable previousSelectable, System.Boolean selectDefault) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/MainMenu.cs:99)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.OpenMenu (Opsive.UltimateInventorySystem.UI.DisplayMenuPanel menu) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:140)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.OpenMainMenu () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:148)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.ToggleMainMenu () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:167)
UnityEngine.Events.InvokableCall.Invoke () (at <58a34b0a618d424bb5fc18bb9bcdac20>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <58a34b0a618d424bb5fc18bb9bcdac20>:0)
UnityEngine.UI.Button.Press () (at G:/unity/2019.3.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at G:/unity/2019.3.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at G:/unity/2019.3.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at G:/unity/2019.3.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
Rewired.Integration.UnityUI.RewiredStandaloneInputModule:processMousePress(MouseButtonEventData) (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:1091)
Rewired.Integration.UnityUI.RewiredStandaloneInputModule:processMouseEvent(Int32, Int32) (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:992)
Rewired.Integration.UnityUI.RewiredStandaloneInputModule:processMouseEvents() (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:976)
Rewired.Integration.UnityUI.RewiredStandaloneInputModule:process() (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:690)
UnityEngine.EventSystems.EventSystem:Update() (at G:/unity/2019.3.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
 
Last edited:
Hi @liquidsht

I'm not sure I understand your issue with the player prefab. Could you give me more detail as to what you wish to achieve and the steps you took to achieve it? I'm assuming you are using UCC and UIS integration, could you confirm that?

As for the errors. You most likely created your own database, but you some of the objects in the scene are referencing objects from the demo database. This is often the case if you grabbed prefabs from the demo scene.

in your case it seems that some of the UI is using categories from the demo database for the tabs. The easy work around for this is to update your scene to use the new database: 1600762223409.png
But sometimes that won't be enough as you may spawn prefabs at runtime which may have reference to the wrong database. So you can update the entire project by right clicking on a folder in the project view and pressing Ultimate Inventory System -> Replace Database Objects (not recommened). This will use the database you have referenced in your editor widow. It's better to duplicate the prefabs/scriptable objects you want, take them out of the Opsive folders and then update them.

The second error seems weird, it may be only happening because the first one occurred.
 
I am not using UCC I am using another asset called corgi engine for my 2d game. When I load my game I use that asset to instantiate my player from the player prefab.
So I was trying to bind the prefab in the main set up screen, it lets me bind the inventory but not the currency. But when I close and re open the main set up screen the binding is no longer there.
I tried putting my player prefab in the scene manually instead of instantiating the player, and go through the setup screen and didn’t have the same problems but I do need to instantiate the player as that’s how my game loads.
 
Ah I see.

Using a prefab to create the Inventory menu won't work like you are hoping. a reference to a prefab is different to a reference from an instance of a prefab.

The main setup window is something you'll use once to setup your character and create your inventory menu. You won't need to use it after that. You do not bind the prefab to the menu through the setup window. That field is simply used such that the inventory and currency is correctly referenced when the UI is created. To help, the inventory and currencyOwner fields in the editor are automatically set to the first one it can find in the scene. I think that might be what caused the confusion.

By default all the inventory/currency UI will find the inventory/currencyOwner on the gameobject with the "Player" tag if none is specified in the inspector. It will do so in the initialize phase. So as long as your player is spawned before that and it has the "Player" tag, things should work.

If that's not possible, the other solution is to find all the UI after your character is spawned and manually assign the reference to the inventory/curencyOwner through code.

Example:

Code:
player = get player after spawned

currencyOwnerMonitor.SetCurrencyOwner(player.GetComponent<CurrencyOwner>());

inventoryGrid.SetInventory(player.GetComponent<Inventory>())

You can create a simple custom script for that and manually drag and drop the currencyOwnerMonitor and InventoryGrid in serialized fields such that you do not have to find them at runtime.

I hope that makes sense, let me know if things still aren't clear
 
Right, so the main screen is just for initial set up? It would let me add the player as the currency owner, so can I just add the currency owner script to the player prefab?

Also, is there any way for me to change the input? the keyboard imports are currently not working as I think Unity is only picking up the input from Corgi Engine.
 
Yes you can manually add the currencyOwner to the character prefab.

I'm not familiar with the corgi engine so I'm not sure how it can impact UIS. All UI input is done using the Unity EventSystem and standalone input module. I know that the new Input System and Rewired replace those components, so corgi engine might do so too.

As for the player, I would strongly recommend not using the character scripts from UIS they are purely for the demo and aren't made as scalable as the core UIS system. But if you really wish to use it you'll have to replace the characterInput component but your own custom script that uses the corgi input.
 
I am using the corgi asset for my player controls but also integrated with Rewired. I can click on the Main menu button but the keyboard doesnt work. So I am guessing i need to go into UIS's input system and make changes there? Can you tell me where i would find that script in UIS? Sorry if my question doesnt make sense, as I am quite new to c# and unity. Thanks.
 
Last edited:
Sorry for the late reply as I have been busy, but have tested out the Rewired method with a new project that only has Rewired and UIS. I followed the steps in the Rewired page. I could only get Rewired and UIS working together in UIS's demo scene, but not within the inventory menu. So I could walk around in the scene and pick up items and open inventory "i" and close inventory using "Escape" key.
 
So you definitely replaced the stand alone input module by the rewired stand alone input module, following the steps in the link I sent you above?
That's what controls the UI so there shouldn't be anything else to do. Make sure there's not another EventSystem component in the scene.

To make sure it works correctly try creating an empty scene with two buttons and use the rewired input module to move between the two buttons. If that works it should work in the Inventory menu
 
As you suggested, now I have a test canvas with 4 buttons that works only with the rewired input and rewired input manager active. I sort of can get it working with Rewired in my game. These are the issues I am still having.
1. I need to click on the the inventory button with my mouse, "I" on keyboard still doesnt work, how would I assign a key to open inventory?
2. Once I am in the inventory menu, i need to hover my mouse over the inventory panels, then I can use WASD keys to move around in the inventory.
Thanks
 
You can set a button to open a panel through code or using the InventoryStandardInput inspector:
1607935342217.png
Note: You can only open high level panels using the inspector. Meaning that if you have the Inventory grid within a main menu, you can open the main menu but not necessarily the Inventory Grid. The only work around is to open the panels in the order you want through code.

You can choose to select the first slot in the grid by ticking the "Select Slot On Open" field on for the "Item View Slots Container Panel Binding" component (This component references you Inventory Grid):
1607935539224.png

Make sure you are using the latest version 1.1.2 as there are quite a few bug fixes and structural changes compared to the previous versions (Make sure to read the release notes before you upgrade as some actions are required on your part to make sure the update goes smoothly)
 
Top