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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Bug Toggle compent's OnValueChanged event not working.

Discussion in 'UGUI & TextMesh Pro' started by HeyBishop, Jun 3, 2021.

  1. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    221
    I have a Toggle. When the user presses it, I see "IsOn" checking on/off. But the events in OnValueChanged are not triggered.

    Here's a demonstration of the toggle not working:


    And here are the functions I'm calling from the OnValueChanged:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class TestDebugOfToggle : MonoBehaviour
    4. {
    5.  
    6.     public void IsThisWorking(bool value)
    7.     {
    8.         if (value)
    9.         {
    10.             print("Yes, it's working. Truth.");
    11.         }
    12.         else
    13.         {
    14.             print("Yes, it's still working, and we're false.");
    15.         }
    16.     }
    17.  
    18.     public void SaySomething()
    19.     {
    20.         print("Something");
    21.     }
    22. }
     
  2. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    221
    Sorry - I just realized, I'm not sure if should have used the Bug prefix in the thead title, or Help Wanted. There are threads with similar issues, but those are years and years old.
    Am I missing something? Or is this a years-old Unity bug?
     
  3. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    221
    Hi there, just pinging back.
    Does anyone have any ideas?
     
  4. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    221
    I've changed the handle of this thread's title to 'bug'.
    Hoping for some support.
     
  5. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    80
    I got the same issue, fwiw. It works fine in build, or if I attach the debugger to the editor, but it does not work in play mode.
     
  6. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    80
    If I toggle the 'isInteractible' property on the toggle component, at runtime, then it starts to work properly. So there is clearly a unity bug.

    I found a repro - it happens if your toggle is inside a scroll view. I filed a bug report.
     
    Last edited: Nov 8, 2021
  7. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    80
    Ok for anyone else who finds this - a workaround while we wait for Unity to fix the issue is to set your toggles/sliders to send events in Editor + Runtime. Toggling the isInteractible property in a script won't work.
     
  8. kvabakoma

    kvabakoma

    Joined:
    Jun 20, 2016
    Posts:
    3
    Old one but just had the same issue and found what was going on:

    Watch this:


    When selecting the method in the OnValueChange field you should select the from the Dynamic Bool options.

    upload_2023-2-18_23-6-44.png