Тёмный
No video :(

How to Rebind Your Controls in Unity (With Icons!) | Input System 

Sasquatch B Studios
Подписаться 42 тыс.
Просмотров 22 тыс.
50% 1

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - / sasquatchbgames
Join our Discord Community! - / discord
By the end of this Unity Tutorial, you'll know how to setup controls with the new Input System, create an Input Manager for them, and have a fully working key-rebinding system that works for any device, and has an easy option to use Text OR icons for your re-binding UI.
Link to Download the FREE 2D Asset Pack seen in this tutorial:
veilofmaia.com...
---
In need of some Unity Assets? Using our affiliate link is a great way to support us. It's free, and we get a small cut that helps keep us up and running: assetstore.uni...?aid=1100lwgBQ
---
Link to Download icons for basically ANY controller you could ever want:
opengameart.or...
Link that goes into detail about the display options for the Rebinding system:
docs.unity3d.c...
Contents of This Video: ------------------------------------------
00:00 - Intro
00:20 - Setting up Controls and Detecting Input
04:57 - Setting up the Rebinding UI
08:00 - Getting our First Re-binding to work
08:38 - Option to Cancel out of re-binding/Exclude Certain Controls
09:50 - Adding a function to ignore re-bind duplicates
12:54 - Adding the Option to Name our Action in the UI
15:29 - How to Display Icons instead of Text
17:19 - Reset bindings for a specific control scheme
19:01 - Keep Re-bindings persistent
Who We Are-------------------------------------
If you're new to our channel, we're Brandon & Nikki from Sasquatch B Studios. We sold our house to start our game studio, and work full time on building our business and making our game, Veil of Maia.
Wishlist our Games:
Wishlist Samurado on Steam! - store.steampow...
Wishlist Veil of Maia! - store.steampow...
Don't forget to Subscribe for NEW game dev videos every Monday & Thursday!
Follow us on Twitter for regular updates!
/ sasquatchbgames
#unitytutorial #unity2d #unity3d

Опубликовано:

 

17 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 71   
@sasquatchbgames
@sasquatchbgames Год назад
A bug was found where, if you separate a composite binding (ie. A vector2 up/down/left/right binding) into 4 separate bindings that you want to rebind, a duplication was possible within the composite binding itself. To fix this, you'll need to change the CheckDuplicateBindings functions to the following: private bool CheckDuplicateBindings(InputAction action, int bindingIndex, bool allCompositeParts = false) { InputBinding newBinding = action.bindings[bindingIndex]; int currentIndex = -1; foreach (InputBinding binding in action.actionMap.bindings) { currentIndex++; if (binding.action == newBinding.action) { if (binding.isPartOfComposite && currentIndex != bindingIndex) { if (binding.effectivePath == newBinding.effectivePath) { Debug.Log("Duplicate binding found in composite: " + newBinding.effectivePath); return true; } } else { continue; } } if (binding.effectivePath == newBinding.effectivePath) { Debug.Log("Duplicate binding found: " + newBinding.effectivePath); return true; } } if (allCompositeParts) { for (int i = 1; i < bindingIndex; i++) { if (action.bindings[i].effectivePath == newBinding.overridePath) { //Debug.Log("Duplicate binding found: " + newBinding.effectivePath); return true; } } } return false; } This also affects the "reset" button, so you'll need to change the ResetBinding function to the below as well: private void ResetBinding(InputAction action, int bindingIndex) { InputBinding newBinding = action.bindings[bindingIndex]; string oldOverridePath = newBinding.overridePath; action.RemoveBindingOverride(bindingIndex); int currentIndex = -1; foreach (InputAction otherAction in action.actionMap.actions) { currentIndex++; InputBinding currentBinding = action.actionMap.bindings[currentIndex]; if (otherAction == action) { if (newBinding.isPartOfComposite) { if (currentBinding.overridePath == newBinding.path) { otherAction.ApplyBindingOverride(currentIndex, oldOverridePath); } } else { continue; } } for (int i = 0; i < otherAction.bindings.Count; i++) { InputBinding binding = otherAction.bindings[i]; if (binding.overridePath == newBinding.path) { otherAction.ApplyBindingOverride(i, oldOverridePath); } } } } And finally, to ensure you can use either WASD separately OR together, be sure to update the ResetToDefault method to: public void ResetToDefault() { if (!ResolveActionAndBinding(out var action, out var bindingIndex)) return; ResetBinding(action, bindingIndex); if (action.bindings[bindingIndex].isComposite) { // It's a composite. Remove overrides from part bindings. for (var i = bindingIndex + 1; i < action.bindings.Count && action.bindings[i].isPartOfComposite; ++i) action.RemoveBindingOverride(i); } else { action.RemoveBindingOverride(bindingIndex); } UpdateBindingDisplay(); }
@Storm3532
@Storm3532 27 дней назад
This makes it so I can't rebind composites at all, it always says there's a duplicate :/
@Malaron2
@Malaron2 18 дней назад
@@Storm3532 Fix Below, explanation: Essentially when it's a composite, the bindingIndex that's passed in is its index within the composite itself, and not within the entire actionMap list of bindings. For example with a WASD composite, bindingIndex is 0 for the header (we don't care about), the first item in the composite will be 1 (W in this case), second item will be 2 (A), and so on. With the currentIndex++ where it's at, it matches our composite binding's index to the ENTIRE list of bindings. Since the elements aren't 1-1 in both lists, it means index will be off and will try to compare itself against itself, finding a 'duplicate'. Moving currentIndex++ down so it only starts incrementing once we've found our composite object will make it so the binding item will start at 0 at that point, it will skip the header (because the header isn't considered "isPartOfComposite"), and then it will compare your composite element to the first item in the composite. The indexing should be correct so it will skip over itself and not have a false duplicate. :) foreach (InputBinding binding in action.actionMap.bindings) { if (binding.action == newBinding.action) { currentIndex++;
@Deatheragenator
@Deatheragenator 12 дней назад
@@Malaron2 That fixed that issue. Since we're sharing solutions. I discovered that the rebound buttons would only load when I opened the related keyboard or gamepad canvas. Solution: I also added the save rebind script to the EventSystem so it loads when the scene is loaded.
@manningfamilychronicles1601
This is no joke right here. Really daunting going through this. Well done. I'm glad I went through this, and I really appreciate the hard work that went into putting this together.
@trinetrapandey5339
@trinetrapandey5339 12 дней назад
lots of time, lots of sanity saved and lots of features provided, thanks for helping me modify all those high level language programing of unity's prebuilt code
@eneseren8332
@eneseren8332 2 дня назад
Great tutorial! I needed to use it on my own project, and it works perfectly right now.
@adassus
@adassus 4 месяца назад
Thank you for your efforts. Your channel is fast becoming my go to place for quality tutorials full of good practices.
@aditya90m
@aditya90m Год назад
Hey, thanks for the great tutorial. I set up my input system differently, thought I'd share. Instead of using the UI based Input Action control binding, I did it all in code. I set up an "InputAction" for each action, and used the "AddBinding or "AddCompositeBinding" function to bind keys/buttons to the action. This way, I can store my control binding map in a json file and then read it and load the controls easily. For using these actions, I pass a function definition as an "InputAction.CallbackContext" and add it to action.performed and (optionally) action.canceled. This way, the function gets triggered directly when any action is performed. So, I don't need the bool variables to detect when an action has been performed. The triggered function will receive the context and you can detect whether the action was performed or canceled from the context. I wasn't sure out how to do the re-bindings and stuff, but your tutorial has given me a good idea. Thanks again!
@Laumania
@Laumania 11 месяцев назад
This is one perfect video! Thank you. Saving it for when I’m redoing my ui and will add rebinding :)
@castlecodersltd
@castlecodersltd 4 месяца назад
Another really good/helpful tutorial from you. Thank you both 🙂
@pocket-logic1154
@pocket-logic1154 Год назад
Just a tip: You can also press Ctrl + E + C to comment out lines of code, making it a bit easier to reach the keys with one hand in one single motion ;-)
@sasquatchbgames
@sasquatchbgames Год назад
i had no idea, thanks!
@karandhir2411
@karandhir2411 13 дней назад
Amazing tutorial, thank you so much!
@tornadre
@tornadre 11 месяцев назад
Thank you for putting this video together. Really helped me out and I really enjoyed your method of tutorial making. I've subbed and will be checking out your other work!
@fleity
@fleity 3 месяца назад
Very nice, very comprehensive overview of how to so rebinding thank you so much. In the beginning you mention rebinding is easier with player input than generated c# classes, but not say why though?
@thankyouverymuch5743
@thankyouverymuch5743 Год назад
Thank you so much, I was searching for this all day.
@AnEmortalKid
@AnEmortalKid Год назад
For Ui icons, I used Xelu’s controller prompts
@angelrubiov
@angelrubiov Год назад
Thanks so much for this tutorial, it worked for me and I was extremely lost haha
@elesh.n
@elesh.n 3 месяца назад
This is such a life saving tutorial. Many thanks!
@treyhayden4261
@treyhayden4261 Год назад
The duplicate rebind modifications were almost identical to samyam's video. :\
@pengchengliu7648
@pengchengliu7648 4 месяца назад
This is realy helpful, thank you very much!
@ReidWinchester
@ReidWinchester Месяц назад
the reset function is not working for me. i've double checked my RebindActionUI prefab reset button and it's set to call the resettodefault function when the player clicks, but for some reason, nothing happens when I press the button. I've got the actual rebinding portion of the tutorial done, but the reset buttons, which were apparently supposed to work out of the box, just are not working for me. Any advice? I followed the code for the reset function exactly
@Malaron2
@Malaron2 19 дней назад
Did you ever figure this out? I've run into the same issue.
@amirhebadatiyaan
@amirhebadatiyaan 7 месяцев назад
Thanks for the great tutorial!!!
@MasterDisaster64
@MasterDisaster64 Год назад
Thanks a lot for this! Just wondering, how hard would it be to modify this so you can add several bindings to an action instead of just one?
@LilianCRE
@LilianCRE Месяц назад
Hello i'm actualy making a fpv drone video game and i want us to be able to use any radio transmiter. In most of FPV Simulator you have a system call the joystick calibration where you have to move your joystick and the game listen to the input of your controller and bind it. I want to do the same system into my game but i realy don't know how so if somebody know how to do it i will realy apreciat it. Thanx
@matt78324
@matt78324 Год назад
Awesome video! Subscribed!
@sergiovieira4869
@sergiovieira4869 3 месяца назад
Great Video! Can you explain why this method of rebinding won't work if you use C# generated class?
@AnEmortalKid
@AnEmortalKid Год назад
Omg.. i just implemented all of this myself not even knowing there were samples in the Unity package SMH. Learned a thing or two.
@cedriclaps
@cedriclaps 17 дней назад
In my case after I pressed one button for rebinding its not closing the Rebindingpanel :/ EDIT: found out I missed to return false on duplicate instead I returned also true at the end
@codem7173
@codem7173 11 месяцев назад
Great tutorial, ty
@CoderDev6545
@CoderDev6545 6 месяцев назад
I found an issue where if you cancel the rebinding and the binding contains composits, the changes will not get revered and will stay as is. This causes a duplication glitch that I've tried fixing myself, but could not fix. I also found an issue where if you rebind an action, then put in a duplicate, it resets the value back to its original value before the rebinding. However, I found a solution to this error by putting in a variable to remember what is was before the method is performed, so it can revert to that by using "action.ApplyBindingOverride(bindingIndex, _binding);". _binding is the variable that stores the previous value, which you can set before the operation is called: string _binding = action.bindings[bindingIndex].effectivePath;. Can you please help me with the original problem with that being canceling a rebinding that contains composits (which don't revert the changes)? Thank you!
@LordBete
@LordBete 2 месяца назад
Followed every step, but when it comes to testing the rebind, the rebindUI is updated with my new keys but my character still controls using WASD. I assume this is because I have generated the C# class you said not to, but I need that class. What do we do in that case?
@INeatFreak
@INeatFreak Год назад
Great video 👍
@chunsh10
@chunsh10 Месяц назад
I can't see Unity.TextMeshPro assembly at 6:31. Do you know how to resolve this?
@martinchya2546
@martinchya2546 Год назад
Hello. The thing in 4:00 technically is not a singleton. Its a global static reference that self-manages. For it to be singleton, it should automatically instantiate itself. Just a minor nitpick.
@hikineet9673
@hikineet9673 Месяц назад
Thanks
@fplayfplay3161
@fplayfplay3161 9 месяцев назад
Thanks for the tutorial. The last part, saving rebinding, getting: 'InputActionAsset' does not contain a definition for 'SaveBindingOverridesAsJson' and no accessible extension method 'SaveBindingOverridesAsJson' accepting a first argument of type 'InputActionAsset' could be found (are you missing a using directive or an assembly reference?) any idea?
@lacrime_khalil3032
@lacrime_khalil3032 7 месяцев назад
I need help! Everything works fine but in my game my player's jump height is variable on jump key Being held but so i changed the jump input is userinput but now my player jumps by itself when jump key is held, which is not what i want
@AlesVokrinek
@AlesVokrinek 5 месяцев назад
Good tutorial but i for some reason cant rebind like jump to left mouse button. Can you please help me.
@JagGentlemann
@JagGentlemann 10 месяцев назад
I updated the Input System so everything is on point, but the keyboard stopped working with the Action Map I use for the gameplay. I don't want to do all of this without updating, because I know it'll be worse in the future, and the listen function doesn't even work for me in the old version.
@QWERTZ-NOOB
@QWERTZ-NOOB 4 месяца назад
My question is not entirely related to this video but maybe somebody can still shine a light on it for me. Can I use Unity to create a tool that remaps and/or automates controller input? I've made some makros with AHK but I'd rather switch to something more advanced and polished that also uses a C-style language because I don't really like the syntax of AHK and its documentation is very bad. I know that Python is the first choice for tasks like this in the Open Source community but I don't really like that language either.
@SoggettoRava
@SoggettoRava 9 месяцев назад
Hi everyone! First of all, great video, it really helped me set up the rebinding options for my game! Still, I need help with a curious issue. Since I put all key reset into one single button, I managed to modify CheckDuplicateBinding function to integrate the swapping method you describe. This way, new bindings immediately swap with duplicates, if found. And everything looks like it's working fine. Now, I encountered a small issue I'm not sure how to solve, so I'm hoping anyone here could point me in the right direction... As I said, rebinding perfectly works as long as I stay in the Editor. When I build the game, however, something weird happens: I can rebind keys without any trouble, but if I close the pause menu (both with escape and by selectin "resume") and then reopen it, the rebind is maintained, but the controls list displays the original, default keys. Example: M key opens map; I rebind the function to key G; now the list says MAP - G and if I close menu and test, G key opens map (perfect); now, if I reopen the menu, it says MAP - M (original binding), but the G key is still the one performing the action. So, to wrap up, the rebinding works perfectly but it DISPLAYS incorrectly... and only in the build, not in the editor, where new keys are displayed correctly. Any idea on what changes between editor and build? Or on where I should go looking for a solution? Thanks!
@IAutumnWest
@IAutumnWest 4 месяца назад
God bless this video. Absolute hero shit : - )
@BarelyTryingStudio
@BarelyTryingStudio 6 месяцев назад
Hopefully you see you this, I was just wondering, if You assigned those sprites for xbox but if the player only has a PlayStation controller wouldn't the player only see xbox controls until they rebind ? is there a way to set the default inputs based on what controller gets detected ?
@benjaminsettlemire7006
@benjaminsettlemire7006 Год назад
Do I have to use the Input System plugin or can I use the default unity input manager
@barionlp
@barionlp 2 месяца назад
Why does no one use UI Toolkit :(
@tommyyodergamecreator
@tommyyodergamecreator Год назад
Found a bug and I am not sure how to fix it. Let's say you have one button set to R2 and another set to L2. If you remap the button with R2 to X and proceed to switch the second button to R2. When you go to switch the first button back to R2 the font updates but Waiting For Responses is still visible. It would be neat to add the set of code to swap like when you reset but nothing happens if I add action.RemoveBindingOverride(bindingIndex); to PerformInteractiveRebind during check for duplicates nothing happens. Any advice would be great.
@wolflexx
@wolflexx 4 месяца назад
Thank you
@sethdossett1304
@sethdossett1304 Год назад
I was actually gonna ask you how you were doing this in your games haha
@yihongzheng1142
@yihongzheng1142 Год назад
I copy the code step by step and it still can't work in the end ,i don't know why ?😭
@yihongzheng1142
@yihongzheng1142 Год назад
The button binding is successful, but it is not mapped to the character
@animedreammachine7123
@animedreammachine7123 Год назад
Hey man could you do a Steam Deck controls video? Thanks man love the videos
@sasquatchbgames
@sasquatchbgames Год назад
I need to get myself a Steam Deck first. Thanks for the idea!
@ColtPtrHun
@ColtPtrHun Год назад
4:40 Line 97 I think the walk checking is wrong
@readyok8230
@readyok8230 Год назад
Hey there, thanks for this video. I noticed that .WithCancelingThrough ("/escape") will also cancel when you press the "E" key on the keyboard. How would you avoid this? Thanks.
@AnEmortalKid
@AnEmortalKid Год назад
That’s a unity bug. Lemme find you the code for this one sec.
@readyok8230
@readyok8230 Год назад
@@AnEmortalKid Hey there, thanks. The solution is to upgrade to input system 1.4.1
@AnEmortalKid
@AnEmortalKid Год назад
@@readyok8230 omg lol. Ok I shall check if I have the latest.
@flecsodev4210
@flecsodev4210 4 месяца назад
Don't forget to change inputs in settings otherwise this doesn't work
@Coco-gg5vp
@Coco-gg5vp Год назад
First
@justbake7239
@justbake7239 4 месяца назад
it really annoys me when I find a good tutorial but it doesn't stick to good programming practices.
@Luis-Torres
@Luis-Torres 4 месяца назад
Most of the code was done by Unity themselves in this video and was edited by Brandon. I'm curious what the issues you had with the programming practices? 🤔
@justbake7239
@justbake7239 4 месяца назад
@@Luis-Torres As much as i would like to explain doing so in a youtube comment is a bit out of scope. For future reference though don't assume that unity always follows good programming practices.
@Luis-Torres
@Luis-Torres 4 месяца назад
@@justbake7239 I don't assume Unity follows best practices...but that's not the point 😅 Your comment seems to be criticizing the video itself when the reality is that the criticism should be aimed at Unity if at all. If you're going to make a critique about programming practices, then elaborate on that. If you decide not to, then the comment seems kind of pointless to me. I was hoping to learn something from this comment.
@SekGuy
@SekGuy 2 месяца назад
​@@justbake7239well, a lot of the time if it is out of the scope for a comment it is also out of scope for the video...
@sebastianhall8150
@sebastianhall8150 Год назад
First
Далее
How I Would Start Gamedev (if I had to start over)
9:02
Coding Adventure: Portals
16:06
Просмотров 1,3 млн
Unity's "NEW" Input System with C# Events
16:46
Просмотров 88 тыс.
Use Unity's Input System Like a Pro
24:48
Просмотров 26 тыс.
Making a Game with Java with No Experience
8:41
Просмотров 171 тыс.
They made a game about philosophy...
23:19
Просмотров 403 тыс.
Unity's New Input System:  The Definitive Guide
32:07
Просмотров 26 тыс.
Unity's NEW input system in 13 minutes
13:02
Просмотров 17 тыс.
We made Vampire Survivors BUT in 10 Lines of Code
7:08