Search Unity

Question Prevent the WebGL Build from swallowing Keyboard Inputs while the Unity Content is loading

Discussion in 'Web' started by PeterPudeltreter, Apr 1, 2021.

  1. PeterPudeltreter

    PeterPudeltreter

    Joined:
    Apr 1, 2021
    Posts:
    9
    Hi Everyone

    Im embedding a Unity Application into a Vue Frontend and I am using some previously discussed workarounds to prevent Unity from swallowing all keyboard inputs on the surrounding website:

    Code (CSharp):
    1.     void Start()
    2.     {
    3.     #if !UNITY_EDITOR && UNITY_WEBGL
    4.       WebGLInput.captureAllKeyboardInput = false;
    5.     #endif
    6.     }
    7.  
    in addition with the tabindex = "1" html tag in the canvas tag to give the keyboard inputs to unity, once the canvas has focus.

    But I'm still not happy with the solution, since during the time the Unity Content is starting/loading (until the scene has been loaded), all text input fields are blocked. This takes a few seconds and makes the whole frontend feel clunky. I couldn't find a solution to prevent the Unity Build from blocking Keyboard inputs while loading. Am I missing something or doing something wrong? Is there a way to make this work?
     
  2. se210

    se210

    Joined:
    Jan 19, 2016
    Posts:
    3
    Did anyone find a solution for this?
     
  3. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Hey, this is a very good point. If you still care about this, or @se210 , would you be able to raise a bug report about this? I think we should improve this and provide a JavaScript loading time field that would allow developers to override this in their own WebGL Template. I think that would solve this limitation.

    Unity is currently going by bug voting on prioritizing so many features, so it would be great if you can create a bug and vote on it, that would give visibility to this.

    As a local workaround, you can look into the lines with "event.preventDefault();" in the generated .framework.js file, and modify those to be called gated on some a global boolean that you would control during load time. Maybe that would unblock you the quickest?