Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
  • Help Room /
avatar image
9
Question by marucu · Feb 17, 2015 at 10:47 AM · uieventeventslayoutscroll

[Solved] Scroll not working when elements inside have click events

I'm using the new Unity UI for a mobile game and in the menu I have a Scroll Rect with a Vertical Layout Group inside, with Text elements inside the group. Like this:

alt text

The thing is that the scroll works fine until I set pointer events to the text elements (Pointer Up, Pointer Click, etc), then when I swipe above an element I think the UI is "paying attention" to the event manager i.e. checking if I release my finger to trigger Pointer Up event and therefore it does not scroll. But it still scrolls if I click outside a Text element but inside the Vertical Layout Group.

So I don't know if there's a way to make the group scroll even if the elements have this events.

captura-de-pantalla-2015-02-16-a-las-210150.png (10.3 kB)
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
50

Answer by marucu · Feb 22, 2015 at 02:00 PM

I found what was happening! The point is that if you use Event Trigger it will eat all other inputs because it implements all the EventSystem interfaces (and the OnDrag event used by the scroll rect was eclipsed).

  namespace UnityEngine.EventSystems
  {
      [AddComponentMenu("Event/Event Trigger")]
      public class EventTrigger : MonoBehaviour, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler, IDragHandler, IDropHandler, IScrollHandler, IUpdateSelectedHandler, ISelectHandler, IDeselectHandler, IMoveHandler
      {
          [Serializable]
          public class TriggerEvent : UnityEvent<BaseEventData>
          {
          }
  ... blah, blah, blah
 }
 }

So, the solution, avoid using Event Trigger, instead, implement the interface you need for the purpose. My example, instead of adding OnPointerDown and OnPointerUp using the Event Trigger I added this script to the object:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.EventSystems;
 
 public class Click : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
 
     public void OnPointerDown (PointerEventData eventData) {
         // Do action
     }
 
     public void OnPointerUp (PointerEventData eventData) {
         // Do action
     }
 }
 


Comment
Add comment · Show 9 · 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 qiaosic · Dec 10, 2015 at 02:51 AM 0
Share

This totally solves my problem!

avatar image Gizmmoo · Jan 26, 2016 at 04:10 PM 0
Share

You the man!!

avatar image KrlinM · Feb 08, 2016 at 01:27 AM 0
Share

Amazing, thanks!

avatar image canis · Jun 21, 2016 at 06:42 AM 0
Share

Thanks @marucu, you save my day, I working on the nest scrollview passer, and your answer help me to understand a lot. https://www.youtube.com/watch?v=0CgG7WIkV0s

full setup article : http://www.clonefactor.com/wordpress/program/unity3d/1519/

avatar image Baktillus · Aug 22, 2016 at 02:56 PM 0
Share

I know this is old as hell, but can anyone tell me if its possible to assign the triggered actions in the inspector, just like in the Unity EventTrigger? Does it use a special editor script, or is there a way to implement this easily?

avatar image petesplace Baktillus · Nov 01, 2016 at 09:59 PM 2
Share

Try something like this

 public class Click : $$anonymous$$onoBehaviour, IPointerDownHandler, IPointerUpHandler
 {
     public UnityEvent PointerDown;
     public UnityEvent PointerUp;
 
     public void OnPointerDown(PointerEventData eventData)
     {
         if (PointerDown != null)
             PointerDown.Invoke();
     }
 
     public void OnPointerUp(PointerEventData eventData)
     {
         if (PointerUp != null)
             PointerUp.Invoke();
     }
 }
Show more comments
avatar image
2

Answer by tomihr2 · Dec 24, 2016 at 11:54 PM

When I try this implementation:

 public class Click : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {

  public void OnPointerDown (PointerEventData eventData) {
      // Do action
  }
 
  public void OnPointerUp (PointerEventData eventData) {
      // Do action
  }

}

On mobile device OnPointerUp event is triggered almost same time as OnPointerDown, so can't do anything with this implementation, am I doing something wrong?

Comment
Add comment · Show 1 · 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 sotrosh · Mar 18, 2019 at 10:13 PM 0
Share

I have the same issue. Does anyone know how to fix it?

avatar image
0

Answer by viciousesque · Aug 20, 2016 at 12:29 AM

A simpler solution is to just use a button. I deleted the EventTrigger components and replaced them with simple Button components and this allowed the Image component to remain clickable and propagated the scroll event up to the ScrollRect game object, so the scrolling action now works when users scroll over the image.

Comment
Add comment · Show 1 · 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 Baktillus · Aug 22, 2016 at 09:50 AM 0
Share

Just a heads up: If you do this, you may run into problems with certain mobile devices. For example my UI is working perfectly in Editor and on a OnePlus Two, but a Samsung Galaxy S6 has huge issues recognising button clicks. For now it seems like @marucu 's solution works best.

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

18 People are following this question.

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

Related Questions

Special Grid layout 0 Answers

How to prevent automatic tmp ugui resizing. 0 Answers

ScrollRect content/Vertical Layout Group content resets to middle when children altered 1 Answer

Making flower of cards 1 Answer

New GUI - Order of elements? 0 Answers


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