I’ve tried googling the hell out of this but I can’t for the life of me find what I’m looking for. At the moment when I go to something like an interactable object, I have it set up to simply just say ‘INTERACT’, but I’m wanting to change it to ‘Press I’ if using a Keyboard, or ‘Press Y’ if using an Xbox Controller, ‘Press Triangle’ if using a PlayStation controller etc.
I’m using the ‘new’ Input System, have my input actions etc all set up and everything works - I just can’t work out how to change the UI Label/Image depending on what input type the user is using?
Any help is really appreciated. I don’t have any example code of what I’ve tried purely because I don’t even know where to start for it. Happy to just be sent the docs if it’s documented, but I can’t find it lol.
Edit: Also sorry if this is the wrong section. I wasn’t sure if it would fall under the Input Controls section or not since it’s the scripting I’m specifically asking about.
I think this is the right place, but it’s a lot more difficult to help you without something you’ve started on.
I think a cool way (perhaps not the best) to approach this is to implement some kind of Localization tool, but for inputs. Then, all of your buttons will pull strings from your localization file depending on the player’s last input, which acts like a “language”. That way, you only have to create a localization for each different button once and never have to worry about it again. Complications might arise when you actually make a localization tool though, as there’s a second layer to check.
It can be useful for the user to know what an Action is currently bound to (taking any potentially active rebindings into account) while rebinding UIs, and for on-screen hints while the app is running. You can use InputBinding.effectivePath to get the currently active path for a Binding (which returns overridePath if set, or otherwise returns path).
// Call GetBindingDisplayString() such that it also returns information about the
// name of the device layout and path of the control on the device. This information
// is useful for reliably associating imagery with individual controls.
var bindingString = action.GetBindingDisplayString(out deviceLayout, out controlPath);
// If it's a gamepad, look up an icon for the control.
Sprite icon = null;
if (!string.IsNullOrEmpty(deviceLayout)
&& !string.IsNullOrEmpty(controlPath)
&& InputSystem.IsFirstLayoutBasedOnSecond(deviceLayout, "Gamepad"))
{
switch (controlPath)
{
case "buttonSouth": icon = aButtonIcon; break;
case "dpad/up": icon = dpadUpIcon; break;
//...
}
}
"
We created a custom system that takes the device and binding strings and returns a specific icon.
For example, if the player is using an Xbox controller and the Attack action is bound to the northern context button, this will display a Y button icon. However, if the player is using a keyboard, then it will display a string for the currently bound keyboard key."