- Home /
Is there a way to check if Scroll Rect is currently being dragged without using events?
As title says, i want to check if ScrollRect is currently dragged, but in some easy way, without implementing Drag interfaces, only from Scroll Rect reference if thats possible.
When I change my inspector view from Normal to Debug, there is a bool variable called "Dragging" in Scroll Rect and it shows exactly what I want, but I can't get its value from code. Is there any way to get its value or some other way to check if Scroll Rect is being dragged?
Answer by Bunny83 · Jan 15, 2018 at 02:33 PM
No, not without using reflection to access internal fields. As you might know large parts of the new UI system is open source. As you can see the m_Dragging bool is a private field of the ScrollRect class. If you want you can build your own UnityEngine.UI version but of course you have to keep it up to date.
Actually I didn't know it's open source and that might be useful in future so thank you. Too bad it's not public, but I'll somehow deal with it. Thanks anyway.
Answer by Likan1995 · Jun 17, 2020 at 02:30 PM
@Molioo, you can use default Eventsystem callbacks.
- Attach a script to the gameobject to which you have added the Scroll Rect component. 
- Inside that script inherit the interfaces named as IBeginDragHandler and IEndDragHandler (can use IDragHandler instead IBeginDragHandler). 
- Implement the methods from the interfaces named as OnBeginDrag and OnEndDrag 
- Now you have access to that private Dragging flag...well...sort of. :p 
 
That's it. Hope this helps.
Thanks. This helped. First I tried using IPointerDownHandler and it was triggering at a wrong time. IBeginDragHandler is the correct solution.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                