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’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Feedback Be careful with ctx => syntax...

Discussion in 'Input System' started by dlorre, Sep 12, 2022.

  1. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    699
    When you use this in a base class:

    Code (csharp):
    1.  
    2.         protected virtual void OnEnable()
    3.         {
    4.             controls.UI.PanelUp.performed += ctx => PanelUp();
    5.         }
    6.  
    7.         protected virtual void OnDisable()
    8.         {
    9.             controls.UI.PanelUp.performed -= ctx => PanelUp();
    10.         }
    11.  
    12.  
    Then if you have 2 classes inheriting from this base the callbacks won't be properly set. This syntax works:

    Code (csharp):
    1.  
    2.         protected virtual void OnEnable()
    3.         {
    4.             controls.MainUI.PanelUp.performed += PanelUp;
    5.         }
    6.  
    7.         protected virtual void OnDisable()
    8.         {
    9.             controls.MainUI.PanelUp.performed -= PanelUp;
    10.         }
    11.  
    12.  
    I've found the explanation here.

    I've had this for 2 UI Document controllers and the first one was receiving all the callbacks, even when disabled.