On screen joysticks and real gamepad on android Problem

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

///pseudo code
if current.Controlscheme=="gamepad"
{
OnScreencontrolcanvas.SetActive(false);
}

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?.

Could you not create another control scheme that lists the touchscreen as the required device? then use

if(current.ControlScheme=="gamepad")
{
OnScreenControlCanvas.SetActive(false);
}
else if(current.ControlScheme=="touch")
{
OnScreenControlCanves.SetActive(true);
}

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.

Maybe you can use onControlsChanged to enable and disable the onscreen controls. https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.PlayerInput.html#UnityEngine_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/com.unity.inputsystem@1.1/manual/HowDoI.html#get-all-current-touches-from-the-touchscreen. If there are no active touches in the array, you can disable the on screen controls.

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.

3 Likes