How To Implement Key Rebinding | Unity Input System Tutorial

Поделиться
HTML-код
  • Опубликовано: 12 ноя 2024

Комментарии • 97

  • @xelioth
    @xelioth 3 года назад +3

    oh god, thank you for this. I've been searching for a tutorial for this and they just don't exist anywhere else! You're a lifesaver!

  • @jack-ey4of
    @jack-ey4of 4 года назад +21

    I’m trying to make a simple fps game for me and my friends to play and your series on mirror has been super helpful. You are the new brackeys since he’s taking a break

  • @ravcho4839
    @ravcho4839 3 года назад +14

    For those of you wondering how to rebind composites:
    var bindingIndex = forwadAction.action.bindings.IndexOf(x => x.isPartOfComposite && x.name == "Up");
    rebindingOperation = forwardAction.action.PerformInteractiveRebinding().WithTargetBinding(bindingIndex).
    OnMatchWaitForAnother(.1f).OnComplete(operation => RebindComplete()).Start();
    To change the other 3 just change "Up" to "Down" "Left" "Right".

    • @dustyh5599
      @dustyh5599 2 года назад

      Thanks for this. It was a little jarring to see such a well made tutorial just totally skip this "small" detail, even though he has it right there in the input asset, but never talks about how some one might want to rebind that as well.

    • @WanduHong
      @WanduHong 2 года назад

      Thanks for the info, helped a lot.
      Although I did add an extra line:
      .WithExpectedControlType("Button")
      This worked for me after googling, hope this helps for some people.

  • @ligofleyens9131
    @ligofleyens9131 3 года назад +2

    I was like "let's see if this guy has a tutorial for this, just in case..." and there you have it! Thank you!

  • @rolandwomack9326
    @rolandwomack9326 3 года назад +4

    its super awesome you're addressing this, arguably the most fundamental feature for any game. This tutorial was a big help, however, i'm struggling with cross binding buttons between gamepad and keys from a keyboard.

  • @汉
    @汉 4 года назад +14

    exactly what i was looking for

  • @GTLugo
    @GTLugo 4 года назад +2

    Thanks for this! I was just in the middle of researching how to do this exact thing and here you go!

  • @LMC_Jarred
    @LMC_Jarred 3 года назад

    Integrating the assets from the RebindingUI sample in the InputSystem package hasn't worked entirely, so while this semester-long school project that I'm working on is due in less than 48 hours, better late than never. Lol, but in all seriousness, this was so helpful! Looking forward to future installments on this topic for my personal projects!

  • @MasterofFire-sc3yn
    @MasterofFire-sc3yn 4 года назад +1

    That's got to be the best 15minutes I'll ever spend. (Unity-wise)

  • @IntenseMX
    @IntenseMX 3 года назад +1

    Hey just finished your RTS udemy course. great work Just wanted to say thank you.
    You don't even need the other guys, you're more than capable of doing it by yourself. Looking forward to more from you.

  • @JadonBarnes
    @JadonBarnes 4 года назад +2

    The mad lad finally did it! THANK YOU!

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  4 года назад +1

      Been wanting this for a while? :D

    • @JadonBarnes
      @JadonBarnes 4 года назад +1

      @@DapperDinoCodingTutorials The new Input System has great features, but seems overly complicated for what it is. And lack of clear documentation and lack of hardly any documentation on rebinding is why I haven’t even really touched it in the first place

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  4 года назад +2

      @@JadonBarnes I saw a video the other day on the Unity channel mentioning a few features (rebinding being one of them) so I had a look into their project and the docs then made this tutorial because I know there are many many people want to know how to implement this in their games!

  • @davidk1526
    @davidk1526 4 года назад +14

    Suggestions for another Tutorial about it:
    * Rebinding in a Start Menu without Player
    * Multiple Rebindings with Loops
    * Multiple Controler support
    * Switch Binding Image with Controler (Scriptable Object of Ps4/Keyboard/Switch etc)
    :D

    • @matthieusommervogel1248
      @matthieusommervogel1248 3 года назад

      after many tries, I still can't create a rebind menu in the main menu without the playercontroller :(

    • @davidk1526
      @davidk1526 3 года назад

      @@matthieusommervogel1248 bcs it depends on the references. the playercontroller component is like public YOURINPUTSCRIPTNAMR yourinputscriptname;

    • @matthieusommervogel1248
      @matthieusommervogel1248 3 года назад

      @@davidk1526 Ok so i think we can make this rebind panel in main menu by using the generated script. I just got an idea

    • @davidk1526
      @davidk1526 3 года назад

      @@matthieusommervogel1248 ofc you can all do with c# script the components based on coding too ^^

    • @stepanmeister3803
      @stepanmeister3803 3 года назад +1

      @@matthieusommervogel1248 If you still can't do this I figured out a way. But I don't use PlayerInput. I use the input action asset (in my case called controls) with subscribing to events (e.g. controls.Gameplay.Dash.performed += OnDash;) I make singleton that holds the asset and get it in every class I need it. Now you just need to modify the script in following way :
      * replace "playerController.PlayerInput.SwitchCurrentActionMap("Menu");" with "controls.FindAction(actionName).actionMap.Disable();"
      * replace every "jump.action" with "controls.FindAction(actionName)" - actionName is name of the action in asset
      * replace "playerController.PlayerInput.SwitchCurrentActionMap("Gameplay");" with "controls.FindAction(actionName).actionMap.Enable();"
      hope it helps

  • @ZoidbergForPresident
    @ZoidbergForPresident 3 года назад +1

    Daaaaamn, nice! It's such hopeless how Unity is making this so hard and undocumented. They post that Knights demo but with absolutely NO comment anywhere. It's really hard to follow.
    There's an issue in videogames where key rebinds wouldn't be offered thus making it unplyable for someone who doesn't use a qwerty layout so I had two questions related to that:
    1 How to display the actual character on the active keyboard layout instead of the text on a qwerty layout?
    2 Is there a possibility to go through the input groups and actions programmatically so a tool could be written to generate a rebind screen (like with tabs for each group - Menu, gameplay, etc) ?
    Cheers! I'm going to subscribe for now! :)

  • @adek445
    @adek445 3 года назад

    Hey Dino. Such a great content! I would love to see more advanced input system operations.

  • @ZuloYT
    @ZuloYT 3 года назад

    just what i needed my guy came through with the clutch thanks.

  • @DeepfriedChips
    @DeepfriedChips 4 года назад +3

    EXACT THING I NEEDED

  • @DrDooma
    @DrDooma 3 года назад

    Just what I was looking for Thank you mate!

  • @tonyzaddo
    @tonyzaddo Год назад +1

    Rebinding code is at: 6:43, everything before this is about setting up the demo project.

  • @ChicDead26
    @ChicDead26 3 года назад +8

    Thanks for the tutorial, but i have some questions left:
    How do i rebind 1D Axis inputs?
    How do i display the binds of the question above?
    How i keep these binds through scenes? Or better, how do i save the binds to a variable i could use in my singleton?
    Let me tell you, documentation on this recently 1.0 input system is awful to say the least. The thing itself is very hard to use...
    Hello again, i'm also wondering: maybe its possible to playerInput/playerController entirely from your script? Or, maybe, you could, if you were to rebind in a scene that is not using any inputs? Reading and watching and testing, dont mind me...

  • @RugbugRedfern
    @RugbugRedfern 4 года назад +3

    holy shit I've been blessed

  • @davidk1526
    @davidk1526 4 года назад +1

    Nice tutorial, really good explained. just keep it up. your the next brackeys :D

  • @marscaleb
    @marscaleb 2 года назад +2

    I really enjoyed your tutorial! You did a great job of explaining all the things you were putting in, making this very accessible.
    There are three things I'm still looking for, though:
    One, how do you have a "cancel" option in the key binding? So for example, if I selected the wrong input I could press "escape" and it would exit the rebinding function without assigning a new key.
    Two, how can I revert controls to default? So, rebind input from code instead of specific player input.
    Three, how do I efficiently handle multiple actions to bind? You said you would do a video on this, but I don't see one yet.

  • @JoeGeorge319
    @JoeGeorge319 2 года назад

    I would be so lost if this project wasn't available on github, tweaking the project made learning what's going on here (vs my previous learned way of just adding InputActions directly to a script) much easier

  • @ThefamousMrcroissant
    @ThefamousMrcroissant 2 года назад +1

    The documentation for this system is a trainwreck in Unity tradition, thanks for this. I really don't like the concept of having a callback in an IDisposable as you cannot logically guarantee it will get disposed of. Probably try-finally-dispose it just in case.

  • @LeaHayes
    @LeaHayes 3 года назад +1

    Does this rebinding get automatically persisted by Unity in built games?

  • @daveb7596
    @daveb7596 3 года назад +1

    does this work with game pads

  • @cookiewood6727
    @cookiewood6727 3 года назад

    Hey ! Awesome tutorial, very helpful.

  • @narmalone5116
    @narmalone5116 11 месяцев назад +2

    Idk know why but it seams not working in 2022

  • @marksmithcollins
    @marksmithcollins 2 года назад +1

    Video is missing what calls StartRebinding() and RebindComplete()

  • @archsteel7
    @archsteel7 2 года назад

    How would you go about saving this sort of thing with playerprefs? Say I want this to persist between multiple sessions of play, so that a player may return and find their controls exactly the same as they'd been before?

  • @blossumgames9443
    @blossumgames9443 3 года назад

    You're a legend sir! :)

  • @johncomedia
    @johncomedia 3 года назад

    Can you make a tutorial on rebinding with the old input system?

  • @mr_noodler
    @mr_noodler 2 года назад

    Great video mate

  • @mozikr9694
    @mozikr9694 4 года назад +1

    that was very helpful

  • @fplayfplay3161
    @fplayfplay3161 Год назад

    Does this actually update the Controls (Control Import Settings)? Cause if it doesn't you're only going to be able to use it in one scene, your rebinds are not going to carry over.

  • @calebbennetts3559
    @calebbennetts3559 4 года назад +1

    Awesome. Thanks!

  • @erich795
    @erich795 7 месяцев назад

    Is it possible to save this change?

  • @heavensgates_
    @heavensgates_ 3 года назад

    I know this is an old video but i hope someone can answer, I noticed you're adding classes that you haven't specified and auto-fills the using statements. What addon is that? It would be great to have that.

  • @kken8766
    @kken8766 3 года назад

    perfect timing!

  • @derJoel
    @derJoel 3 года назад

    I want to implement this on top of my game which is using the old Input System and I don't want to change it to new new input system in the near future. Do the two input systems work together/can I use this tutorial anyway?

  • @Patryk-Sowinski
    @Patryk-Sowinski 4 года назад +1

    I was just looking for something like this last night! Do you think this solution could be used together with a joystick too?

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  4 года назад +1

      I don't see why not! Though it's been a while since I've had a joystick to be able to test it myself. Give it a go and let me know if it works!

  • @betadv
    @betadv 3 года назад

    How could I make this save the keybinds in between Sessions?

  • @a.technology1446
    @a.technology1446 4 года назад +1

    Thank u, how to add input system, never done this before

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  4 года назад +1

      I have this old video that might help: ruclips.net/video/KNiM53UbGfA/видео.html&ab_channel=DapperDino and there are plenty other videos on getting set up with the Input System on RUclips :)

    • @a.technology1446
      @a.technology1446 4 года назад

      @@DapperDinoCodingTutorials thank you man ❤️

  • @spidernh
    @spidernh 3 года назад

    how would you do this like in source games, where for example you could do
    bind mwheelup +jump
    how do you bind a key to an action instead of an action to a key, and also how would you have multiple

  • @ctpax1933
    @ctpax1933 3 года назад

    Is the way to save this binding by going through playerprefs or can u change the asset itself in some way?

  • @OrganicCitrus
    @OrganicCitrus 3 года назад

    hey there, I absoluetly love your videos they help so much. anyway I was wondering I'm trying to make a game like pulsar lost colony but im having trouble trying to get the rigid body character to stay on the floor like gravity generator? also ive been struggling to switch from player controls to ship controls, like stopping the character moving switching the cameras ect? :/

  • @rodrigozol
    @rodrigozol 3 года назад

    Thanks Dino, great tutorial, saved us a lot of time! With me, works fine with a keyboard, I also tested with a joystick and didn't work, looks like a "array index check". Any idea why not?

  • @anyshittynickname
    @anyshittynickname 3 года назад

    Why do you set your variables as null when declaring them at the beginning of the script?

  • @yoaquin2986
    @yoaquin2986 3 года назад

    man you are awesome

  • @humansonofhuman
    @humansonofhuman 3 года назад

    Thank you!

  • @theogramme_official
    @theogramme_official 7 месяцев назад

    You can pass the RebindingOperation through the OnComplete callback, don't use a lambda, only pass RebindComplete

  • @serj_1264
    @serj_1264 4 года назад +1

    Hi! Thanks for the video!
    Just for curiosity, is it possible to remap or build custom axis like horizontal/vertical default input manager has?
    Stay safe&cool and keep it up!

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  4 года назад +1

      You're welcome! I've been looking into this because I know it is possible for sure, but I do think there is a bit of code that will be slightly different to what I did in this video. I'll be sure to include it in an upcoming Input System video once I've figured it out myself. Good luck in the meantime! Let me know if you figure it out first :D

    • @serj_1264
      @serj_1264 3 года назад

      @@DapperDinoCodingTutorials I found this:
      wiki.unity3d.com/index.php?title=Unity_Custom_Input_Manager&_ga=2.265472719.1509041107.1607721878-17885974.1474273148
      hope it helps!

  • @666_Man0war
    @666_Man0war 2 года назад

    Thanks a lot!!

  • @smasson99
    @smasson99 3 года назад

    What about composite rebinding?

  • @Iigua
    @Iigua 2 года назад

    Unity's new Input system is such a headache, I don't understand why they didn't just expand the legacy one which works so nicely

  • @steve-zd4kl
    @steve-zd4kl 3 года назад

    help! It works for me but for example my player jump with "space" I change the key to "j" it works, but the "space" key still works. Helpme pls!

  • @GamePlay-dh5mb
    @GamePlay-dh5mb 3 года назад

    just how to save the new key to the system so that wan exit the game still there wan i get back to it 🤔🤔

  • @watercat1248
    @watercat1248 3 года назад

    This sounds amezing and samthin i definitely needs i have few questions i few problems
    Problems
    1. I did know haw to use axis in the new input system
    2. In my project omost all the code made with the old input system i know haw too change i the normal buttons few off this with but i don't know for button like axis and i don't find eny tourial from that to replace the code from old input system to new
    3. The new input system supports only the device i have been added and the consoles contrllers this i problem because off that if saman has i different therd party controllers from what im used the don't ablel to play that mens if want to make customize buttons from therd party controllers the need to use the old input system
    Questions
    1. Haw to create axis
    2. There is eny way to support all devices and not need to add eny therd party controllers separately

  • @googleuser4720
    @googleuser4720 3 года назад

    Missing on persistence on rebinded controls.

  • @jaydeepmodha1
    @jaydeepmodha1 4 года назад

    96th like, doesn't matter if you look upside down😂😂

  • @zolaire
    @zolaire 3 года назад +1

    I have been through so many articles, scripts, stackoverflows, etc. I have yet to find a single solution to how your rebind a key with the new input system and a control scheme...
    Over 8 hours of pure google searching, this video didnt help either unfortunately, please if you know how make a video on it.
    Even the sample didnt work...

  • @valentinstudio3334
    @valentinstudio3334 Год назад

    I mean, problems arise when you have composite bindings and controller + keyboard
    Rebinding a single keybinding/action really isn't hard

  • @cubix02
    @cubix02 3 года назад +1

    How to save changes?

    • @Mushe94
      @Mushe94 3 года назад

      There is a method added to load/save in the 1.1 Input System preview

  • @DeepfriedChips
    @DeepfriedChips 4 года назад

    A more efficient way for press a button text would be to set the button’s text to that and disable interactable and then capture input

  • @francescobrunocia3110
    @francescobrunocia3110 Год назад

    Sarò sempre dalla parte di maldini

  • @ethzalt84
    @ethzalt84 2 года назад

    1:59

  • @RealRogerFK
    @RealRogerFK 3 года назад

    This has less than 10K views. Really makes yuo realize why Unity games have such bad fame...

  • @xmetrix
    @xmetrix 2 года назад

    couldnt find the haitch key.