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

InputField focus issue

Discussion in 'WebGL' started by Zaskar7777, Jul 10, 2021.

  1. Zaskar7777

    Zaskar7777

    Joined:
    Oct 17, 2020
    Posts:
    36
    I have the following setup in Unity.

    Parent GameObject - "Main", it has the following child gameobjects.
    1. InputField: User Name
    2. InputField: Password
    3. Button: Submit

    When I enter user and password and click Submit I want the UserName and Password and the Submit button to be hidden so I call
    Code (CSharp):
    1. Main.SetActive(false);
    Output in Unity Editor:
    Username, Password, and Submit buttons get hidden

    Output in Webgl on a browser:
    Username and Submit button get hidden but not the Password field

    I realized the focus on the Password InputField is on hence it is not getting hidden

    So I tried

    Code (CSharp):
    1. Password.interactable = false;
    - did not work


    Code (CSharp):
    1. Password.DeactivateInputField();
    - did not work

    Though the parent GameObject Main is hidden, the child Password InputField is not

    How can I defocus the Password field or in general how can I hide the Password field?

    Thanks!
     
  2. Zaskar7777

    Zaskar7777

    Joined:
    Oct 17, 2020
    Posts:
    36
    Debugged in the browser and saw this error message:

    "Coroutine couldn't be started because the game object 'InputField_Password' is inactive!"

    I am sure there is no coroutine attached or running as a script on InputField_Password. Not sure what is happening here.
    'InputField_Password' is inactive!. I understand as I am trying to hide it using Main.SetActive(false)

    Any help will be appreciated as I am not getting enough to debug information to dig deep. All is working well in the editor.

    Full error details:

    2a95659c-2f50-4fc9-a0c2-cf6327424a07:3452 Coroutine couldn't be started because the the game object 'InputField_Password' is inactive!
    UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    WebGLSupport.WebGLInput:OnBlur(Int32)
    [./Runtime/Mono/MonoBehaviour.cpp line 731]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 731)
    _JS_Log_Dump @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:3452
    __Z19WebGLPrintfConsolev7LogTypePKcPi @ 059c5e12:0x195889
    __ZL20InternalErrorConsolePKcz @ 059c5e12:0x195708
    __Z40DebugStringToFilePostprocessedStacktraceRK21DebugStringToFileData @ 059c5e12:0x19521f
    __Z17DebugStringToFileRK21DebugStringToFileData @ 059c5e12:0x193a7c
    __ZN13MonoBehaviour22StartCoroutineManaged2E18ScriptingObjectPtr @ 059c5e12:0x56f4bd
    __Z43MonoBehaviour_CUSTOM_StartCoroutineManaged2P12Il2CppObjectS0_ @ 059c5e12:0x57801d
    dynCall_iii @ 059c5e12:0x1059599
    (anonymous) @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:24590
    invoke_iii @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:16059
    _MonoBehaviour_StartCoroutineManaged2_m114327BBBA9F208E8BA2F8BBF71FA0E8E996F7B8 @ 059c5e12:0x100600e
    dynCall_iiii @ 059c5e12:0x1059668
    (anonymous) @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:24630
    invoke_iiii @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:16139
    _MonoBehaviour_StartCoroutine_mBF8044CE06A35D76A69669ADD8977D05956616B7 @ 059c5e12:0x1005e6c
    dynCall_iiii @ 059c5e12:0x1059668
    (anonymous) @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:24630
    invoke_iiii @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:16139
    _WebGLInput_OnBlur_mB1F037542119214E3D940BF086D9E573E4DE904A @ 059c5e12:0x102477d
    dynCall_vii @ 059c5e12:0x105a02d
    (anonymous) @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:25095
    invoke_vii @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:17069
    _ReversePInvokeWrapper_WebGLInput_OnBlur_mB1F037542119214E3D940BF086D9E573E4DE904A @ 059c5e12:0x10245fd
    dynCall_vi @ 059c5e12:0x1059e28
    (anonymous) @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:24995
    dynCall @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:579
    (anonymous) @ 2a95659c-2f50-4fc9-a0c2-cf6327424a07:3885
     
  3. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    241
    you can try this:
    Code (CSharp):
    1. public void RemoveFocus()
    2. {
    3.     if (!UnityEngine.EventSystems.EventSystem.current.alreadySelecting)
    4.     {
    5.         UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);
    6.     }
    7. }
     
  4. Zaskar7777

    Zaskar7777

    Joined:
    Oct 17, 2020
    Posts:
    36
    Thanks for the help. That didn't work either.

    Looks like this piece for Webgl is broken in Unity. It's a bit strange that for such a simple requirement we don't have a simple solution.

    Summary:
    The last input field edited by the user remains active and stays on the screen. Nothing works, trying to hide it, move it.
     
  5. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    334
    This looks like a bug. I'll make note of it. If you submit a bug report, you can track it.