Unable to drop item

Hi, I am trying to implement inventory system in my project. Before this section everything worked. I was able to drag&drop items in the inventory. Currently I can drag an item but I can’t drop it. If I drop it it goes to the origin place. No error in console.

I tried use some logs. So and I see that in DragItem.cs A can’t get the source in this line:
source = sourceGameObject.GetComponent<IDragSource>();
Debug.Log("Awake source " + source);

in console log is only: Awake source

Same problem is here (also DragItem.cs):

private IDragDestination<T> GetContainer(PointerEventData eventData)
        {
            if (eventData.pointerEnter)
            {
                var container = eventData.pointerEnter.GetComponentInParent<IDragDestination<T>>();

                return container;
            }
            return null;
        } 

Debug.Log for container is nothing.

So I think problem would be somewhere here. But I don’t know how to get game object sourceInventorySlot(Clone) (based on our project)

Do you have an idea where could be a problem?

If you’re using the versions of the scripts in this section, be aware that they are not complete, nor is the setup within the scene complete. Everything is taylored to the specific goal trying to be shown in each lesson/section. When you get to the integration section, the Inventory.zip file contains all of the needed scripts (that + the changes Sam goes through in the integration section) to make the Drag system work properly.

I am using this package: 3 Inventory Backing Store
But how come in your project (same package) drag and drop works properly and in my not? For example if I use debug in your project I can see that source is sourceInventorySlot(Clone). This is weird.

But lets see If the drag system will work properly in integration section.

The only thing I can think is that the slot you’re dragging from (the source) doesn’t have an IDragContainer or IDragSource based script (an IDragDestination would accept an item, but you wouldn’t be able to drag from it, as it wouldn’t be a source.

Oh man, I got it. Thanks for the hint. I forgot this line: using GameDevTV.Inventories;
in InventoryDragItem.cs. Stupid mistake.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms