Hello!
I hope everyone is doing well!
I am having issues with the inventory course. Currently, I’m on step 3 “Inventory Backing Store”. I imported the package to a test project and it works fine (as expected) however, I tried to integrate the code into my own project and it does not work.
The problem is that when I try to move an item to another slot, it resets to the original position when I drop it
I have tracked down the issue, and it is on this method on the DragItem class:
private IDragDestination<T> GetContainer(PointerEventData eventData)
{
if (eventData.pointerEnter)
{
var container = eventData.pointerEnter.GetComponentInParent<IDragDestination<T>>();
return container;
}
return null;
}
The problem is the method GetComponentInParent is returning null always. I tried doing this:
if (eventData.pointerEnter)
{
var container = eventData.pointerEnter.GetComponentInParent<IDragDestination<T>>();
//If we can't find the container in the parent, look for it in the gameobject
if (container == null)
{
container = eventData.pointerEnter.GetComponent<IDragDestination<T>>();
}
return container;
}
return null;
But it did not work.
As you can see, my InventorySlot prefab has the right script:
And the InventorySlotUI implements the right interface too:
public class InventorySlotUI : MonoBehaviour, IDragContainer<InventoryItem>
So I have no idea why is this happening, and the strangest thing is it USED to work, when I integrated the code from step 2 and the dragging and dropping of items worked only in the UI, it worked excellently and I was able to move items around
But now, it just doesn’t work, any ideas?
I have a repository on github with my project in case anyone would want to take a look, let me know.
Thanks!