Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

child objects blocking scrollrect from scrolling

Discussion in 'UGUI & TextMesh Pro' started by pat_sommer, Mar 17, 2015.

  1. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    i am making a desktop application, i would like the user to be able to scroll the scrollrect by clicking and dragging, even over other objects with event system components.

    Basically:
    user can click on the child objects inside the scroll rect with a click event
    if user clicks down and drags, scroll rect should scroll and click up should cancel

    sort of looking for mobile style functionality.

    any thoughts?
    Thanks
     
  2. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    I have exactly the same problem and have not been able to solve it. Attached a test scene to illustrate the problem.

    I suppose many people are building some kind of drag-able menus full of buttons, maybe too trivial and we are overlooking something?
     

    Attached Files:

    MilenaRocha and friuns3 like this.
  3. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    bump? anything on this? its a rather big issue for my use case, if the UI system doesnt offer this i may have to abandon it
     
  4. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    I've got a scroll rect full of buttons and it scrolls just fine by dragging (at least on Windows).

    Is your content made out of Button components or EventTrigger components? My understanding is that EventTrigger captures all events, but Buttons should only capture pointer enter/exit/click, not drag.
     
    markkmlam, Vagonn and glitchers like this.
  5. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    right, im seeing if the button has a OnClick() function, but i need more functionality then OnClick. i need to call methods besides changing color on mouse over and exit as well, so from what i see i need to add an EventTrigger, and thats actually where im seeing the problem.

    any way to call functions on mouse enter / exit on buttons without event triggers?
     
  6. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Yes--you can write your own component that implements the IPointerEnterHandler and IPointerExitHandler interfaces. As long as you don't implement the drag handlers, drag events should pass right through.
     
  7. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    thank you Antistone exactly what i was looking for
     
  8. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    Do you mind posting simple example of your implementation? Would be really helpful.
     
  9. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    sure, theres a few small steps to take to get the methods to work
    Im using C#, im not sure on exact translation if your using javascript

    first, import event systems
    Code (CSharp):
    1. using UnityEngine.EventSystems;
    then add event types to your class (this will change depending on the type of events you are using, ignore 'InfinityScrollCell', that is my base class, yours will most likely say 'MonoBehaviour' )
    Code (CSharp):
    1. public class TimeLineCell : InfinityScrollCell,IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler,IPointerDownHandler
    finally implement the methods
    Code (CSharp):
    1. public void OnPointerEnter (PointerEventData eventData)
    2.     {
    3.         mouseOver = true;
    4.         highlightCell (true);
    5.     }
    6.  
    7.     public void OnPointerExit (PointerEventData eventData)
    8.     {
    9.         mouseOver = false;
    10.         highlightCell (false);
    11.     }
    12.  
    13.     public void OnPointerDown (PointerEventData eventData)
    14.     {
    15.         if (parentScrollRect.scrollRect.velocity.magnitude > 0) {
    16.             canClick = false;
    17.         }
    18.     }
    19.  
    20.     public void OnPointerClick (PointerEventData eventData)
    21.     {
    22.         if (canClick == true) {
    23.                   // add code for click here
    24.         }
    25.         canClick = true;
    26.     }

    as a tip, i recommend blocking the click method if the scrollRect is moving when the user clicks down. this way the first click will stop the scroll rect from moving, second click will be selecting the button/object. you can see some sample logic in OnPointerDown and OnPointerClick

    one nice thing about this is this can be added to any rectTransform, so you dont have to use button objects, however, i have not done any hit testing with overlapping views
     
    Last edited: Mar 27, 2015
    fronzu and EnriqueL like this.
  10. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    Whoa cool, thanks for such a fast answer. I do work mainly with C# but am rather newcomer when it comes to this kind of tweaking. Will try to use your instructions!
     
  11. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    no problem, you may want to mess with the threshold for clicking. in my sample i have it set to '0' but im seeing sometimes even when the scrollRect.velocity.magnitude looks to be still, its returning slightly above zero, im finding '0.1' to be more stable
     
  12. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    Im now finally trying to follow your instructions. I suppose "highlightCell" etc are somehow based on the uGUI stuff on the background, sorry for my ignorance, but I get following error with your code: Assets/DragHandler.cs(14,17): error CS0103: The name `mouseOver' does not exist in the current context. And same error for highlightCell etc.

    Here is my full code:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4. using UnityEngine.EventSystems;
    5.  
    6. public class SkipDragHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler,IPointerDownHandler
    7. {
    8.  
    9.     private bool canClick;
    10.  
    11.  
    12.     public void OnPointerEnter (PointerEventData eventData)
    13.     {
    14.         mouseOver = true;
    15.         highlightCell (true);
    16.     }
    17.  
    18.     public void OnPointerExit (PointerEventData eventData)
    19.     {
    20.         mouseOver = false;
    21.         highlightCell (false);
    22.     }
    23.  
    24.     public void OnPointerDown (PointerEventData eventData)
    25.     {
    26.         if (parentScrollRect.scrollRect.velocity.magnitude > 0) {
    27.             canClick = false;
    28.         }
    29.     }
    30.  
    31.     public void OnPointerClick (PointerEventData eventData)
    32.     {
    33.         if (canClick == true) {
    34.             // add code for click here
    35.             Debug.Log ("OnPointerClick detected!");
    36.         }
    37.         canClick = true;
    38.     }
    39.  
    40. }
    If I understand correctly, canClick is your own stuff, so I just created variable for it and it is ok. But how to proceed with the rest?
     
    Last edited: Apr 28, 2015
  13. CxydaIO

    CxydaIO

    Joined:
    May 12, 2014
    Posts:
    61
    mouseOver and highlightCell is also own stuff just delete them and fill the methods with your own stuff... you don't need the variables, the Events (OnPointerEnter , OnPointerExit etc) get triggered anyway

    this is enough
    Code (CSharp):
    1.  
    2. public class YourClass: MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler,IPointerDownHandler
    3. {
    4. public void OnPointerEnter (PointerEventData eventData)
    5.     {
    6.           //do stuff
    7.     }
    8.     public void OnPointerExit (PointerEventData eventData)
    9.     {
    10.           //do more stuff
    11.     }
    12.     public void OnPointerDown (PointerEventData eventData)
    13.     {
    14.          //do wicked stuff
    15.     }
    16.     public void OnPointerClick (PointerEventData eventData)
    17.     {
    18.           //do random stuff
    19.     }
    20. }
     
    Cromfeli likes this.
  14. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    Attached now the version including the code from pat_sommer and PBeast fixes. Unfortunately it still is not working. I am afraid that my lack of working with the event system in this way does not allow me to see the obvious. PBeast would you mind taking a look at the example project and see where I go wrong?

    Ultimately I try to use this with toggle on top of the scroll rect. But even disabling the toggle and just using image component with rect transform does not make the drag handler "go through" the button.
     

    Attached Files:

  15. CxydaIO

    CxydaIO

    Joined:
    May 12, 2014
    Posts:
    61
    Am i guessing right that you want to have your toggle clickable but you DON'T want it to block drags? So that you can drag the scrollRect even if you begin the drag over the toggle?
     
  16. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    Yes, exactly that :)
     
  17. CxydaIO

    CxydaIO

    Joined:
    May 12, 2014
    Posts:
    61
    hm okay, i never did this before and as Antistone mentioned the dragevent SHOULD pass right through but actually it does not o.0. Sorry i'm no master so i don't know what we are doing wrong here or if this is a bug.

    But i can say that you cant add a SkipDrag script and add it to you toggle, your toggle blocks the drag, so you have to write your own toggle class. I tried but i think even the Image component blocks the dragEvent from passing through :(

    Sorry for being no help :'(
     
  18. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    No worries PBeast! I'm very grateful for the fact that you even try to help! I will keep studying how to write this toggle by myself :)
     
  19. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    Im now just trying to simplify everything to make the Drag event go through the button. Apparently no matter what even if I dont have drag on the script, the image itself will block raycast and it is simply not possible for the scrollrect detect the drag?

    Edit: Now I got it to work, the toggle MUST be as child to the ScrollRect for it to go through and I had to naturally remove the default implementation of the events to be replaced with my own version that did not have drag handling. For the OnValueChanged that seems to work just fine as is.

    Attachment: Example project with working solution and example of an custom OnPointerDown event.
     

    Attached Files:

    Last edited: May 4, 2015
  20. Naphier

    Naphier

    Joined:
    Aug 4, 2014
    Posts:
    114
    It seems this is still an issue. I have a Scroll rect with a bunch of buttons in it. If you use the scroll wheel and the pointer is over a button or an image without a CanvasGroup with blocksRaycasts=false then it prevents scrolling. When I used to write my own UI for a different engine the scroll rect would always check for it's own interaction first and then the elements within it. This seems like a major flaw in the UI system! Hopefully Unity will address this. And thanks for the hack, I'll give it a go.
     
    PNUMIA-Rob, Zullar and Cromfeli like this.
  21. Naphier

    Naphier

    Joined:
    Aug 4, 2014
    Posts:
    114
    Seems to be an issue with EventTriggers for me. I have event triggers for onPointerEnter/Exit so that we can do a hover UI. There are workarounds, but still seems like Unity should automatically handle priorities or add these triggers to the UI system instead of the old event triggers...
     
  22. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    As I said way up in post #4 in this thread, my understanding is that the EventTrigger component captures ALL events, whether you assign listeners to them or not, and so nothing will be passed up the chain. If you want to capture only some events, you can write your own component that implements only the interfaces for the events you need.

    Making EventTrigger only capture the events that you're specifically listening for is likely problematic because listeners could be added or removed at runtime.
     
  23. Naphier

    Naphier

    Joined:
    Aug 4, 2014
    Posts:
    114
    I think the issue may also lie in the event system listening to pointer over events. If those were accessible then I could use those instead, but they don't appear to be. Maybe it is better to add a script to the button GO and use OnMouseEnter/OnMouseExit. I think I'll give this a shot when I get back to it.
     
  24. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    I have the exact same problem! Anybody has an solution?
     
  25. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    No one? This is a huge problem to me!
     
  26. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    202
    This not working anymore?
     
  27. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    I found a fix.... I added this to all my buttons which are over the ScrollRect! I have to set MainScroll to the Main Scroll Rect and all is working as expected now. But I think this should be the default behavior.

    Code (csharp):
    1.  
    2.  
    3. public class FixScrollRect: MonoBehaviour, IBeginDragHandler,  IDragHandler, IEndDragHandler, IScrollHandler
    4. {
    5.     public ScrollRect MainScroll;
    6.  
    7.  
    8.     public void OnBeginDrag(PointerEventData eventData)
    9.     {
    10.         MainScroll.OnBeginDrag(eventData);
    11.     }
    12.  
    13.  
    14.     public void OnDrag(PointerEventData eventData)
    15.     {
    16.         MainScroll.OnDrag(eventData);
    17.     }
    18.  
    19.     public void OnEndDrag(PointerEventData eventData)
    20.     {
    21.         MainScroll.OnEndDrag(eventData);
    22.     }
    23.  
    24.  
    25.     public void OnScroll(PointerEventData data)
    26.     {
    27.         MainScroll.OnScroll(data);
    28.     }
    29.  
    30.  
    31. }
    32.  
    33.  
    34.  
    35.  
     
  28. GarretPolk

    GarretPolk

    Joined:
    May 26, 2013
    Posts:
    49
    Thanks so much for this solution. I have a couple UI's with nested child objects where mouse wheel scrolling wasn't working. It's been driving me nuts for months. I suspected that the events were being eaten by the child objects but I didn't want to deal with it.
     
    sevensails likes this.
  29. rainini

    rainini

    Joined:
    Nov 26, 2015
    Posts:
    3
    My solution is Call the events of parent scroll rect in the event handler of child object .
    for example:
    private void OnScrollRectChildButtonDrag(PointerEventData eventData)
    {
    // do my button drag stuff

    // call parent scroll rect handler
    parentScrollRect.OnDrag(eventData);
    }
     
  30. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Just a note: you have to implement all I*DragHandler and pass all the events to the parent ScrollView, otherwise it will result in jumpy and inaccurate results because the data from the Start event is used to calculate the dragging.
     
    Last edited: Mar 29, 2016
    attilam likes this.
  31. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    I
    I have the same issue.

    It seems the Unity UI needs to break "raycast target" up into each event category. For example (in my case) a Button needs to absorb the "OnClick" but pass-through the "OnScroll" to the parent ScrollView.

    I think the Unity UI should change events from "public void OnScroll" to "public bool OnScroll" where a bool is returned that determines if the event is passed to the parent or not. Or something along those lines.
     
    prabhukaran likes this.
  32. NandusMasta

    NandusMasta

    Joined:
    Apr 9, 2011
    Posts:
    63
    This solution worked great for me. Thanks sevensails!
     
  33. MyLiaison

    MyLiaison

    Joined:
    Nov 18, 2016
    Posts:
    3
    Lifesaver
     
    Zullar likes this.
  34. Thankxz

    Thankxz

    Joined:
    Dec 25, 2014
    Posts:
    1
    Why I can't think like this , simple solution but Lifesaver :)
     
    sevensails likes this.
  35. logicandchaos

    logicandchaos

    Joined:
    May 16, 2016
    Posts:
    26
    Hi I'm having a similar problem, I have a scrollview populated with GO, but they are draggable.. I have to drag them from the scrollview to other containers and vice versa, I want to make it so that when I click and hold for a bit the GO highlights and can be dragged out of the scrollview, but if you just drag without waiting it will scroll, I got the highlight and dragging the GO all working fine, just can't get the scrollview to scroll instead, I was wondering if the scrollview implements the same interfaces by default and I could just change the target, I tried eventData.pointerDrag = transform.parent.gameObject; which worked to set the eventData.pointerDrag to the scrollview content, but the scrollview's drag interface does not become called, do I have to write a custom scrollview? more detail and my code in this post: https://forum.unity.com/threads/onbegindrag-with-delay.514168/
     
  36. logicandchaos

    logicandchaos

    Joined:
    May 16, 2016
    Posts:
    26
    Hey I solved my problem, I changed the line to eventData.pointerDrag = transform.parent.parent.parent.gameObject;
    that being the component with the drag interfaces.
     
  37. Brijesh_Kumar_Vaishya_

    Brijesh_Kumar_Vaishya_

    Joined:
    Jan 24, 2018
    Posts:
    6
    Yes, I agree with your answer.
    But what if you have moved 1000 child then it may lead to performance issue,
    can you provide a solution in the context of the parent rather than child coz child may be many but the parent will always only one.
    Thanks
     
  38. Brijesh_Kumar_Vaishya_

    Brijesh_Kumar_Vaishya_

    Joined:
    Jan 24, 2018
    Posts:
    6
    Here I found a solution for the above issue with the help of @sevensails

    The component which targets to receives click event with EventTrigger Component for that the below script is meant for.


    for example, I have a Text component that receives click event I simply extend predefined Text class and implements all the interface that was created the issue with scrollRect.

    My custom class is named TextForScrollView and the code is below.

    Just remove the unity Text component and click Add Component and add TextForScrollView.

    and now the result works smoothly fine now.

    Code (CSharp):
    1. using UnityEngine.EventSystems;
    2.  
    3. namespace UnityEngine.UI
    4. {
    5.     public class TextForScrollView : Text, IBeginDragHandler, IDragHandler, IEndDragHandler, IScrollHandler
    6.     {
    7.         ScrollRect MainScroll;
    8.          //MainScroll is immediate parrent of scrollView entries.
    9.  
    10.         void Start()
    11.         {
    12.             MainScroll = transform.GetComponentInParent<ScrollRect>();
    13.             base.Start();
    14.         }
    15.         public void OnBeginDrag(PointerEventData eventData)
    16.         {
    17.             MainScroll.OnBeginDrag(eventData);
    18.         }
    19.  
    20.         public void OnDrag(PointerEventData eventData)
    21.         {
    22.             MainScroll.OnDrag(eventData);
    23.         }
    24.  
    25.         public void OnEndDrag(PointerEventData eventData)
    26.         {
    27.             MainScroll.OnEndDrag(eventData);
    28.         }
    29.  
    30.         public void OnScroll(PointerEventData data)
    31.         {
    32.             MainScroll.OnScroll(data);
    33.         }
    34.  
    35.     }
    36.  
    37. }
     
    f4bo and codxr like this.
  39. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    That's exactly how a scrollview should work...
    I can't understand why a button should stop the scroll functionality. this makes no sense.
     
  40. Malek-Bakeer

    Malek-Bakeer

    Joined:
    Jun 6, 2015
    Posts:
    1
    Hello guys, I've found out that I (Accidentally) had another unused scroll rect as a child in my scroll which resulted in the buttons registering the drag to the unused scroll instead of the main scroll (Which means Unity already solved it but the mistake was from my side for having 2 scrolls inside of each other)

    Conclusion:
    - If you have a child scroll in your main scroll, the buttons will register drag events to the child scroll instead of the main one.
     
  41. Strom_CL

    Strom_CL

    Joined:
    Nov 17, 2012
    Posts:
    112
    2021 and we still have to do this, thanks for the script. There is no reason for a content item to block scrolling or drag events in a ScrollRect. Unity fix this, or at least add an option in ScrollRect that we can toggle to have this behavior.
     
    prabhukaran, f4bo, niallmc and 2 others like this.
  42. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,298
    I have made a component which you can add to any object you want. No need to extend Unitys native components. One caveat though: if another code is listening for onPointer events then these will be triggered even while dragging. I've added a "DisableEventTriggerWhileDragging" bool to control that.

    Btw.: if you only need onClick events from a button then simply remove the EventTrigger component from it and all scroll and drag events will work out of the box.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.EventSystems;
    4. using static UnityEngine.EventSystems.ExecuteEvents;
    5.  
    6. namespace kamgam
    7. {
    8.    /// <summary>
    9.    /// Bubbles events to the parent. Use this to overcome EventTriggers which stop scroll and drag events from bubbling.
    10.    ///
    11.    /// If an EventTrigger component is attached and other code is listening for
    12.    /// onPointer events then these will NOT be triggered while dragging if DisableEventTriggerWhileDragging
    13.    /// is true.
    14.    /// </summary>
    15.    public class UiScrollRectEventBubbling : MonoBehaviour,
    16.                                        IBeginDragHandler,
    17.                                        IDragHandler,
    18.                                        IEndDragHandler,
    19.                                        IScrollHandler
    20.                                      
    21.    {
    22.        [Tooltip("Should the scroll and drag events be forwarded (bubble up) to the parent?")]
    23.        public bool Bubble = true;
    24.  
    25.        [Tooltip("Stop EventTriggers from executing events while dragging?")]
    26.        public bool DisableEventTriggerWhileDragging = true;
    27.  
    28.        protected EventTrigger eventTrigger;
    29.        public EventTrigger EventTrigger
    30.        {
    31.            get
    32.            {
    33.                if (eventTrigger == null)
    34.                {
    35.                    eventTrigger = this.GetComponent<EventTrigger>();
    36.                }
    37.                return eventTrigger;
    38.            }
    39.        }
    40.  
    41.        protected bool dragging = false;
    42.  
    43.        protected void HandleEventPropagation<T>(Transform goTransform, BaseEventData eventData, EventFunction<T> callbackFunction) where T : IEventSystemHandler
    44.        {
    45.            if (Bubble && goTransform.parent != null)
    46.            {
    47.                ExecuteEvents.ExecuteHierarchy(goTransform.parent.gameObject, eventData, callbackFunction);
    48.            }
    49.        }
    50.  
    51.        public void OnScroll(PointerEventData eventData)
    52.        {
    53.            HandleEventPropagation(transform, eventData, ExecuteEvents.scrollHandler);
    54.        }
    55.  
    56.        public void OnBeginDrag(PointerEventData eventData)
    57.        {
    58.            HandleEventPropagation(transform, eventData, ExecuteEvents.beginDragHandler);
    59.  
    60.            dragging = true;
    61.            if (DisableEventTriggerWhileDragging && EventTrigger != null)
    62.            {
    63.                EventTrigger.enabled = false;
    64.            }
    65.        }
    66.  
    67.        public void OnDrag(PointerEventData eventData)
    68.        {
    69.            HandleEventPropagation(transform, eventData, ExecuteEvents.dragHandler);
    70.        }
    71.  
    72.        public void OnEndDrag(PointerEventData eventData)
    73.        {
    74.            HandleEventPropagation(transform, eventData, ExecuteEvents.endDragHandler);
    75.  
    76.            dragging = false;
    77.            if (DisableEventTriggerWhileDragging && EventTrigger != null)
    78.            {
    79.                EventTrigger.enabled = true;
    80.            }
    81.        }
    82.  
    83.        /// <summary>
    84.        /// If the object is disabled while being dragged then the EventTrigger would remain disabled.
    85.        /// </summary>
    86.        public void OnDisable()
    87.        {
    88.            if (DisableEventTriggerWhileDragging && dragging && EventTrigger != null)
    89.            {
    90.                dragging = false;
    91.                EventTrigger.enabled = true;
    92.            }
    93.        }
    94.    }
    95. }
    96.  
    Maybe it will be useful.
     
    Last edited: Mar 2, 2021
    KlivenPL, dre788 and KurtGokhan like this.
  43. Natey

    Natey

    Joined:
    Oct 10, 2014
    Posts:
    26
    Here's my solution.

    Code (CSharp):
    1.     public Scrollbar scrollbar;
    2.     public float scrollSpeed = .05f;
    3.  
    4.     void Update()
    5.     {
    6.         if(Input.mouseScrollDelta.y != 0)
    7.         {
    8.             scrollbar.value += Input.mouseScrollDelta.y * scrollSpeed;
    9.         }
    10.         if(scrollbar.value > 1)
    11.         {
    12.             scrollbar.value = 1;
    13.         }
    14.         else if (scrollbar.value < 0)
    15.         {
    16.             scrollbar.value = 0;
    17.         }
    18.     }
     
    OneManArmy3D likes this.
  44. ian-tw

    ian-tw

    Joined:
    Jan 28, 2019
    Posts:
    5
    This code was exactly what I needed. Thanks so much for passing it along!
     
    Zullar likes this.
  45. Calvares

    Calvares

    Joined:
    Jul 11, 2018
    Posts:
    17

    Six years later, still coming for this.
     
    Rising-Win likes this.
  46. BobberooniTooni

    BobberooniTooni

    Joined:
    Apr 9, 2021
    Posts:
    46
    Same bro
     
  47. PNUMIA-Rob

    PNUMIA-Rob

    Joined:
    Jan 7, 2015
    Posts:
    33
    Seven - years - later...
     
    Last edited: Mar 17, 2022
  48. ducalle

    ducalle

    Joined:
    Nov 5, 2021
    Posts:
    3
    Your solution works. Thanks.
     
  49. Bilobog

    Bilobog

    Joined:
    Oct 12, 2016
    Posts:
    20
    Not suited for elements with Event Triggers. Still don't know how to fix this
     
  50. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    Still having this problem in 2022.The solution above is a great fix but when I dragged on a button and released on the same button, it counted as a click - so I fixed that. Here's the code:
    ( Add this code to the script provided by sevensails )


    Code (CSharp):
    1.  
    2.     public static bool isDragging { get; private set; }
    3.  
    4. // these two methods are already in the script, just add the lines with isDragging
    5.     public void OnBeginDrag(PointerEventData eventData)
    6.     {
    7.         MainScroll.OnBeginDrag(eventData);
    8.         isDragging = true;
    9.     }
    10.     public void OnEndDrag(PointerEventData eventData)
    11.     {
    12.         MainScroll.OnEndDrag(eventData);
    13.         isDragging = false;
    14.     }
    And then in the function your buttons use, add this return check:
    Code (CSharp):
    1.  if (FixScrollRect.isDragging) return;