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. Dismiss Notice

Feature Request onClick.AddListener() delegates don't appear on Inspector Events

Discussion in 'Editor & General Support' started by guayeah, Jan 2, 2021.

?

Do you think like me, that it would be helpful to see listeners added by code on inspector?

  1. Yeah, of course!

    12 vote(s)
    92.3%
  2. Nah

    1 vote(s)
    7.7%
  1. guayeah

    guayeah

    Joined:
    Jun 9, 2017
    Posts:
    6
    This is not an error but is something that I think it would help a lot on development if on future versions of Unity we could see the new Events we add to our Buttons on Inspector by AddListener delegates on script. I found that because I've seen that although the listener is working on scene I couldn't find any reference on the Inspector.
     
  2. A_Marraff

    A_Marraff

    Joined:
    Dec 12, 2015
    Posts:
    5
    I second this. I'm trying to debug some code where I believe I accidentally added multiple of the same listener to one button, but there doesn't seem to be a clear way of viewing the listeners added through code.

    Update: My suspicion was correct. I fixed the bug, but I couldn't find anything to help me debug this circumstance. Button.OnClick has a function called GetPersistentEventCount() and even that didn't work, it kept returning 0 even though I knew there was more than one listener active on the button. So, I created a function that ran Button.OnClick.RemoveAllListeners() when the menu closed, to ensure it was a clean slate each time the menu opened, and the bug went away.

    Conclusion, would really appreciate some way to view listeners added through code, even if that meant using a foreach loop and print a debug log of each one on the button.
     
    Last edited: Jul 20, 2023