Search Unity

Question Looking for recommendation for best input solution

Discussion in 'Scripting' started by karderos, Mar 29, 2023.

  1. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    Right now I am simply using

    Code (CSharp):
    1.  
    2. if (Input.GetKeyDown(KeyCode.Space))
    3. if (Input.GetMouseButton(0))
    4.  
    to get inputs as I have been making windows only builds.

    Now I am looking do add some functionality for mobile and gamepads, while still keeping keyboard and mouse as pc options.

    I have seen that there are many ways to manually code each input style, like the Touch struct for mobile for example.

    I have seen that there is a new input system for unity but I could not find info on if it covers all the requirements I need, so I would like to ask for advice.

    My requirements are:

    PC:
    - Keyboard and Mouse
    - Gamepad

    Console:
    - Gamepad

    Mobile:
    - Onscreen canvas virtual Joystick
    - Onscreen virtual Buttons
    - (possibly dont need dragging, pinching, etc)

    I am comfortable just coding each part 1 by 1, but does the new unity input system unify all of the above for smoother workflow?

    Thanks for the advice.
     
    Last edited: Mar 29, 2023
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
  3. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    so would you say that overall I can skip the unity input system and just implement my own stuff? As long as I keep it clean like you say, variables collect input, and all equivalent inputs in the multiple platforms trigger the same 1 method?

    For example both the joystick and the wasd inputs are writing to their own variables but theres only the one method "move" that is triggered when either input is detected.

    Also do I have to worry about detecting gamepads and that sort of stuff? Thanks for the help.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    That's not a thing and I certainly never said that.

    I simply said "gather all input" separately from "process all input."

    If you missed that important point, here it is stated two additional ways:

    https://forum.unity.com/threads/how...a-with-new-input-system.1418386/#post-8912410

    https://forum.unity.com/threads/how...ing-the-new-input-sytem.1331409/#post-8412618
     
  5. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    It's just that you never replied to my question directly, that's the disconnect.

    I can figure it out, I just wanted to know if the new input system was recommended for my case or not. No need to explain how.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Ah, I read this question:

    and most frequently people who ask that have splattered input calls all over their entire project and are staring hopelessly at the void realizing they will need to add NEW input calls all over too.

    That's why the links I provided answer that question.

    I have not cut over to the new input system (except for one game, a VR game where I had no choice) because:

    a) it is much more fiddly to set up involving far more moving parts
    b) it doesn't run on older versions of Unity that I am still supporting
    c) I don't feel like keeping both systems in my brain at once
    d) it has several painful limitations, and
    e) offers me nothing (presently) that the old input system doesn't have.

    Your mileage may vary.
     
    karderos likes this.