Input Systems Rebind UI sample and advice

Hello,

I have been implementing our games key rebinding screen and have found the rebinding UI sample project very useful.

I need to be able to “clear” a binding, and add secondary bindings to some actions. It would be great if the sample project demonstrated some best practice for how this is done.

Has anybody done the work to extend the RebindActionUI to support actions with no binding, or adding new bindings? Any advice?

Jay.

Clear as in remove or clear as in disable?

// Remove.
myAction.ChangeBinding(1).Erase();

// "Disable" by setting empty path.
myAction.ApplyBindingOverride(1, ""); // As override.
myAction.ChangeBinding(1).WithPath(""); // Directly change path.
// Add binding.
// (If you use control schemes, the "groups" thing is the
// name of the control scheme you want the binding in;
// can list multiple separated by ';').
myAction.AddBinding("<Gamepad>/buttonSouth", groups: "Gamepad");

// Add composite binding.
myAction.AddCompositeBinding("Dpad")
    .With("Up", "<Keyboard>/w")
    .With("Down", "<Keyboard>/s")
    .With("Left", "<Keyboard>/a")
    .With("Right", "<Keyboard>/d");

Thanks, yes. After I posted yesterday I moved from reading sample code to reading the API directly and I have to say the sample code makes things seems a lot more complicated than it needs to be.

I think sometimes devs at Unity forget that we don’t become experts in Unity UI or Input, we just want to do the absolute minimum to get the games in the hands of our players. :slight_smile:

PerformInteractiveRebinding is great btw.

Heh, yeah, I think that goes for the samples as much as for the docs. From a SimpleDemo that isn’t simple to a manual that doesn’t answer some basic questions in a click or two. With us looking past pure stabilization, I think this is one of the highest priority items to tackle.

Think it’s a confluence of factors. But no matter the whys, the result for now is still something too much of a toolbox and too little of a… “prefab”.

Good to hear.

1 Like

Hey, so I built my UIs and they are very nice, but I just found out that my binding overrides are not actually triggering the actions in game.

Any tips for debugging why the overrides are not working?

In the player character we simply have code that looks like this. (I assume it looks like this because we transitioned to the new UI system about 6 months ago.)

public bool GetAimInputHeld()
{
    return inputActions.Encounter.Zoom.ReadValue<float>() > 0;
}

public bool GetSprintInputHeld()
{
    return inputActions.Encounter.Sprint.ReadValue<float>() > 0;
}

public bool GetJumpInputDown()
{
    return inputActions.Encounter.Jump.triggered;
}

Should the override be visible here in the Input Debugger? Is this the path or the effective path?

1 Like

From the code, it looks like you are using the “Generate C# Class” option for your .inputactions asset. The resulting C# class is entirely self-contained with no connection anymore to the original asset.

My guess is that the rebinds are probably happening on the original asset and thus not affecting the generated class.

Good spotting. Thanks. I did not know that was a thing!

Here I was believing for two wasted days that the generated C# class was wrapping the actual asset for proper use, but turns out it’s hardcoding an entire json string with a redundant copy of the whole thing. Just tried deleting it and my project stills works without it.

This is so confusing and looks so unnecessary… Specially when this thing tells nothing about any of this and one is to believe it might be needed to generate the event listeners. Please add clarity to it.

Generating a C# sheet of this asset is only needed in case of A, B and C and will become harcoded in your source, no longer reflecting it etc, etc, etc

If only I saw such a warning, I would have not had this sincerely enraging and table-flipping revelation.

8824648--1201351--upload_2023-2-21_23-13-55.png

There. Right THERE. THIS is where that information should go.