Search Unity

Feedback New input system doesn't work in WebGL builds

Discussion in 'Input System' started by ElnuDev, May 4, 2019.

  1. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    For me, the new input system doesn't work in WebGL builds. Are there any ways to fix this? Thanks in advance!
     
  2. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    I have the same problem. WebGL builds don't seem to be working for me just yet.
    Unity 2019.1 + Input System 0.2.6 – everything works fine in the Editor, but neither "Build" nor "Build & Run" for WebGL seems to register any input (nor controller, nor keyboard). I briefly tried 0.2.8 but had to revert back because of 'missing InputActionAssetReference' errors after pressing "Generate C# Class".
    I use the Generate Interfaces workflow in a pretty simple and small project.

    Other people in this forum seem to have some problems in WebGL (e.g. this thread), but in my builds, no key appears to be working.
     
    ElnuDev likes this.
  3. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    Ok, good to hear other people have the same problem with WebGL builds. I'm going to try upgrading my Unity project to 2019.1 and see if that makes a difference - I'm still on 2018.3. By the way, what is Generate Interfaces workflow? I'm unfamiliar.
     
  4. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    I upgraded from 2018.3 to 2019.1 because it looked like 2018.3 isn't compatible anymore.

    I might not explain it exactly accurately, but as I understand it, one of the workflows was to add a listener to whatever event you needed:
    Code (CSharp):
    1. controls.Player.Shoot.performed += _ => Shoot();
    The system also allowed you to generate either "Events" or "Interfaces":



    I've never tried events, but interfaces seem more robust, since you're basically subscribed to everything out of the box via callbacks – and the compiler even warned you if you forgot something.

    XXX.png

    i.e. to use everything in an action map, you'd use
    controls.ActionMap.SetCallbacks(this)
    .

    According to the 0.2.8 changelog, it's now the default way.
    • The option to generate interfaces on wrappers has been removed, instead we always do this now.
    Or at least it should be. I have the same problem as you show in your other thread. In 0.2.8, I still see the 'generate interfaces' option and the class is still generated in the old way with InputActionAssetReference – which is now a removed class. I don't really have an idea for a solution because I don't know how the new, self-contained generated class template is supposed to look like. I simply downgraded the package back to 0.2.6 for now.
     
  5. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    I managed to solve the other problem. Delete the generated class, restart Unity, and generate a new class. With 0.2.8, the generated class should not derive from
    InputActionAssetReference
    . Instead, it should derive from
    IInputActionCollection
    , since it seems that
    InputActionAssetReference
    has been removed from the new input system. However, my only problem now is the fact that I don't know how to refer to this different class like I did before,
    public Controls controls;
    , which doesn't show up in the inspector.
     
    Rallix likes this.
  6. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    Thank you! Restarting Unity was the step I was missing.
    The new approach without the InputActionAssetReference is described here.
    Code (CSharp):
    1. Controls controls;
    2. void Awake()
    3. {
    4.     controls = new Controls();
    5.     controls?.Player.SetCallbacks(this);
    6. }
    7. void Controls.IPlayerActions.OnMovement(InputAction.CallbackContext context)
    8. {
    9.     // TODO: Player movement
    10. }
    11.  
    Something like this should do the trick.
     
    ElnuDev likes this.
  7. arielsan

    arielsan

    Joined:
    Dec 3, 2013
    Posts:
    47
    Hi, we are using it in a WebGL and it worked for us, Unity 2019.1.0 and Input System 0.2.8. However, we are using it almost raw, without all the PlayerInput stuff, just pairing devices to users and reading gamepad values directly, maybe there is an issue with the callbacks, etc. Here is our ludum dare game if you want to check how input system is working.
     
    ElnuDev likes this.
  8. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    Thanks so much! That works ... in the editor. Unfortunately, the new input system still isn't working for me in WebGL builds. However, I'm not using it "raw" like @arielsan. So... I suppose I'll have to wait for that bug to be fixed. :(
     
  9. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    @ElnuDev I have the same issue with the last Input System (1.0.0), did you report the bug now that it's supposed to be stable?
     
  10. demonixis

    demonixis

    Joined:
    Aug 20, 2013
    Posts:
    185
    Hello,
    Same problem here, mouse input is working, but the keyboard is not.
     
  11. jtiret

    jtiret

    Joined:
    Nov 11, 2020
    Posts:
    63
    Hello @demonixis, have you been able to solve this problem on your side?

    I have the same issue: mouse inputs are working properly (in the UI) but I need the keyboard for moving the player and it's not working at all.
    However, keyboard is working well in standalone and Editor.
     
  12. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    72
    I am seeing this issue in 2019.4.29f1 as well. If the input system is set to both instead of new it starts working.