Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What Is The Best Way To Make A System That Returns A Sprite Of A Gamepad Button

Discussion in 'Input System' started by EitanZ, Apr 14, 2019.

  1. EitanZ

    EitanZ

    Joined:
    Oct 11, 2016
    Posts:
    6
    What is the best way to make a system that returns a sprite of a Gamepad button, that will support multiple controller types?
     
  2. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    "Controller types" in a brand sense (PS4 versus XBox) or in a shape sense (two-joystick gamepad, VR hand controllers, Wii Remote and Nunchuk)?
     
  3. EitanZ

    EitanZ

    Joined:
    Oct 11, 2016
    Posts:
    6
    Basically I want to display a sprite that represents the binding that activates something in game, for things like prompts, quick time events and tutorials that explain which button you should press. I already have sprites that map every button for Dualshock 4, Xbox One controller and Keyboard and mouse.
    Let's say i want a prompt to pop up on the screen. I want the prompt to display [ E ] if the active input comes from the keyboard, and if not, detect which brand of controller is used and display a sprite of [Gamepad/buttonSouth] that matches the controller brand ("x"on ps4 , "A" on Xbox).
    I just need to know what is being used as a controller Keyboard & Mouse/ Dualshock/Xbox One Controller.
    What is the best way to do that?
     
  4. jweidenbach

    jweidenbach

    Joined:
    Dec 29, 2018
    Posts:
    54
    It's pretty simple to detect the controller types on windows. The device has a property called "name" that you can query; for an XBoxOne controller I get "XInputControllerWindows" (in the Input Debugger), for a PS4 controller I get "DualShockGamepadHID". You could take that information and use it to return a specific sprite. I don't have any code for this at the moment, but it seems pretty straightforward, and honestly the specific query highly depends on the specific methodology you're using to query your input. If you're using a PlayerInput component, you can query .devices on that component, as a start.

    Off windows, it really depends on the platform drivers.
     
    TMuggle likes this.
  5. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    Huh. I could probably stand to bookmark this thread so I can access this answer.
     
  6. EitanZ

    EitanZ

    Joined:
    Oct 11, 2016
    Posts:
    6
    I have a solution, I'll post it soon!
     
  7. EitanZ

    EitanZ

    Joined:
    Oct 11, 2016
    Posts:
    6
    Please read the description
     
  8. Shaolin-Dave

    Shaolin-Dave

    Joined:
    Apr 3, 2015
    Posts:
    32
    EitanZ's solution will work for what you're going for, but I think you should consider not having dynamic gamepad icons.
    Someone who's new to a PS controller will see the icons on screen and have to look at their controller to find it. xBox vs Nintendo have the same button names in different places, xBox vs Logitech have different colored buttons, then you get into all the other possible gamepads....
    I suggest just showing a generic gamepad image and highlight the button. No matter what they're using, they don't even need to look off the screen to find it. Easier for the players, easier for you.

    mario-example.png
     
    MegamaDev likes this.
  9. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,274
    I like it. It's a neat design that reads well. I get confused to this day when a game tells me to press L2, so just showing a top-down view of a controller with L2 highlighted would read much faster.

    It might be that you end up eating more screen space than just using an image of eg. square, but it's probably worth it.

    Won't work for keyboards, though.
     
  10. Not to mention that it should be done very carefully. Colorblind people may have some problems with this design, also people who have low vision (it should be big enough on the screen).