Search Unity

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,913
    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:
    780
    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!
    :)
     
    Zeno37 likes this.