Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

On Screen Controls not working correctly.

Discussion in 'Input System' started by nyscersul, Apr 18, 2020.

  1. nyscersul

    nyscersul

    Joined:
    Oct 17, 2018
    Posts:
    132
    I have used the On Screen controls, creating both a stick and a few buttons, but i cannot seem to get the sticks to work. The strange thing is that they move, but the input is not actually used, the object doesnt move. The object *does* move and work perfectly if i drag the sticks in the editor on my pc, anyone have any ideas what might be wrong?

    Thanks!

    (Let me know if further information is desired, or what information.)
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    So it works in the editor but does not work in the player? Which platform?

    And the buttons work but the stick does not? Or none of the controls work?
     
  3. MicheleBunetto

    MicheleBunetto

    Joined:
    Jul 2, 2012
    Posts:
    5
    It also doesn't work, from debugging I can see that the component works, but the Player Input does not receive the event
     
  4. nyscersul

    nyscersul

    Joined:
    Oct 17, 2018
    Posts:
    132
    I got it working in the end... cant remember what i changed tho hehe
     
  5. unity_shawn

    unity_shawn

    Joined:
    May 27, 2020
    Posts:
    3
    I got the same problem! when i use player input, i hardly can drag the onscreen stick and the action hardly be triggered. if I don't use player input, I can drag the controll smoothly, but still have no action be triggerd
     
    AndreIvankio and diogo2010rs like this.
  6. Eldirfar

    Eldirfar

    Joined:
    Feb 9, 2014
    Posts:
    56
    Hmmm, any solution for this? I have the same problem that OnScreenControl (LeftStick [GamePad]) works until I add the PlayerInput script on the scene.

    I found that PlayerInput Auto-Switch was causing jittering and to get it to work in the editor I needed to set manually input.SwitchCurrentControlScheme("Keyboard&Mouse"); to remove all devices.
     
    Last edited: Nov 17, 2020
    Mr_Cliff likes this.
  7. RogueStargun

    RogueStargun

    Joined:
    Aug 5, 2018
    Posts:
    257
    Same problem. I drag the stick on my phone and it registers for about a second then stops. I have to wiggle my finger to get continuous movement
     
  8. rnagy90

    rnagy90

    Joined:
    Oct 6, 2020
    Posts:
    1
    Same problem and sadly the official Input System tutorial's source code doesn't containt the On Screen controllers (and if you add it still doesn't work :() but(!) I have found 2 solutions for this.

    The main problem is with the PlayerInput script, because for some reason it sends "canceled" input event immediately after the "performed" event, so you can create a bunch of if statement, and predictions to check the cancel event is fake, or:

    1.) Instantiate the input action from the action map by yourself and enable/disable it on the correct lifecycle event (OnEnable, OnDisable).
    If it's enabled you can read the value from it in the Update() like in the "old" input system.
    You can check this video, and focus on the assets -> c# script generation and usage.



    2.) The second solution is to obtain the asset itself (e.g. create a serialized field and drag that into it) and get the action mappings and actions from it. After that, you can enable/disable the action and add/remove the correct listeners to it.

    Here is a sample code:

    Code (CSharp):
    1. [SerializedField]
    2. InputActionAsset controls;
    3.  
    4. InputAction movement;
    5. InputAction useAction;
    6. InputAction attackAction;
    7.  
    8. ...
    9.  
    10. void Awake()
    11. {
    12.   var actionMap = controls.FindActionMap("Player");
    13.  
    14.   movement = actionMap.FindAction("Move");
    15.   useAction = actionMap.FindAction("Use");
    16.   attackAction = actionMap.FindAction("Attack");
    17.   specialAction = actionMap.FindAction("Special");
    18. }
    19.  
    20. ...
    21.  
    22. void OnEnable()
    23. {
    24.   movement.Enable();
    25.   useAction.Enable();
    26.   attackAction.Enable();
    27.   specialAction.Enable();
    28.  
    29.   movement.performed += OnMove;
    30.   useAction.performed += OnUse;
    31.   attackAction.performed += OnAttack;
    32.   specialAction.performed += OnSpecial;
    33. }
    34.  
     
    Blankeos and blackmodjo like this.
  9. blackmodjo

    blackmodjo

    Joined:
    May 6, 2014
    Posts:
    13
    I subscribe to the things mentioned above, PlayerInput 1.2.0 doesn't work with On-screen Stick
     
  10. PlayCreek

    PlayCreek

    Joined:
    Jul 8, 2020
    Posts:
    3
    yes, On-screen Stick seems to be broken in 1.1.1 and 1.2.0.
     
  11. avivoren

    avivoren

    Joined:
    Sep 21, 2014
    Posts:
    31
    I wrote a possible fix/replacement for the PlayerInput class, for example if you want to use Move action's event you'll need to make OnMove like I did below
    Code (CSharp):
    1.  [SerializeField] private InputActionAsset inputControls;
    2.     private InputAction[] inputActions;
    3.     private void Awake()
    4.     {
    5.  
    6.         InputActionMap actionMap = inputControls.FindActionMap("Player");
    7.  
    8.         inputActions = actionMap.actions.ToArray();
    9.     }
    10.     private void OnEnable()
    11.     {
    12.         foreach (var action in inputActions)
    13.         {
    14.             action.Enable();
    15.             action.performed += ProcessInput;
    16.             action.canceled += ProcessInput;
    17.  
    18.         }
    19.  
    20.     }
    21.     private void OnDisable()
    22.     {
    23.         foreach (var action in inputActions)
    24.         {
    25.             action.Disable();
    26.             action.performed -= ProcessInput;
    27.             action.canceled -= ProcessInput;
    28.  
    29.         }
    30.     }
    31.     private void ProcessInput(CallbackContext callbackContext)
    32.     {
    33.         SendMessage($"On{callbackContext.action.name}", callbackContext, SendMessageOptions.DontRequireReceiver);
    34.     }
    35.     private void OnMove(CallbackContext callbackContext)
    36.     {
    37.         Vector2 currentInput = callbackContext.ReadValue<Vector2>();
    38.  
    39.     }
     
    Last edited: Dec 18, 2021
  12. Navlyc

    Navlyc

    Joined:
    May 21, 2021
    Posts:
    1
    The auto-switch on PlayerInput can cause jittering.To avoid this, there are 2 solutions (I use the second one) :
    - disable auto-switch and select manually ControlScheme playerInput.SwitchCurrentControlScheme(new InputDevice[]{ inputDevice })
    - enable auto-switch but edit ControlScheme (top left button in the InputActionAsset editor) and add Touchscreen device as optionnal
     
    Marc-Saubion likes this.
  13. blackmodjo

    blackmodjo

    Joined:
    May 6, 2014
    Posts:
    13
    It is also broken on 1.3.0
     
    Stanley88 and BinaryRavine like this.
  14. BinaryRavine

    BinaryRavine

    Joined:
    Oct 30, 2021
    Posts:
    6
    blackmodjo likes this.
  15. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    337
    the cancelled event is fired when the joystick moves, so it moves, and then it cancels outs.
     
    Stanley88 likes this.
  16. Rouliboudin

    Rouliboudin

    Joined:
    Jan 26, 2022
    Posts:
    2
    still waiting for a fix lol
     
  17. andyblem

    andyblem

    Joined:
    Nov 11, 2014
    Posts:
    26
    After investing so much time in the new input system only to find out it needs some hacks to work on mobile. I will gladly revert back to the old input system or look some third party option.
     
  18. fcorbel

    fcorbel

    Joined:
    Oct 27, 2016
    Posts:
    7
    Hi there !
    I just figured out that I had no EventSystem in the scene. Therefore the On-Screen Stick cannot work. I also had to replace the StandaloneInputModule with the new input system version (Unity kindly offer a button to do that)

    upload_2023-2-3_20-55-12.png

    I hope it can help someone !
     

    Attached Files:

  19. GabrielDPeterson

    GabrielDPeterson

    Joined:
    Jan 21, 2018
    Posts:
    3
    Still an issue in Input System 1.5.0