Complete and Persistent Control Rebinding with the New Input System - Unity Tutorial

preview_player
Показать описание
Make a complete rebinding system using Unity's New Input System and Rebinding UI Sample. This video will show you how to implement the rebinding menu, disable and enable controls before rebinding, add constraints to the rebinding process, remove duplicate rebinding including composite actions (2D vector as an example), implement a Reset All bindings option, and create persistent rebinds.

ᐅGet the full Source Code Bundle to my Unity Tutorials 🤓

In this video I use Unity version 2020.2.7f1 and Input System version 1.1.0-preview.3. This project is available at my patron link below.

📥 Get the Source Code 📥

🔗 Documentation Links 🔗
ᐅDisplay String Options
ᐅRebinding Operation

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we have recommended. While clicking these links won't cost you any money, they will help me fund my development projects while recommending great assets!

😎 Cool Unity Assets 😎

🤝 Support Me 🤝

►Timestamps
0:00 Overview
1:35 Project Setup
5:23 Rebinding Menu
13:29 Why Use Unity's Rebind Sample
15:15 RebindUI Script Overview
20:21 Disable Action for Rebind
20:53 Add Rebinding Constraints
23:20 Remove Duplicate Rebinds
29:58 Reset All Bindings
31:04 Rebind Script Small Fix
31:31 Reset All Bindings Cont.
32:50 Persistent Bindings
34:15 Outro

💖💖THANK YOU TO ALL MY PATRONS 💖💖

❯❯❯ My Links ❮❮❮
💗 Patreon 💗
💬 Discord Server 💬
🐦 Twitter 🐦
📚 Facebook 📚
🎵 Music 🎵
Ambient Gold
👍 Like and Subscribe! 👍

🖥️ Computer Setup 🖥️
*As an Amazon Associate I earn from qualifying purchases.

#madewithunity #gamedev #unity
Рекомендации по теме
Комментарии
Автор

A bug was found where when you reset an action and the binding is already set in another action, there will now be 2 actions with the same binding. I fixed it so that it swaps the values instead. Full source code available in the description.

Here's the fix:

RebindActionUI.cs

// In the ResetToDefault function add
public void ResetToDefault() {

if (!ResolveActionAndBinding(out var action, out var bindingIndex))
return;

ADD THIS IF STATEMENT


// Check for duplicate bindings before resetting to default, and if found, swap the two controls.
if (SwapResetBindings(action, bindingIndex)) {
UpdateBindingDisplay();
return;
}
// keep the rest as normal

}

/// <summary>
/// Check for duplicate rebindings when the binding is going to be set to default.
/// </summary>
/// <param name="action">InputAction we are resetting.</param>
/// <param name="bindingIndex">Current index of the control we are rebinding.</param>
/// <returns></returns>
private bool SwapResetBindings(InputAction action, int bindingIndex) {
// Cache a reference to the current binding.
InputBinding newBinding =
// Check all of the bindings in the current action map to make sure there are no duplicates.
for (int i = 0; i < ++i) {
InputBinding binding =
if (binding.action == newBinding.action) {
continue;
}
if (binding.effectivePath == newBinding.path) {
Debug.Log("Duplicate binding found for reset to default: " + newBinding.effectivePath);
// Swap the two actions.
action.actionMap.FindAction(binding.action).ApplyBindingOverride(i, newBinding.overridePath);

return true;
}
}
return false;
}

samyam
Автор

I think rebinding is a feature that every game should have. However, there are not many tutorials about this. Thank you!

AlexBlackfrost
Автор

Thank you. This is great.
I think rebinding is essential in a decent project.
I was looking forward to see your tutorial for this. And your method is very intuitive as usual.

Bruce.B
Автор

Honestly, setting up rebinding doesn't seem to be as difficult as I thought, so long as you now what you are doing of course. Great tutorial.

Also I was NOT expecting the persistent rebinding to be that simple.

nightmareblocks
Автор

Thanks for the tutorial. Especially for showing me the script they have made in the preview versions because I was struggling so much with the composite rebinding... It is still not perfect but at least it does the job.

thefrenchdev
Автор

I'm trying to wrap up a project I've been working on for two years, and I had to switch to a newer version of unity for one reason or another. I've been looking at a lot of tutorials on this input system after using unity 2018 and yours was the only one to help me figure out why it wasnt saving my key rebindings. Thank you for finally helping me wrap up this sisyphean nightmare, and I hope we can get more excellent tutorials on godot when I finish this project and make the switch hahah

WhoaitsJoe
Автор

Yes, thank you! Been looking forward to this one.

asztrik
Автор

Your videos on the new input system are great and very informative, thank you!

HadiExtreme
Автор

Thanks for this Sam. I'll keep this in mind for my game later down the track

paypercutts
Автор

Once again, +1 on the awesome Input System!
Thankyou so much for promoting it :) Great work!

scorpionlair
Автор

I'm from México and I'm starting to make my games and I just love your videos, your voice is so sweet and makes me concentrate very well and you make look so easy everything you do. Thank you for all your videos, really really thank you <3 Lov U

cosmemartinez
Автор

I usually don't write comments, but for this one I have to:

By far the best tutorial I found for covering more edge-case issues such as composite bindings or duplicate keys. Really well explained and vividly moderated!
Maybe, instead of jumping through the unity sample, you could have prepared an own, shorter and better named example of the rebind UI, but I guess that would not be worth the extra time.

Keep up the great work, really helped us with implementation!

PlatinumCollectibles
Автор

Thank you, I implemented rebinding to my game with your tutorial. This is a very best tutorial, you explained pretty much everything about rebinding inputs.

ugurtunakoca
Автор

Your videos about the input system are pretty nice. :D

RickyYhC
Автор

I'm having a problem where my WASD binding isn't getting overridden letting me move using different keys. Buttons that are not composite aren't having this problem. Help?

InterloopStudios
Автор

U r the best one Explaining the input systems ❤️

a.technology
Автор

Thank you so much for taking your time to make this. It is very helpful and i hope you are doing great!

noodless
Автор

Thanks a lot for this tutorial, really helps a lot!

paulmozet
Автор

What a magenificent, to-the-point, and clear tutorial. Thanks! :)

imDanoush
Автор

Glad to see another tutorial from you. I was worried you had gone the way of Brackeys.

jonathanjblair