Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Lemon30 · Mar 16, 2017 at 04:03 PM · uiinputeventsystemscrollviewscroll

How to solve event triggers blocking scrollview inputs in an inventory/menu?

I'm working on an inventory system. I'm done with most of the basic stuff but there are a few critical points that I'm unable to fix.

This is how my inventory looks like at the moment.

This is the object hiearchy in the canvas.

These are the attached scripts and components.

As you noticed if you have checked the hierarchy, the panel is inside a scroll view.

  • Problem 1

I'm populating the inventory slots dynamically inside a grid layout using one example slot object. If the player has 30 slots, a script creates 29 copies of it and adds them as siblings. Grid layout handles the positioning. If there are 100 slots some of them won't be able to fit into the screen and the user will have to scroll vertically to reach them. All my inputs are blocked by the items in front of the scrollview, therefore I can't scroll the panel. I was using buttons earlier and everything was fine but I had to use an event trigger instead to differentiate between pointer up and down events to handle dragging.

  • Problem 2

It's a similar issue with the first problem. Maybe I can even solve it on my own if the first one is solved but here it is. There are 4 tabs at the top. I want to be able to switch between 4 inventory tabs using these buttons and also swiping horizontally. Unlike the vertical scroll in a single tab, horizontal swipe should move to the next tab completely and not show half of a tab and half of the other.

For example, if the user is in equipment tab a vertical scroll down should move the inventory slots up as long as the scroll's length. However, a swipe to right in equipment tab, as long as it's half a screen long, should move the whole materials tab into the screen and move the old, equipment panel out.

Any kind of help/guidance is appreciated. Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RahulOfTheRamanEffect · Mar 26, 2018 at 07:07 PM 0
Share

Problem 1: I don't quite get it. Did you say everything worked fine when you were using buttons? In that case, what's the problem?

Problem 2: You could nest each tabbed view as an equally wide vertical scrollrect inside a horizontal scrollrect.
(Note: You will need to use a custom scroll rect script to handle nesting correctly. I've written one up that you can find here: https://forum.unity.com/threads/nested-scrollrect.268551/#post-3434275)
To make sure that the entire tab is changed when you swipe to either side, make sure to go to your horizontal scrollbar component under the scrollrect and set "Number of Steps" to the number of tabs you have.

2 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by moment_um · Jul 25, 2019 at 08:09 PM

I finally made an answer for this. Obviously years late, but Hopefully anyone else who stumbles upon this will find it helpful. Add this component to any GameObject with the EventTrigger:

  • using UnityEngine;

  • using UnityEngine.EventSystems;

public class PropogateDrag : MonoBehaviour{

     public UnityEngine.UI.ScrollRect scrollView;
     // Start is called before the first frame update
     void Start()
     {
         EventTrigger trigger = GetComponent<EventTrigger>();
         EventTrigger.Entry entryBegin = new EventTrigger.Entry(), entryDrag = new EventTrigger.Entry(), entryEnd = new EventTrigger.Entry(), entrypotential = new EventTrigger.Entry()
             , entryScroll = new EventTrigger.Entry();
 
         entryBegin.eventID = EventTriggerType.BeginDrag;
         entryBegin.callback.AddListener((data) => { scrollView.OnBeginDrag((PointerEventData)data); });
         trigger.triggers.Add(entryBegin);
 
         entryDrag.eventID = EventTriggerType.Drag;
         entryDrag.callback.AddListener((data) => { scrollView.OnDrag((PointerEventData)data); });
         trigger.triggers.Add(entryDrag);
 
         entryEnd.eventID = EventTriggerType.EndDrag;
         entryEnd.callback.AddListener((data) => { scrollView.OnEndDrag((PointerEventData)data); });
         trigger.triggers.Add(entryEnd);
 
         entrypotential.eventID = EventTriggerType.InitializePotentialDrag;
         entrypotential.callback.AddListener((data) => { scrollView.OnInitializePotentialDrag((PointerEventData)data); });
         trigger.triggers.Add(entrypotential);
 
         entryScroll.eventID = EventTriggerType.Scroll;
         entryScroll.callback.AddListener((data) => { scrollView.OnScroll((PointerEventData)data); });
         trigger.triggers.Add(entryScroll);
     }
 }

And then assign the scrollview you want to scroll in the editor. In the future, either try to use buttons, or make your own script that uses the Unity handler Interfaces (e.g. IPointerClickHandler)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image melitoren · Oct 14, 2020 at 05:18 PM 0
Share

YOU ARE A LIFE SAVER FORREAL!!!!!! THX A LOT

avatar image gregathee · May 16, 2021 at 01:35 AM 0
Share

You are a beautiful person.

avatar image marcozakaria · Aug 22, 2021 at 01:37 PM 0
Share

Thanks Worked.

avatar image
0

Answer by hannabone3445 · Aug 22, 2021 at 08:18 PM

Hi! Hey! Perhaps you can find a solution to your problem here. Otherwise, you can find a lot of useful information here

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get UI elements such as Scroll Rect to work with new input system? 0 Answers

Unity UI double Scroll Rect handler? 0 Answers

[Solved] need help regarding autolayout in scrollrect 1 Answer

Can I Simulate the "Submit" Event with Gamepad Buttons? 0 Answers

IPointerEnterHandler doesn't work when object switches parent 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges