Error when dragging onto shape grid

Zaddo

Active member
I have a Problem Dragging from another container to a shape grid. It throws an error in ItemShapeDropPreviewItemView.ClearGridColorPreview because ItemShapeGrid is null.
ItemShapeGrid is referenced to ItemShapeItemView.ItemShapeGrid

I think this may have broken when I recently upgraded. I restored an old copy of my project and this works without error. I confirmed all the properties on the Shape Grid match the old project. I have another shapegrid in the scene, this works without error. But again the properties appear to be identical between the two grids.

I can't work out what what has changed to cause this. Do you know what might cause this error?

I have posted a short video showing the problem and properties.

I put a try/catch around the error so I can see the stack:

ITEMSHAPE: Object reference not set to an instance of an object
UnityEngine.Debug:Log (object)
Opsive.UltimateInventorySystem.UI.Item.ItemViewModules.ItemShapeDropPreviewItemView:ClearGridColorPreview () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewModules/ItemShapeDropPreviewItemView.cs:110)
Opsive.UltimateInventorySystem.UI.Item.ItemViewModules.ItemShapeDropPreviewItemView:SelectWith (Opsive.UltimateInventorySystem.UI.Item.DragAndDrop.ItemViewDropHandler) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewModules/ItemShapeDropPreviewItemView.cs:88)
Opsive.UltimateInventorySystem.UI.Item.DragAndDrop.ItemViewDropHandler:ItemViewSlotSelected (Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotEventData) (at Assets/DeadFear/Opsive/UltimateInventorySystem/Scripts/Custom/UI/UI/Grid/Item/DragAndDrop/ItemViewDropHandler.cs:285)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase/<>c__DisplayClass76_0:<Initialize>b__1 () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainerBase.cs:218)
Opsive.UltimateInventorySystem.UI.CompoundElements.ActionButton:OnSelect (UnityEngine.EventSystems.BaseEventData) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/CompoundElements/ActionButton.cs:316)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlot:OnSelect (UnityEngine.EventSystems.BaseEventData) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlot.cs:106)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlot:SetItemInfo (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlot.cs:79)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase:AssignItemToSlot (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo,int) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainerBase.cs:407)
Opsive.UltimateInventorySystem.UI.Grid.ItemShapeGrid:DrawInternal () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Grid/ItemShapeGrid.cs:300)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase:LateUpdate () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainerBase.cs:676)


EDIT: In the video, moving within the shape grid appeared to misbehave. But typically if the item is in the grid and I am just moving its position, there is no problem. The error only appears to occur when dragging from another container.

1659647363498.png
 
Last edited:
You error message line does not match anything in my project.
Are you sure you are using the latest version 1.2.10?

This is the function your error is refering to. But line 110 (your error line) is in the middle of the summary of another function for me.
Code:
/// <summary>
/// Clear the grid color preview.
/// </summary>
protected void ClearGridColorPreview()
{
    if(ItemShapeGrid?.ItemViewSlots == null){ return; }
    
    for (int i = 0; i < ItemShapeGrid.ItemViewSlots.Count; i++) {
        var view = ItemShapeGrid.GetItemViewAt(i);
        var itemShapePreview = view.GetViewModule<ItemShapeDropPreviewItemView>();
        itemShapePreview.m_ColorFilter.enabled = false;
    }
}

In the recent updates I made many changes to the Drag & Drop functionality especially between different containers. Because there was issues with Inventories not adding items in the correct spot especially when it came to ItemSlotCollections
 
Sorry I was on 1.2.9. I upgraded about a month ago, it must have been just before you released 1.2.10. I didn't pick up on this problem until recently.

I upgraded to 1.2.10 and I still have a problem. Although it has moved to the ItemShapeDropPReviewItemView.PreviewColor method, because you now have a check at the top of ClearGridColorPreview to return if ItemShapeGrid is null.

The screen capture/stack dump below shows where the error is. Exiting the method if ItemShapeGrid is null seems to fix the problem, i.e. Modify method with this line at top:

C#:
if (ItemShapeGrid == null || ItemShapeGridData == null) return;


1659700738294.png

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.UI.Item.ItemViewModules.ItemShapeDropPreviewItemView.get_ItemShapeGridData () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewModules/ItemShapeDropPreviewItemView.cs:33)
Opsive.UltimateInventorySystem.UI.Item.ItemViewModules.ItemShapeDropPreviewItemView.PreviewColor (Opsive.UltimateInventorySystem.UI.Item.DragAndDrop.ItemViewDropHandler dropHandler) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewModules/ItemShapeDropPreviewItemView.cs:121)
Opsive.UltimateInventorySystem.UI.Item.ItemViewModules.ItemShapeDropPreviewItemView.SelectWith (Opsive.UltimateInventorySystem.UI.Item.DragAndDrop.ItemViewDropHandler dropHandler) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewModules/ItemShapeDropPreviewItemView.cs:90)
Opsive.UltimateInventorySystem.UI.Item.DragAndDrop.ItemViewDropHandler.ItemViewSlotSelected (Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotEventData eventdata) (at Assets/DeadFear/Opsive/Mods/UltimateInventorySystem/Scripts/UI/Item/DragAndDrop/ItemViewDropHandler.cs:290)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase+<>c__DisplayClass78_0.<Initialize>b__1 () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainerBase.cs:222)
Opsive.UltimateInventorySystem.UI.CompoundElements.ActionButton.OnSelect (UnityEngine.EventSystems.BaseEventData eventData) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/CompoundElements/ActionButton.cs:316)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlot.OnSelect (UnityEngine.EventSystems.BaseEventData eventData) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlot.cs:106)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlot.SetItemInfo (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlot.cs:79)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase.AssignItemToSlot (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, System.Int32 slot) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainerBase.cs:414)
Opsive.UltimateInventorySystem.UI.Grid.ItemShapeGrid.DrawInternal () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Grid/ItemShapeGrid.cs:300)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainerBase.LateUpdate () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainerBase.cs:695)
 
Last edited:
Thank you, I'll use your fix for now.
If it ever turns out to be something more complicated fo let me know and I will see what I can do
 
Just wanted to chime in, I was also having this issue, and that fix seems to have worked for me as well. Thanks!
 
Top