Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Toggle items and scroll view

Discussion in 'UGUI & TextMesh Pro' started by ClosingTime, Feb 19, 2017.

  1. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    208
    There is an issue in case there is a toggle inside the content of a scroll view.
    If you try to touch the toggle button on an Android device and accidentally scroll the scroll view a bit, the toggle won't change(even thought the button would highlight noting it was actually registering the touch).

    I disabled the inertia thing which made it better, because things won't change while in inertia.
    However, it still happen.
    I think I will disable elastic and change it to clamp. Maybe it will solve it.

    What can I do to make sure my pressed on toggle buttons aren't cancelled by the scroll view?
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,078
    the best solution coming to my mind is changing the behavior so that the toggle is already pressed on mouse down.
    you probably can achieve this by making a custom class extending Toggle. there you have to override OnPointerDown and OnPointerUp. Don't call the base implementation of either of them. in OnPointerDown add isOn = !(isOn); in OnPointerUp do nothing at all.
    This should do the trick but I did not ever tried it.
     
  3. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    208
    Ok, I know what is the issue. It's entirely different.
    I was using a sensor listener for my app.
    The sensor updates was pretty fast, so it slowed down the app enough for the GUI to be not responsive.
    I don't know how to deal with it, even with a not so fast update it slows down the app and consume a lot of battery.
    This is not an issue in the pure android app test I did.
    I think it is something about AndroidJavaProxy being extremly slow/CPU consuming?
    So being called every time makes it slow?
     
  4. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,078
    not sure about performance of interops. I can imagine that it is not a good idea to do that every frame.

    Did you try to handle that stuff in a different thread?
     
  5. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    208
    Err... I thought everything in unity is on the same thread or recommended to be on the main unity thread with coroutines.
    Updating every frame was not an issue with the little android test app I did(Pure android, not from unity).
     
  6. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,078
    yes it is recommended not to use other threads. Maybe because it is not possible to use the logger of unity from another thread... or because it is difficult to debug.
    However it is possible to use another thread and in some cases it is a good idea...
     
  7. douglasg14b

    douglasg14b

    Joined:
    Oct 2, 2014
    Posts:
    34
    Also having this issue, a toggle in a scrollview is REALLY frustrating to tap. Even the slightest, impermeable hint of scrolling stops the toggle from functioning.

    Any ways around this?
     
  8. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    208
    This was quite some time ago on an app I no longer work maintain, I don't remember what was the solution if any, sorry :/
     
  9. Fangh

    Fangh

    Joined:
    Apr 19, 2013
    Posts:
    248
    I still have this issue on 2021.3.0