I’m not sure I understand the best practices for simultaneous keyboard and gamepad inputs. This is my menu input. The idea is that either keyboard or gamepad should work. I have a PS4 controller connected to my computer via USB.
When I start a game, the keyboard inputs don’t work. The gamepad inputs do work (although they don’t work perfectly, they seem to register a press every frame, but that might be a bug in my input repeat code since it continues if I unplug the controller).
However, if I start the game with the controller unplugged, the keyboard controls do work. If I plug the gamepad in while the game is running, both gamepad and keyboard work (the every-frame behavior still happens but at least I can tell it’s registering the gamepad input).
This is the component that has access to the player input component.
void Update() {
if (input.enabled) {
InputRepeater repeat = gameObject.GetComponent<InputRepeater>();
InputAction ia = input.actions["Cycle Down"];
if (ia.triggered && ia.phase == InputActionPhase.Performed) {
repeat.Set(OnCycleDown);
}
if (ia.triggered && ia.phase == InputActionPhase.Waiting) {
repeat.Clear();
}
ia = input.actions["Cycle Up"];
if (ia.triggered && ia.phase == InputActionPhase.Performed) {
repeat.Set(OnCycleUp);
}
if (ia.triggered && ia.phase == InputActionPhase.Waiting) {
repeat.Clear();
}
ia = input.actions["Cycle Left"];
if (ia.triggered && ia.phase == InputActionPhase.Performed) {
repeat.Set(OnCycleLeft);
}
if (ia.triggered && ia.phase == InputActionPhase.Waiting) {
repeat.Clear();
}
ia = input.actions["Cycle Right"];
if (ia.triggered && ia.phase == InputActionPhase.Performed) {
repeat.Set(OnCycleRight);
}
if (ia.triggered && ia.phase == InputActionPhase.Waiting) {
repeat.Clear();
}
ia = input.actions["Accept"];
if (ia.triggered && ia.phase == InputActionPhase.Performed) {
OnAccept();
}
ia = input.actions["Cancel"];
if (ia.triggered && ia.phase == InputActionPhase.Performed) {
OnCancel();
}
}
}
Here’s the input component on the same gameobject:
I’m on the latest version of Unity. What am I doing wrong?