"Rebinding UI" sample bugs & fixes

I integrated the RebindActionUI code in my project and found the following issues. I attached the .cs file with the fixes, so you can diff it against what you have in your repo.

  1. The code didn’t work outside the sample. It always threw the following exception:
InvalidOperationException: Cannot rebind action 'Player/Fire[/XInputControllerWindows/buttonSouth]' while it is enabled

Disabling the action before the rebind and enabling it afterwards seems to workaround the problem:

  1. Leaving the m_RebindOverlay member unassigned causes the following error and the code doesn’t work:
UnassignedReferenceException: The variable m_RebindOverlay of UIRebindInput has not been assigned.

Don’t use the Elvis operator to check for null:

m_RebindOverlay?.SetActive(false);

Use != null instead:

if (m_RebindOverlay != null)
    m_RebindOverlay.SetActive(false);

The Elvis operator doesn’t work with UnityEngine.Object types in some circumstances. It seems to be a long standing issue, see this thread for details.

There are also several ?? operators used on UnityEngine.Object types as well. I can’t tell whether these actually work.

8269290–1083300–RebindActionUI.cs (16.4 KB)

5 Likes

It would be beneficial when you move the “BindingId” code from RebindActionUIEditor.cs to a PropertyDrawer/Attribute and preferably have the classes in InputSystem and not in the sample project.

This would allow to reuse rebind functionality more easily and you can already see from the sample project that such functionality is needed in a project anyway.

Did my feedback make its way to someone on the input system team? :eyes:

It made it to me at least. Thanks for the thread, this is still an issue in the version I tried 1.7.0 sample

1 Like

Thank you Peter, I’ve added your suggested code and it should be available once 1.8.0 fully releases out of pre-release.

2 Likes