- Home /
Multiple Key Input for new Input System Limited?
I've been using the new Input System to write a character controller. Currently, I have WASD for moving, shift for sprinting, and Q/E for strafing. I ran into an issue, however, that causes concern. When pressing more than 3 keys at a time, the input prioritizes the newest key pressed and forgets about the other one that is STILL pressed down. This is an insanely large issue, and I can't imagine this is intended. I can press W, A, and Sprint. Strafing causes A to drop off. If anyone knows a solution to this, I'd be grateful.
private void Awake()
{
masterControls = new MasterControls();
masterControls.Keyboard.Move.performed += c => OnMove(c);
masterControls.Keyboard.Move.canceled += c => OnMove(c);
masterControls.Keyboard.Sprint.performed += c => OnSprint(c);
masterControls.Keyboard.Sprint.canceled += c => OnSprint(c);
masterControls.Keyboard.Strafe.performed += c => OnStrafe(c);
masterControls.Keyboard.Strafe.canceled += c => OnStrafe(c);
}
Answer by toddisarockstar · Jan 03, 2021 at 07:24 AM
looking at this new small "feature" of "master controls".... seems like it would take longer to figure out the bug than to write the entire new "feature" yourself. Seems the friendly unity team will stop at nothing to prevent users from needing to write code. anyways, here is the same thing (cute and organized) that doesn't have bugs and also can expand to detect double clicks, tripple clicks, ups, downs, durations, blah ,blah,blah.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class move : MonoBehaviour
{
public delegate void voids(int i,int state);
public class press {
public bool state;
public voids DoIt;
public KeyCode key;
public int Number;
public press(KeyCode k, voids doit, int n) { DoIt = doit; key = k; Number = n; }
}
public List<press> strokes;
void Start()
{
strokes = new List<press>();
strokes.Add(new press(KeyCode.W, yaxis, 1));
strokes.Add(new press(KeyCode.S, yaxis, -1));
strokes.Add(new press(KeyCode.A, yaxis, -1));
strokes.Add(new press(KeyCode.D, yaxis, 1));
strokes.Add(new press(KeyCode.Space, otherbuttons, 0));
strokes.Add(new press(KeyCode.LeftShift, otherbuttons, 1));
strokes.Add(new press(KeyCode.RightShift, otherbuttons, 1));
}
void Update()
{
int i = strokes.Count;
while (i > 0) { i--; int state = 0;
bool d = Input.GetKey(strokes[i].key);
if (strokes[i].state != d) { state++; if (!d) { state++; } }
if(d||state>0){strokes[i].DoIt(strokes[i].Number, state); }
strokes[i].state = d;
}}
public void xaxis (int i,int state){ print("im moving " + i + " on x" ); }
public void yaxis (int i,int state){ print("im moving " + i + " on y"); }
public void otherbuttons(int i, int state) { print("pushing other button number" + i);
if (state == 1) { print("button down"); }
if (state == 2) { print("button up"); }
}
}
$$anonymous$$akes sense to queue the information rather than just using the immediate result. I think I'll write an object based system that keeps information about the callbacks. I enjoy using Unity's interface that they've come up with for the different input methods, as it makes diversity between keyboard and controller a lot easier to deal with. Thanks for the answer though.
Your answer
Follow this Question
Related Questions
what are the single joystick prefab's inputs for the input manager 1 Answer
New Input System: Can't set binding path anymore 2 Answers
Is there a way to detect a change in Control Scheme with the new Input System? 1 Answer
Toggling with a key not working 2 Answers
create default and customizable inputs 0 Answers