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?
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;
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!
This worked great for me. Thanks.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
5 People are following this question.
Graphics.DrawTexture is not working with GUI.BeginScrollView
Standalone UI Mask
plz let me know how to use sprite mask?
how do i mask a sprite against a canvas?
Reading a masked texture?