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

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

Sasquatch B Studios

1 год назад

20,842 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

tornadre
tornadre - 20.09.2023 22:00

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!

Ответить
Code M
Code M - 17.09.2023 08:59

Great tutorial, ty

Ответить
Laumania
Laumania - 03.09.2023 11:56

This is one perfect video! Thank you. Saving it for when I’m redoing my ui and will add rebinding :)

Ответить
Benjamin Settlemire
Benjamin Settlemire - 23.08.2023 18:08

Do I have to use the Input System plugin or can I use the default unity input manager

Ответить
AngelOnIt
AngelOnIt - 19.08.2023 03:40

Thanks so much for this tutorial, it worked for me and I was extremely lost haha

Ответить
G-han
G-han - 15.08.2023 23:10

When I use IsPressed() method to check if the button is being held, sometimes it is just not setting the bool true. Is this any kind of bug or am I doing something wrong? WasPressedThisFrame() is working fine but this is not.

EDIT: The problem was me using two different control schemes in one project and spliting keyboard and mouse into two different schemes. So it looks like you can't use both at the same time. While using one th eother is being disabled. So my character wasn't able to shoot while I am moving my cursor.

So I deleted one of them and put both keyboard and mouse into that scheme. Solved everything!

Ответить
Tommy Yoder
Tommy Yoder - 29.07.2023 05:42

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.

Ответить
Manning Family Chronicles
Manning Family Chronicles - 27.07.2023 08:13

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.

Ответить
Matt
Matt - 26.07.2023 05:04

Awesome video! Subscribed!

Ответить
Thank You Very Much
Thank You Very Much - 29.06.2023 17:03

Thank you so much, I was searching for this all day.

Ответить
AnEmortalKid
AnEmortalKid - 20.06.2023 08:15

For Ui icons, I used Xelu’s controller prompts

Ответить
AnEmortalKid
AnEmortalKid - 20.06.2023 08:00

Omg.. i just implemented all of this myself not even knowing there were samples in the Unity package SMH. Learned a thing or two.

Ответить
Yihong Zheng
Yihong Zheng - 16.06.2023 21:28

The button binding is successful, but it is not mapped to the character

Ответить
Yihong Zheng
Yihong Zheng - 16.06.2023 21:12

I copy the code step by step and it still can't work in the end ,i don't know why ?😭

Ответить
MasterDisaster64
MasterDisaster64 - 05.06.2023 02:07

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?

Ответить
Aditya
Aditya - 27.05.2023 10:32

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!

Ответить
ReadyOK
ReadyOK - 21.05.2023 22:54

Hey there, thanks for this video. I noticed that .WithCancelingThrough ("<keyboard>/escape") will also cancel when you press the "E" key on the keyboard. How would you avoid this? Thanks.

Ответить
Trey Hayden
Trey Hayden - 04.05.2023 14:32

The duplicate rebind modifications were almost identical to samyam's video. :\

Ответить
Pocket-Logic
Pocket-Logic - 23.04.2023 02:28

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 ;-)

Ответить
INeatFreak
INeatFreak - 21.04.2023 17:32

Great video 👍

Ответить
Waves and Blaze
Waves and Blaze - 21.04.2023 01:17

Hey man could you do a Steam Deck controls video? Thanks man love the videos

Ответить
Seth Dossett
Seth Dossett - 20.04.2023 17:18

I was actually gonna ask you how you were doing this in your games haha

Ответить
Coco
Coco - 20.04.2023 16:04

First

Ответить
Sebastian Hall
Sebastian Hall - 20.04.2023 16:02

First

Ответить
Sasquatch B Studios
Sasquatch B Studios - 17.04.2023 18:19

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();
}

Ответить