• 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
7
Question by marucu · Feb 17, 2015 at 10:47 AM · uieventlayouteventsscroll

[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
32

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 1
Share

Try something like this

 public class Click : MonoBehaviour, 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 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Card array layout 1 Answer

What is the best/simplest way to make a charecter selection screen like in Crossy Road? 0 Answers

Change the "reference position" of an elastic scroll rect 1 Answer

Canvas Sorting Layer having issues with Horizontal Layout Group (And override sorting is not working) 1 Answer

Having problems with setting up layout group properly 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges