Search Unity

Question How to use OnScreen-Controls on pc and android?

Discussion in 'Input System' started by Dawando, Jun 12, 2020.

  1. Dawando

    Dawando

    Joined:
    Oct 12, 2016
    Posts:
    11
    Hello,

    currently I am struggling with the new input system when following the OnScreen Controls example from the new input system - specially with the analog stick, since it's bound to gamepad devices.

    So when I try to use these controls on pc with the mouse or on android with touch - it has no effect since it doesnt recognize a connected gamepad.

    Is there a howto/tutorial how to get that to work on pc and android?

    Since it's a singeplayer game - the desired behavior would be that all controls are active at the same time: player can use onscreen controls and keyboard/mouse at the same time.
     
  2. Dawando

    Dawando

    Joined:
    Oct 12, 2016
    Posts:
    11
    push - is the new input system not supporting mobiles? I noticed all questions about the new input system & mobile are ignored by the unity stuff.
     
  3. I don't really understand your posts, are you saying the OnScreen Controls example doesn't work for you when you import it in an empty project?
     
  4. Dawando

    Dawando

    Joined:
    Oct 12, 2016
    Posts:
    11
    Okay I try to explain it better.

    1. Created a new project with a simple platform and a cube to control via an onscreen analog stick.
    2. Added new inputsystem + onscreen controls
    3. updates eventsystem to new input system
    4. add playerinput to cube & create standard input asset
    5. create playerscript with OnMove method
    6. Place Stick.prefab from OnScreenControl sample in scene

    Now I can move my cube with awsd/arrows - but no matter what I'll try - it's not possible to move the cube via the stick. Neither on Android nor in Unity Editor.

    I also uploaded a demo project to github:
    https://github.com/dawuwu/unity-newinput
     
    ahaghdan likes this.
  5. HoecusPocus

    HoecusPocus

    Joined:
    Oct 14, 2020
    Posts:
    7
    I'm having the same issue! I can't click to move the onscreen stick in the game window either.
    The gamepad works fine when I attach it, but I'm trying to simulate mobile.

    I've opened the sample called "OnScreenControlsSample"
    I've noticed that if I use the Standalone Input Module (old input system), then the on-screen joystick works.
    If I switch it to the Input System UI Input Module, then the on-screen joystick does NOT work...

    Please see the image below; just flicking between those 2 modules in the inspector is enough to break it. Error.png

    I can't use the old input module in my project.
     
    Last edited: Jan 13, 2021
  6. samyam_

    samyam_

    Joined:
    Jun 29, 2017
    Posts:
    10
    I have a video on mobile joystick control w/ new input system if that helps
     
    RazorSquirrel and Mikaru like this.
  7. HoecusPocus

    HoecusPocus

    Joined:
    Oct 14, 2020
    Posts:
    7
  8. samyam_

    samyam_

    Joined:
    Jun 29, 2017
    Posts:
    10
    Awesome thanks!
     
  9. Skotrap7

    Skotrap7

    Joined:
    May 24, 2018
    Posts:
    125
    Sam, first, your video is great. Second, any idea why on-screen controls don't work if you use the PlayerInput component instead of the generated C# class?

    Would you mind checking out this post and letting me know what you think?
     
  10. samyam_

    samyam_

    Joined:
    Jun 29, 2017
    Posts:
    10
    Thanks! Just responded, here's a copy:
    I'm able to use a PlayerInput component and an On-Screen joystick when the PlayerInput action asset is different than the one the EventSystem uses, but the sample doesn't seem to work for me when using the same asset.
    Unity v2020.2.7f1 & Input System v1.1.0-preview.3
     
    Steem likes this.
  11. FernandoDarci

    FernandoDarci

    Joined:
    Jan 25, 2018
    Posts:
    19
    I clicked on the script and notice that was conditional flags to allow the code to compile.
    PACKAGE_DOCS_GENERATION || UNITY_INPUT_SYSTEM_ENABLE_UI.
    Someone can explain to me why the script appears gray in VS?