- Home /
Is it possible to drag UI item from ScrollRect to elsewhere without mask blocking item?
Hi there. I have a class implementing IDropHandler used on rect transforms as a plane to drag items onto and another that implements the IDragHandler (and begin/end variants) to allow for dragging elements to and from the class dropping IDropHandler. This works perfectly on straight panels and items can be moved from one panel to another with no problems.
However, when using a ScrollRect with the IDropHandler class any items dragged from it are blocked from view by its Mask component until the item has been moved to another panel. Once it is on another panel, it can then be moved onto the ScrollRect IDropHandler instance with no mask problems; it only occurs when the IDragHandler class is still parented to the ScrollRect's content gameobject and thus still within the mask.
I've experimented with resetting the IDragHandler class's parent to null and various parents, but for all intents and purposes this has not solved the problem or added additional issues. Is there a way to enable dragging items from a ScrollRect's bounds without the Mask blocking it from view?
How did you get the objects in the scrollrect to get drag events? When I try something similar the scrollrect gets the drag events, and no dragging of objects happens.
Don't suppose you can add the code, or at least where it came from, I am having a similar problem, I can't figure out how to make the drag drop go over the mask and the code we use may be different.
Answer by JoshuaMcKenzie · Feb 08, 2016 at 01:51 AM
you're close, you need to keep the draggable UI a child of a canvas for it to render properly, not set to null. so simply move it above the scrollrect and the mask in your canvas hierarchy.
since its not mentioned this should be noted just to be sure. for RectTransforms don't set transform.parent, but use transform.SetParent() instead. also be aware that setting parents can also mess up their scaling too. After calling SetParent() you usually want to call transform.localScale = Vector3.One;
I'll give this another shot and get back to you; I had not been using SetParent when attempting to remove it out of the mask. Thanks for the tip!