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

Clear all event listeners on VisualElement?

Discussion in 'UI Toolkit' started by Stardog, Jan 31, 2020.

  1. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,890
    Is there a way to clear all event listeners, such as
    visualElement.UnregisterAllListeners();
    ?

    Maybe I will just have to stop using lambdas and shift everything into a dedicated function.

    I have seen you can do this, too:
    Code (csharp):
    1. EventCallback<MouseDownEvent> handler = e =>
    2. {
    3.     ...
    4. };
    5.  
    6. ve.UnregisterCallback(handler);
    7. ve.RegisterCallback(handler);
     
    Last edited: Jan 31, 2020
    achimmihca likes this.
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    737
    This is not possible at the moment.

    As you suggest you can unregister a callback by keeping a reference to it or using a method.

    To temporarily disable mouse events on an objet you can set its pickingMode property to Ignore.
     
    Last edited: Feb 1, 2020
    Stardog likes this.
  3. GuillaumeLeplang

    GuillaumeLeplang

    Joined:
    Sep 3, 2019
    Posts:
    8
    Good point, an UnregisterAllListeners or UnregisterAllCallbacks method could be very useful!
    :)