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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

nintendo switch joy con support

Discussion in 'Input System' started by smallg2023, Jan 7, 2020.

  1. smallg2023

    smallg2023

    Joined:
    Sep 2, 2018
    Posts:
    103
    i'm getting an error when i have my joy cons connected to my pc, does anyone know if it's possible to use the nintendo switch joy cons in the new input system or if it is a planned feature at any point? would be a great addition for local co-op etc

    the error is this but it's not very usefull - basically just saying the controller format isn't implemented i guess
    NotImplementedException: The method or operation is not implemented.
    UnityEngine.InputSystem.Utilities.PrimitiveValue.FromString (System.String value) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.3/InputSystem/Utilities/PrimitiveValue.cs:407)
     
  2. Meorge

    Meorge

    Joined:
    Feb 10, 2017
    Posts:
    21
    wlwl2 likes this.
  3. bob_mosh

    bob_mosh

    Joined:
    May 30, 2018
    Posts:
    12
    Funny that you post this! I am currently working with the same. I am able to connect my JoyCons into the InputSystem but they're hard to recognise and I am not able to read analog values from the JoyCons.

    I have the weird issue that I am not able to connect the JoyCons beforehand, but if I connect the JoyCons while the game is running, everything seems to work (Joysticks only give me (1,0,-1) values but other than that it works okay.

    I am using a Mac, so it might not be possible on Windows at all, I have no clue. On Mac however it works to some degree.

    I just pair the JoyCons up with the Mac and I am able to listen for their input in the Input Actions.
     
  4. smallg2023

    smallg2023

    Joined:
    Sep 2, 2018
    Posts:
    103
    i figured it wasn't supported yet, just wanted to confirm and didn't realise there was a document for it, thanks :)

    mine is probably getting completely messed up due to having vjoy installed then as it still errors even with them removed from the list of installed devices
     
  5. bob_mosh

    bob_mosh

    Joined:
    May 30, 2018
    Posts:
    12
    What system are you on? Mac or PC?
     
  6. smallg2023

    smallg2023

    Joined:
    Sep 2, 2018
    Posts:
    103
    PC, i removed the vjoy drivers and it no longer errors so that's good as it was annoying that it errors even with the joycons removed from device manager.
    i have a couple xbox controllers i can use for now till joycon support gets added
     
  7. bob_mosh

    bob_mosh

    Joined:
    May 30, 2018
    Posts:
    12
    Awesome. I'll probably do the same. I have a PS4 Controller lying around somewhere and I'll use that in the meantime. Let's hope that JoyCon support will come. :)
     
  8. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    We're currently still having multiple issues with our HID fallback that kicks in when a HID is connected that isn't specifically recognized by the input system (which is the case with JoyCons on desktop). In some cases, the HID fallback just wires up the device incorrectly, in others it leads to exceptions being thrown. We're working on it.

    Proper Joy-Con support on desktop is planned for after 1.0.
     
  9. bob_mosh

    bob_mosh

    Joined:
    May 30, 2018
    Posts:
    12
    Hey @Rene-Damm Awesome thanks for your reply! I think I won't need to set it up using custom scripts. I'll stick to what they can do right now. They do sort of work and that's okay so far. It's just a passion project so I was just curious!
     
  10. smallg2023

    smallg2023

    Joined:
    Sep 2, 2018
    Posts:
    103
    yh they work ok without the vjoy drivers on windows too, just a couple issues but it's good enough to do dev tests, looking forward to full support :)
     
    bob_mosh likes this.
  11. Lentor_Gaming

    Lentor_Gaming

    Joined:
    Feb 24, 2018
    Posts:
    4
    How do you get it to work?? It's not working for me for some reason. I have my pro controller connected to my pc and Unity shows on the console: "Joystick Reconnected ("Pro Controller"). but whenever I try to use the "Listen" button for the keybinding it doesn't take any input.
     
  12. BinaryEclipse

    BinaryEclipse

    Joined:
    Sep 1, 2016
    Posts:
    43
    same. also in the debug controls window, it doesn't update values (but the ds4 works fine here)
     
  13. toma7687

    toma7687

    Joined:
    May 25, 2015
    Posts:
    1
    Hello,
    Is JoyCon still planned to be supported after version 1.0? And do you have a best guess of when this might be?
    Many thanks,
     
  14. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    It's still the plan but there's no concrete ETA yet. 1.1 will focus mainly on fixes and performance improvements. Beyond that the timeline is still uncertain. Sorry I don't have better news at this point :/
     
  15. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    what's the perf drop compared to the old input system?
     
    wlwl2 likes this.
  16. Ivan_br

    Ivan_br

    Joined:
    Nov 10, 2015
    Posts:
    29
    @Rene-Damm , is there any update on this (if it is compatible or an estimated date on when it will be), as we are currently (January 26th) on version 1.1.0-preview.2?

    Aside from the input (button presses), are there any issues with receiving sensor information from these joycons (i.e. gyroscope/accelerometer)?

    Thank you.
     
  17. MikeGDev

    MikeGDev

    Joined:
    Dec 19, 2017
    Posts:
    53
    Also waiting for an update regarding the JoyCon support. In the meantime, did anyone manage to setup a custom controller that supports them? Any pointers in the right direction would be appreciated.
     
  18. dTurok20

    dTurok20

    Joined:
    Nov 2, 2018
    Posts:
    1
    These are the result of me trying to follow the wondrous journey of confusion that is the input system guide pages and adapt the ps4 controller example.
    I remapped the controller to be two half-controllers but i mapped SL and SR to L3 and R3 and did not map the stick press itself. Also the Stick is read as a dpad for some reason, so not analog.
    There is a lot you can improve on this, i would call this a work in progress but it works for me.

    Code (CSharp):
    1. using System.Runtime.InteropServices;
    2. using UnityEngine.InputSystem.Layouts;
    3. using UnityEngine.InputSystem.LowLevel;
    4. using UnityEngine.InputSystem.Utilities;
    5.  
    6. [StructLayout(LayoutKind.Explicit, Size = 32)]
    7. struct LeftJoyconInputReport : IInputStateTypeInfo
    8. {
    9.     // Because all HID input reports are tagged with the 'HID ' FourCC,
    10.     // this is the format we need to use for this state struct.
    11.     public FourCC format => new FourCC('H', 'I', 'D');
    12.  
    13.     [InputControl(name = "buttonSouth", displayName = "Down", bit = 1)]
    14.     [InputControl(name = "buttonWest", displayName = "Left", bit = 0)]
    15.     [InputControl(name = "buttonEast", displayName = "Right", bit = 3)]
    16.     [InputControl(name = "buttonNorth", displayName = "Up", bit = 2)]
    17.     [InputControl(name = "leftStickPress", displayName = "SL", bit = 4)]
    18.     [InputControl(name = "rightStickPress", displayName = "SR", bit = 5)]
    19.     [FieldOffset(1)] public byte buttons1;
    20.  
    21.     //Stickpress is not assigned
    22.     //    [InputControl(name = "leftStickPress", displayName = "StickPress", bit = 2)]
    23.     [InputControl(name = "start", displayName = "Minus", bit = 0)]
    24.     [InputControl(name = "select", displayName = "Cam", bit = 5)]
    25.     [InputControl(name = "leftTrigger", displayName = "Trigger", format = "BIT", bit = 7)]
    26.     [InputControl(name = "leftShoulder", displayName = "Shoulder", bit = 6)]
    27.     [FieldOffset(2)] public byte buttons2;
    28.  
    29.     [InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
    30.     [InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=5,maxValue=7", bit = 0, sizeInBits = 4)]
    31.     [InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=7,maxValue=1,nullValue=8,wrapAtValue=7", bit = 0, sizeInBits = 4)]
    32.     [InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=1,maxValue=3", bit = 0, sizeInBits = 4)]
    33.     [InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=3, maxValue=5", bit = 0, sizeInBits = 4)]
    34.     [FieldOffset(3)] public byte leftStickX;
    35. }
    36.  
    37. [StructLayout(LayoutKind.Explicit, Size = 32)]
    38. struct RightJoyconInputReport : IInputStateTypeInfo
    39. {
    40.     // Because all HID input reports are tagged with the 'HID ' FourCC,
    41.     // this is the format we need to use for this state struct.
    42.     public FourCC format => new FourCC('H', 'I', 'D');
    43.  
    44.     [InputControl(name = "buttonSouth", displayName = "Down", bit = 2)]
    45.     [InputControl(name = "buttonWest", displayName = "Left", bit = 3)]
    46.     [InputControl(name = "buttonEast", displayName = "Right", bit = 0)]
    47.     [InputControl(name = "buttonNorth", displayName = "Up", bit = 1)]
    48.     [InputControl(name = "leftStickPress", displayName = "SL", bit = 4)]
    49.     [InputControl(name = "rightStickPress", displayName = "SR", bit = 5)]
    50.     [FieldOffset(1)] public byte buttons1;
    51.  
    52.     //Stickpress is not assigned
    53.  
    54.     //   [InputControl(name = "rightStickPress", displayName = "StickPress", bit = 3)]
    55.     [InputControl(name = "start", displayName = "Plus", bit = 1)]
    56.     [InputControl(name = "select", displayName = "Home", bit = 4)]
    57.     [InputControl(name = "rightTrigger", displayName = "Trigger", bit = 7, format = "BIT")]
    58.     [InputControl(name = "rightShoulder", displayName = "Shoulder", bit = 6)]
    59.     [FieldOffset(2)] public byte buttons2;
    60.  
    61.     [InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
    62.     [InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=1,maxValue=3", bit = 0, sizeInBits = 4)]
    63.     [InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=3,maxValue=5", bit = 0, sizeInBits = 4)]
    64.     [InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=5, maxValue=7", bit = 0, sizeInBits = 4)]
    65.     [InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=7,maxValue=1,nullValue=8,wrapAtValue=7", bit = 0, sizeInBits = 4)]
    66.     [FieldOffset(3)] public byte rightStickX;
    67. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5. using UnityEngine.InputSystem;
    6. using UnityEngine.InputSystem.Layouts;
    7.  
    8. [InputControlLayout(stateType = typeof(LeftJoyconInputReport))]
    9. #if UNITY_EDITOR
    10. [InitializeOnLoad] // Make sure static constructor is called during startup.
    11. #endif
    12. public class LeftJoyconGamepadHID : Gamepad
    13. {
    14.     static LeftJoyconGamepadHID()
    15.     {
    16.         InputSystem.RegisterLayout<LeftJoyconGamepadHID>(
    17.             matches: new InputDeviceMatcher()
    18.                 .WithInterface("HID")
    19.                 .WithCapability("vendorId", 0x57E) // Nintendo
    20.                 .WithCapability("productId", 0x2006)); // L
    21.  
    22.  
    23.     }
    24.  
    25.     // In the Player, to trigger the calling of the static constructor,
    26.     // create an empty method annotated with RuntimeInitializeOnLoadMethod.
    27.     [RuntimeInitializeOnLoadMethod]
    28.     static void Init() {}
    29. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5. using UnityEngine.InputSystem;
    6. using UnityEngine.InputSystem.Layouts;
    7.  
    8. [InputControlLayout(stateType = typeof(RightJoyconInputReport))]
    9. #if UNITY_EDITOR
    10. [InitializeOnLoad] // Make sure static constructor is called during startup.
    11. #endif
    12. public class RightJoyconGamepadHID : Gamepad
    13. {
    14.     static RightJoyconGamepadHID()
    15.     {
    16.         InputSystem.RegisterLayout<RightJoyconGamepadHID>(
    17.             matches: new InputDeviceMatcher()
    18.                 .WithInterface("HID")
    19.                 .WithCapability("vendorId", 0x57E)//Nintendo
    20.                 .WithCapability("productId", 0x2007)); //R
    21.     }
    22.  
    23.     // In the Player, to trigger the calling of the static constructor,
    24.     // create an empty method annotated with RuntimeInitializeOnLoadMethod.
    25.     [RuntimeInitializeOnLoadMethod]
    26.     static void Init() {}
    27. }
     
    wlwl2, toma7687 and MikeGDev like this.
  19. MikeGDev

    MikeGDev

    Joined:
    Dec 19, 2017
    Posts:
    53
    Awesome, thanks!
     
  20. Ivan_br

    Ivan_br

    Joined:
    Nov 10, 2015
    Posts:
    29
    Hi @Rene-Damm, is there any update on using JoyCons (button press and sensor data) with the new Input System (if it is compatible or an estimated date on when it will be)?

    Thank you.
     
    Last edited: Feb 27, 2022
  21. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    299
    Anyone been able to get the controllers to work on Windows builds? Specifically the Gyroscope and Accelerometer?
     
  22. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,593
    do joycons work yet? they show up in unity, if I disconnect them and reconnect it looks like its getting data but they still dont work. I will assume they are not supported yet. Its a real shame because it makes deving for switch much harder.

    However If the switch pro controller works then it should be an easy way to mimmic 2 joycons.