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.
  2. Dismiss Notice

Input system android

Discussion in 'Input System' started by piggybank1974, Sep 9, 2020.

  1. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    621
    @Chris-Trueman

    There seems to be issues with the new input system, or the very least how I've implemented it when it is used on android.

    1 - I'm using 8BitDo wired for development and testing on windows 10.
    2 - I'm running the built version on android with the controller wirelessly.
    3 - with the controller wirelessly I can move around the android environment fine.

    According to the unity video that was released, a button that is set up as the south is always south but I've found this, not the case, the south button I setup is mapped to the east button when used on android, although on windows using it it is correct.

    The following code works ok in a development environment with the controller but when used on the android device never seems to work "get called", when the controller is connected.

    Code (CSharp):
    1.  
    2. UnityEngine.InputSystem.Utilities.ReadOnlyArray<UnityEngine.InputSystem.InputDevice> devices = UnityEngine.InputSystem.InputSystem.devices;
    3.     if (devices.Count > 0)
    4.      for (Int32 a = 0; a < devices.Count; ++a)
    5.       if (devices[a] is UnityEngine.InputSystem.Joystick || devices[a] is UnityEngine.InputSystem.Gamepad)
    6.         {
    7.          mManagers.Project.Settings.DeviceType = DeviceTypes.GAMEPAD;
    8.          Debug.Log("A Gamepad Has Been found");
    9.          break;
    10.         }
    11.  
     
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    I've played around only with a 360 controller and the new input system, I also have never done any work with Android and the new input system, not even for touch. Sorry I can't really help you out here D:.
     
  3. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    621
    @Chris-Trueman

    Afternoon Chris,

    After a night of scratching my head, and shouting at the machine, I figured out I was the idiot on two fronts, I could find problems with although the first one was a little bit more, of a lack of knowledge than anything, it turns out that "UnityEngine.InputSystem.Joystick" is always available on android as "androidjoystick", even though you don't have one on a phone.

    The second problem, was later one last night when I sore this "mManagers.Project.Settings.DeviceType" by itself it's not a problem but if for example you change the music off/on in the game all the SettingsState object gets saved to a file, but as I've updated that file to use the GamePad next time it runs I wouldn't get no touch joystick on screen, not to be confused with "androidjoystick" by the way. Once I created a new property that was for what the user device they are using in that game session it all started to work once I had changed and updated the property to the new one.
     
    Chris-Trueman likes this.
  4. ASTW

    ASTW

    Joined:
    Jul 29, 2021
    Posts:
    2
    Hi, I'm a newer in Unity, and I'm confused with the AndroidJoystick, may I ask why this class exists? Thank you!
     
  5. piggybank1974

    piggybank1974

    Joined:
    Dec 15, 2015
    Posts:
    621
    @ASTW

    I'm sorry for the late reply, I think it's the android implementation unless they have changed it in another version I'm using the new Input system on my Gauntlet clone and it works fine.