Key Rebinding with Unity's New Input System and Generated C# Code

preview_player
Показать описание
Rebinding keys in your Unity project with the New Input System using the generated C# code. We'll look at how to create the UI code, Input Manager, handles composite inputs, C# Events to update the UI, Exclude devices, save and load the binding at runtime and allow the player to reset the binding back to the default.

Want to support the Channel?
*******************************

Other Links
************

Video Gear List (Amazon Affiliate)
***********************************

Timestamps
*************
0:00 Intro
1:20 Scene Setup
2:32 Controller Code
3:23 Creating ReBind UI
15:54 Input Manager
23:33 Handling Composite Bindings
30:44 Adding C# Events
33:14 Getting Binding Name at Run Time
37:06 Cancel Binding & Exclude Device
40:48 Save and Load Binding
46:39 Reset Binding to Default
50:41 THE END

#NewInputSystem #GameDevelopment #Unity3D #indiedeveloper
Рекомендации по теме
Комментарии
Автор

Thank you for this. I spent all day failing to wrap my mind around key rebinding with the new Input System, until I came across this video. It's both comprehensive and easy to follow. You're a great communicator.

thereisnocowlevel
Автор

Such an amazing tutorial, I found some others but they didn't address the issue with using the scriptable object versus the c# generated script. Such a life saver!

NeonBluz
Автор

Holy Molly this works. I’ve been stuck with rebinding for half a month. Thank you so sooo much!
You can’t imagine how overwhelming and difficult such ‘simple’ things are for a newcomer like me. Finally I can continue working on my game.

Hopecho
Автор

I had to watch this few times in order to get my head around things but overall well done on a topic that hasn't been documented very well. Awesome job.

petarkanev
Автор

Fraking ace videos probably one of the best I seen straight to the point clean and very well explained! Much love for these!

Zultron-sysv
Автор

most professional tutorial I've seen on YouTube regarding any Unity topic! Good job! Very useful!

AdamJankowskiD
Автор

This is the best input binding video that I understand it beautifully.
Thank you so much for your great explanation.

s.mohammedjunaith
Автор

Had an absolute nightmare trying to get this working. This video potentially saved me days of torment. Thank you for explaining this so well!

mandatoryentertainment
Автор

This is the best video on YouTube for understanding how to rebind keys with the new input system. Thank you!

THETVRUS
Автор

dis iz a hella dynamic system bro, good job

revel
Автор

dear "One Wheel Studio", I really liked this video, I congratulate you for helping us, now I'm going to study all your videos, thanks

yuniorbestardaroche
Автор

Thanks so much for this video, it has been really useful! I thought the route of using generated code would end up being painful, but you've explained it all.

ktsu
Автор

This is an immense tutorial! Thank you. It has been so helpful, I never would have managed this on my own.
As others have pointed out there were a few errors but solutions have also been provided, so that's great.

I played about with getting the composite individual key names to appear during binding, but I think I'll go the route of having each key, W A S D on their own, so that it is much clear which key you are currently rebinding.

Also I'll add in some extra functionality to alert the player if they are overwriting a key which has already been bound. When playing with the composites I bound Up, Down, Left, and Right all to the same key :D So I'll have to find a way to prevent that.

mintydog
Автор

Thank you for this tutorial, very helpful. If anyone runs into the problems I had here are some changes I had to make:

- My InputManager is set up as a singleton, so I had to change all the Null checks in LoadBindingOverride(), GetBindingName() etc. accordingly:

if (Instance.inputActions == null)
Instance.inputActions = new InputActions();

- I was also getting Null reference exceptions due to actionName not being references, I assume this is happening because of script execution order. I "fixed" it by adding:

if (actionName == null)
return;

to LoadBindingOverride()

- Since the Instance of my InputManager is handled in Awake, I had to move all the OnEnable() stuff from the ReBindUI script to Start, so the instance already exists in the scene before anything gets called from there. Except for the two lines of UpdateUI event subscription.
- I also had to change OnValidate because the Instance doesn't exist when this is first called. But only when running the game, otherwise the changes made in the Inspector (like changing the keybind) wouldn't be reflected:

if (Application.isPlaying)
if (InputManager.Instance == null)
return;

markuskoepke
Автор

Thanks for answering the most important question upfront, that the example does not work with the C# generated class.

sealsharp
Автор

The reset code has a bug where you can't reset composite bindings. To fix, remove "&& in the for loop. You don't need to check if each binding isComposite. You only need to know if the main binding is.

Fixed code for 48:47:

if
{
for (int i = bindingIndex; i < action.bindings.Count; i++)
{

}
}

_sumarbrander
Автор

As always, thank you very much for this awesome video !

umapessoa
Автор

If you're having actionName be null in build, but work fine in the editor.
if (actionName == null)
return;
Do that in LoadBindingOverride

Laffey
Автор

Fantastic video - thanks for your time creating it!

JonLamont
Автор

Excellent tutorial and super thanks for providing the code.

litgamesdev