Bug: Inventory panel with tabs

HI,

UIS version 1.1.81

I have a strange bug with player inventory. I created a new inventory grid and add tabs.
SimplePanel.jpg
When I start the game I get the following error:
C#:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.UI.Grid.GridEventSystem.GetSelectedButtonIndex () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Grid/GridEventSystem.cs:345)
Opsive.UltimateInventorySystem.UI.Grid.GridEventSystem.GetSelectedButton () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Grid/GridEventSystem.cs:357)
Opsive.UltimateInventorySystem.UI.Grid.GridGeneric`1[T].DrawInternal () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Grid/GridGeneric.cs:306)
Opsive.UltimateInventorySystem.UI.Grid.GridBase.Draw () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Grid/GridBase.cs:311)
Opsive.UltimateInventorySystem.UI.Item.InventoryGrid.DrawInternal () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Item/InventoryGrid.cs:182)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase.Draw () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainerBase.cs:624)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.InventoryGridTabControlBinding.HandleTabChange (System.Int32 previousIndex, System.Int32 newIndex) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/InventoryGridTabControlBinding.cs:114)
Opsive.UltimateInventorySystem.UI.TabControl.SetTabOn (System.Int32 index) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/TabControl.cs:179)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.InventoryGridTabControlBinding.OnBindItemViewSlotContainer () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/InventoryGridTabControlBinding.cs:36)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.ItemViewSlotsContainerInventoryGridBinding.BindItemViewSlotContainer (Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase container) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/ItemViewSlotsContainerBinding.cs:127)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase.Initialize (System.Boolean force) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainerBase.cs:271)
Opsive.UltimateInventorySystem.UI.Item.InventoryGrid.Initialize (System.Boolean force) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Item/InventoryGrid.cs:84)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.ItemViewSlotsContainerPanelBinding.OnInitializeBeforeInventoryBind () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/ItemViewSlotsContainerPanelBinding.cs:62)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.InventoryPanelBinding.Initialize (Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel display, System.Boolean force) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/InventoryPanelBinding.cs:42)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.ItemViewSlotsContainerPanelBinding.Initialize (Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel display, System.Boolean force) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/ItemViewSlotsContainerPanelBinding.cs:42)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel.Setup (Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager manager, System.Boolean force) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanel.cs:130)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.SetupDisplayPanels (System.Boolean force) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:129)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.SetPanelOwner (UnityEngine.GameObject panelOwner) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:155)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.Initialize (System.Boolean force) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:118)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManager.Awake () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManager.cs:78)

and also (probably this is the react for previous error)
C#:
The Display Panel with the name 'Overflow Menu' for the menu of type 'OverflowInventoryMenu' was not found
UnityEngine.Debug:LogError (object,UnityEngine.Object)
Opsive.UltimateInventorySystem.UI.Panels.InventoryPanelOpener`1<YYG2.UI.OverflowInventoryMenu>:Initialize (bool) (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/InventoryPanelOpener.cs:82)
Opsive.UltimateInventorySystem.UI.Panels.PanelOpener:Start () (at Assets/3rd-Party/Opsive/UltimateInventorySystem/Scripts/UI/Panels/PanelOpener.cs:31)
YYG2.UI.OverflowMenuOpener:Start () (at Assets/Project/Scripts/Core/UI/Inventory/OverflowMenuOpener.cs:22)

The problem started when I added a tabs to the grid.
I found that problem is in method:

C#:
protected virtual EventSystem GetEventSystemForInternal(GameObject localGameObject)
        {
            if (localGameObject == null) {
                return EventSystem.current;
            }

            if (m_GameObjectToEventSystemMap.TryGetValue(localGameObject, out var eventSystem)) {
                if (eventSystem != null) {
                    return eventSystem;
                }
            }

            var root = localGameObject.transform.root;
            var identifier = root.gameObject.GetCachedComponent<EventSystemIdentifier>();

            eventSystem = identifier == null ? EventSystem.current : identifier.EventSystem;
        
            m_GameObjectToEventSystemMap[localGameObject] = eventSystem;
        
            return eventSystem;
        }

In line
C#:
eventSystem = identifier == null ? EventSystem.current : identifier.EventSystem;
I get the null as result

How can I solve the problem?
 
That's odd. I don't know how that error could be related to adding tabs.

Can you confirm that you have an Event System component in your scene (Its required to navigate UI in Unity):
1631870543498.png

Btw are you using split screen UI? If not then an "Event System Identifier" shouldn't be necessary. It is a component that we added such that multiple local players can control their own UI individually each using their onw event system.

Double check your canvas and see if you have an Event System Indentifier. If so either remove it or make sure it points to an Event System.

Finally I changed the line of code that caused the issue such that it can prevent it if an Evnent System Identifier is pointing to nothing:
Code:
eventSystem = identifier == null || identifier.EventSystem == null ? EventSystem.current : identifier.EventSystem;

Finally make sure all your Inventory UI is within the same canvas (exepct if you are using local split screen) with the Display Panel Manager and other required components.

I hope that helps
 
I don't have component "Event System Identifier". Problem is when I start the game and then EventSystem.current is null.
 
I create a temporary solution. I change the method in GridEventSystem
C#:
 protected int GetSelectedButtonIndex()
        {
            var eventSystem = EventSystemManager.GetEvenSystemFor(gameObject);
            if (eventSystem == null)
                return -1;
            for (int i = 0; i < m_Buttons.Length; i++) {
                if (eventSystem.currentSelectedGameObject == m_Buttons[i].gameObject) { return i; }
            }

            return -1;
        }
 
I'll add that fix to my code too. But the Event system OnEnable should be called before the Display Panel Manager.
What Unity version are you using?
Can you double check your script execution order?
1631879320964.png
 
Ah, you are using Rewired.
In that case you may want to use the "Rewired Event System" and use the "Event System Identifier" to point to it.
 
Top