Search Unity

OnCancel & OnSubmit never called.

Discussion in 'UGUI & TextMesh Pro' started by georgeq, Aug 21, 2019.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    I'm trying to make my UI to respond to the <Esc> and <Enter> keys, with the following code:

    Code (CSharp):
    1.  public class UIPage : Selectable, ICancelHandler, ISubmitHandler {
    2.  
    3.       public virtual void OnCancel(BaseEventData evt) {
    4.          Debug.Log("esc");
    5.       }
    6.  
    7.       public virtual void OnSubmit(BaseEventData evt) {
    8.          Debug.Log("enter");
    9.       }
    10.  
    11.    }

    But none of these events are ever called...
     
  2. himan2104

    himan2104

    Joined:
    Sep 17, 2022
    Posts:
    2
    Any update on this?
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,842
    Pretty sure these require the new input system, and have the appropriate event system active in a scene. And of course also have the right inputs assigned to these.
     
  4. himan2104

    himan2104

    Joined:
    Sep 17, 2022
    Posts:
    2
    Yes, I knew that. But it still does not work. As it turns out, ICancelHandler and ISubmitHandler (and other related interfaces) are invoked only on the currently selected UI Object. My "Panel" or "Page" Is not selected as the selected UI object is some button. As far as I could test in the short duration I had, it is not propagated to parent objects.

    For now, I just let my UI manager bind to the cancel and submit action using the InputSystemUIInputModule and invoke it on the current page/screen.
     
    DMorock likes this.