Комментарии:
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!
ОтветитьGreat tutorial, ty
ОтветитьThis is one perfect video! Thank you. Saving it for when I’m redoing my ui and will add rebinding :)
ОтветитьDo I have to use the Input System plugin or can I use the default unity input manager
ОтветитьThanks so much for this tutorial, it worked for me and I was extremely lost haha
Ответить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!
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.
Ответить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.
ОтветитьAwesome video! Subscribed!
ОтветитьThank you so much, I was searching for this all day.
ОтветитьFor Ui icons, I used Xelu’s controller prompts
ОтветитьOmg.. i just implemented all of this myself not even knowing there were samples in the Unity package SMH. Learned a thing or two.
ОтветитьThe button binding is successful, but it is not mapped to the character
ОтветитьI copy the code step by step and it still can't work in the end ,i don't know why ?😭
Ответить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?
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!
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.
ОтветитьThe duplicate rebind modifications were almost identical to samyam's video. :\
Ответить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 ;-)
ОтветитьGreat video 👍
ОтветитьHey man could you do a Steam Deck controls video? Thanks man love the videos
ОтветитьI was actually gonna ask you how you were doing this in your games haha
ОтветитьFirst
ОтветитьFirst
Ответить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();
}