Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question On screen joysticks and real gamepad on android Problem

Discussion in 'Input System' started by Aokkii, Jan 14, 2021.

  1. Aokkii

    Aokkii

    Joined:
    Nov 3, 2013
    Posts:
    119
    Since the usual approach in the examples to onscreen joysticks is to emulate a gamepad I do it like that,

    but I wanted to disable Onscreen controls if it detects a change in the control scheme and detects a gamepad

    with
    Code (CSharp):
    1.  
    2. ///pseudo code
    3. if current.Controlscheme=="gamepad"
    4. {
    5. OnScreencontrolcanvas.SetActive(false);
    6. }
    but since both onscreen joystick and real gamepad use the same control scheme, as soon as I try to move the player with the virtual joystick, the OnscreenControlCanvas is disabled.


    what should be the approach to this problem?.
     
  2. sodarocketstudios

    sodarocketstudios

    Joined:
    Jan 14, 2021
    Posts:
    21
    Could you not create another control scheme that lists the touchscreen as the required device? then use
    Code (CSharp):
    1. if(current.ControlScheme=="gamepad")
    2. {
    3. OnScreenControlCanvas.SetActive(false);
    4. }
    5. else if(current.ControlScheme=="touch")
    6. {
    7. OnScreenControlCanves.SetActive(true);
    8. }
     
  3. Aokkii

    Aokkii

    Joined:
    Nov 3, 2013
    Posts:
    119
    No, Cuz the Onscreen controls would still be emulating the gampedad control scheme. making the active control scheme the gamepad even when using the touchscreen


    I already have the two control schemes , "gamepad" an "Phone", like I said before since the onscreen controls emulate a gamepad input , the control scheme will always be gamepad,
    I also get input stuttering sometimes from the control scheme fighting between the gamepad and touchscreen.

    and sometimes the Onscreen controls get stucked and don't work at all.
     
    Last edited: Jan 14, 2021
  4. sodarocketstudios

    sodarocketstudios

    Joined:
    Jan 14, 2021
    Posts:
    21
    Maybe you can use onControlsChanged to enable and disable the onscreen controls. https://docs.unity3d.com/Packages/c...ine_InputSystem_PlayerInput_onControlsChanged I'm still not sure how to differentiate between the controller and on screen controls unfortunately. I would think the information you need would be somewhere in the device code, but it seems well hidden.

    You could also potentially use this https://docs.unity3d.com/Packages/c...#get-all-current-touches-from-the-touchscreen. If there are no active touches in the array, you can disable the on screen controls.
     
  5. Aokkii

    Aokkii

    Joined:
    Nov 3, 2013
    Posts:
    119
    I am already using OnControlsChanged(), I am going to ditch OnScreenbutton and OnscreenStick scripts for now, and use the default UI button script for buttons and make a script for the stick.


    To the input system developers:

    For the Onscreen controls scripts it would be better if instead of biding controlpaths you could bind the Action() itself.

    I don't know if that would be possible tho.
     
    PandaArcade and nraw like this.