Search Unity

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

Question Dynamic inline input prompts for keyboard inputs?

Discussion in 'UGUI & TextMesh Pro' started by AVAVT, Feb 28, 2023.

  1. AVAVT


    Jul 28, 2015
    Hello, I'm working on the possibility to show input prompt in a dialogue to the player, basically something like this:


    The keys are rebindable via Unity's `InputSystem`, so it's not always `W` but player might have rebind-ed it to `Up` or something else.

    The idea is NPC should tell player to press whichever button they've bound to "Forward" to move forward.


    Simple solution I have found is to create a SpriteAsset which include all possible rebindable buttons, and show the corresponding sprite in the text. It works for controllers of course, but for keyboards there are so many buttons so:

    - It's a waste or resource to add again and again the same button background with only a slight change of the button name.
    - I can be hard-working and add the 50 labels on top of a background now, but not sure I'll still have the same passion to do that all over again when the artists/designers want to change the button background for some reason.

    Since button rebinding is fairly common these days, how are other people solving this problem? I have tried:

    1. Creating a 0-width sprite as button background, and try to trick the label text on top of it
    -> doesn't work, because Sprites are rendered in submesh and always placed on top of text.

    2. Trying to find a worse option: like let's say not a customizable background but just some simple visual different (`<mark>`) or something: `<mark>` is also placed on top of texts so they must be transparent
    -> looks really, really amateurish.

    3. Maybe there could be a photoshop/GIMP plugins that I can just feed the original background image and a list of text into it, and it would generate all 50-ish rendered sprites for me? Doesn't solve the load size issue but at least if design change it can be remade quickly
    -> Was quite harder than I expected (not much knowledge of PTS/GIMP), and since it doesn't solve the memory issue I gave up on it quickly.

    I'm kind of stuck on leads here. Would love to have more opinions/experience sharing :(
  2. tobias_froihofer


    Jul 30, 2015
    Hi, having a SpriteAsset with all the available buttons and displaying the corresponding button of the currently bound path of the action is the way to go I think. You also should be aware that there different types of keyboard layouts (the most common should be QWERTY, QWERTZ and AZERTY).

    Last year I have made an asset which can handle this functionality. While creating it, I found that a quite satisfying solution for the backgrounds of the keyboard buttons was to use clones in Inkscape.

    Basically I created an object with all the details I needed or might need for the background of the displayed icons and made that my main object. Then I created clones of that object and put the letters of all the keys onto these clones. Now when I need to make small changes like coloring or some small shape changes, all I need to do is to manipulate the main object and batch export all of the key images at once with Inkscape.

    Here is a nice video about how clones in Inkscape work:

    If you want to save some time, you can also get my created keyboard sprites from the asset store:

    The asset I made which can handle the functionality of displaying the current bindings of your actions with support for keyboard/mouse and gamepads is also available on the asset store. I have kept maintaining and improving on it for the past year and a half, so it might be worth a look: