Author Topic: Drag and Drop with the "Clone" object  (Read 1457 times)


  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 30
    • View Profile
Drag and Drop with the "Clone" object
« on: October 02, 2014, 07:41:11 PM »
I'm so glad there is a clone option, that is exactly what I wanted!  However it looks like the cloned GameObject is being destroyed after releasing the DragDropItem!

  1.         protected virtual void OnDragDropRelease (GameObject surface)
  2.         {
  3.                 if (!cloneOnDrag)
  4.                 {
  5.                         ...
  6.                 }
  7.                 else NGUITools.Destroy(gameObject);
  8.         }

Why?!  In my game I have an inventory, just imagine you have a stack of potions represented by 1 DragDropItem widget, and I want to drag just one of these potions onto my belt, for example.

Things I don't know and need help with:

1. The duplicated potion widget is getting destroyed and not sticking to my belt DragDropContainer slot. I would like this duplicate to be re-parented just like the origin would be if I'm not using duplicates.
2. How do I get notified that the DragDropItem has been released?  Does my belt slot need to have a function defined and it will get called whenever an item is dropped on it? I don't see the DragDropContainer having any mechanism allowing me to add a delegate to be called.
3. Does it look like I will have to extend the UIDragDropItem class to implement re-parenting of the clone? And extending UIDragDropContainer so that I can get notified when an item is dropped?  I have very specific slots and need to know when items are dropped on them and when items are removed from them.

Attached a screenshot so it will give you an idea what I'm trying to do.


  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag and Drop with the "Clone" object
« Reply #1 on: October 02, 2014, 11:04:49 PM »
Overwrite the OnDragDropRelease function in your custom class and do what you want inside, including not destroying it.