Home / C# / Unity 4.6 UI and nested ScrollRect

Unity 4.6 UI and nested ScrollRect

I wanted to have nested ScrollRects with different scrolling axis using the new Unity UI 4.6. By default this cannot be achieved currently.

My goal was to be able to swipe through 4 pages of the main menu of my game (green axis) and then on one of the pages be able to swipe through a list of items (red axis):


So I created a subclass of ScrollRect that routes the drag events to all parent ScrollRects in case a simple rule checked in OnBeginDrag is true. For my simple case I just wanted to route events to the parent in case a horizontal drag was being initiated but the scroll rect is a vertical one, or a vertical drag was being initiated and the scroll rect is a horizontal one. This is my subclass:


11 thoughts on “Unity 4.6 UI and nested ScrollRect

  1. Jakov

    26 Apr on 2015 at 7:06 pm

    Thanks. I had the same requirement for my project. I’ve just copied this code and it works like a charm.
    Have you considered submitting this to Unity’s open source repository for UGUI? I think this would be a great feature to add to their code and UI team might help you with the process. I am working on a “snap to content” feature myself.

  2. Zahi

    06 May on 2015 at 3:55 pm

    Sweet! Solved my problem within 30 seconds of googling :)

  3. Kalty

    14 May on 2015 at 3:13 pm

    I don’t know who you are …
    But i’m gonna find you and marry you!!!

    Best Regards

  4. Christian

    23 Jul on 2015 at 8:38 am

    I attempted to use this but got nowhere with it lol. Would you provide an example project please.

    • Robert

      29 Aug on 2017 at 7:11 pm

      For other people who stumble on this and are not sure. It inherits from ScrollRect, so instead of adding a Scroll Rect component to the child scroll rect object, attach this script instead.

  5. Johannes Deml

    13 Nov on 2015 at 10:02 am

    Thanks a lot, I had exactly the same problem and it took me a lot of time to try to fix it myself. Thanks for the help, this is really awesome!

  6. PavanN

    13 Jan on 2016 at 5:29 am

    Working well for Nested ScrollRects :)

  7. Anonymous

    23 Feb on 2016 at 8:08 am

    Thanks a lot! This was just what I needed.

  8. Ken

    14 May on 2016 at 6:28 am

    Brilliant! Saves a lot of time!!!

  9. Roland

    26 Aug on 2016 at 9:11 pm

    Works perfectly! You saved my life! Thank you so much!

  10. MG

    27 Mar on 2017 at 12:07 pm

    Nice, working in U5.5.


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">