ATM thereâs no equivalent to the keyboardâs âanyKeyâ for gamepads. Makes me wonder whether we should actually adapt AnyKeyControl to be AnyButtonControl and add that to more devices. Could be useful.
Anyway. In code, one alternative way is to do
var gamepadButtonPressed = Gamepad.current.allControls.Any(x => x is ButtonControl button && x.isPressed && !x.synthetic);
Unrolling it into a for loop will avoid GC heap garbage.
It should only be true as long as there is some state on the gamepad that isnât at default value. In practice, that will, however, almost always be the case (sticks are rarely at exact zero, for example). Overall, thereâs currently no meaningful definition of a whole device being actuated. So it uses the default definition which is just that itâs state is not at default.
@Rene-Damm Indeed, an âanyKeyâ on keyboard/gamepad/whatever would be really usefull ! Atm I canât use the autoswitch of PlayerInput (it just bugs or idk, related to VR always sending input probably), so being able to do the âautoswitchâ myself with a anyKey binding would be super usefull !
While not super efficient, there are ways in which you can bind to all buttons or all controls on a device even without a dedicated control for that.
To do that, you need to switch the âPathâ property to text mode using the little T button on the right. With that, you have access to the path language directly which allows for writing more expressions than the control picker can currently generate.
Some examples.
// Bind to all toplevel buttons on the left-hand XR controller.
<XRController>{LeftHand}/<Button>
// Bind to all toplevel controls on the right-hand XR controller.
<XRController>{RightHand}/*
Would like to know more about the problems here. Sorry if I missed something you already posted somewhere else. Still catching up.
Iâm using version 0.9.6 of the input system (because nothing works if I go to 1.0 due to the gamepad/xr parts that got removed).
Iâm using PlayerInput, but stuck with using âSend messageâ as Invoke Unity Event is still broken (someone from Unity said it should be fixed in 2019.2.8f but itâs still broken for me).
Iâm able to toggle between VR/Non-VR (gamepad or mouse/keyboard) with the âisTrackedâ action + XRDevie.userPresence, so I automatically switch by putting on the VR headset. For that, I added the headset as optionnal device to all Non-VR control scheme
Iâm listening to InputUser.onChange to modify everything I need between VR/Non-VR.
Iâm currently facing 2 problems :
if I toggle the auto-switch on PlayerInput, VR control scheme gets set everyframe even without the headset / controllers moving or doing anything, my guess is that itâs always sending inputs no matter what, so PlayerInput is switching to this ?
to be able to switch BACK to VR, I need to do this
Sorry about that. I know that the fix has made it out in 2019.3b4 but Iâm not sure about the state of the backport to 2019.2. All I know is it did happen so should make it out eventuallyâŚ
A likely cause of that is controls missing a noise flag. The system relies on controls that give noisy input on being marked explicitly. If a noisy control (such as orientation) is missing that flag, the system will think thereâs valid user input on the control. Let me go and talk to the XR guys about that.
Could you file a ticket through the Unity bug reporter and attach the project? What you describe definitely sounds buggy and we should have closer look.
No problem, just a bit annoying with the SendMessage (and that I will need to rewrite every action :p)
Donât know if itâs that youâre referring to, but I tried checking the âFilter noise on currentâ in the project settings / input system package, but it did nothing. (btw, UI is weird here, canât read all the text).
Iâm doing it and will post the case number here, thanks !
Every control has a noise flag (in the API, that determines the value of InputControl.noisy). This flag has to be set by the âlayoutâ, i.e. the data for a specific device. In this case, the XR layout builder is responsible for setting these flags.
The code that detects control scheme switches will ignore any input that happens to come from a control thatâs marked as noisy. This will prevent, for example, a control scheme switch to trigger from the gyro on a PS4 gamepad.
If a layout isnât setting these flags correctly, the control scheme switching code will mistake noise for real input and initiate spurious control scheme switches. Thatâd be a bug in how a specific device is wired up for the new input system.
(NB: There were some bugs in the layout override code which are fixed on latest develop and will be in the next package; but yeah, means youâd potentially run into some issues on 0.9.6)
Iâll make sure we address it on our side (if this is indeed the problem; could also be something else).
An âAny Buttonâ or âAny Axisâ would be super helpful, as right now it seems impossible to recreate something like this for gamepad or mouse input. The code snippet alternative provided early on in this post no longer works.
or to hook into InputSystem.onEvent (which is relatively quick but not efficient):
InputSystem.onEvent +=
(eventPtr, device) =>
{
if (!eventPtr.IsA<StateEvent>() && !eventPtr.IsA<DeltaStateEvent>())
return;
var controls = device.allControls;
foreach (var control in controls)
{
if (!(control is ButtonControl button))
continue;
if (button.ReadValueFromEvent(eventPtr) > InputSettings.defaultButtonPressPoint)
{
Debug.Log($"Button {button} pressed");
break;
}
}
};
An API to do these kind of event queries a lot more efficiently is in the works (both RebindingOperation and InputUser currently have performance problems related to this).
Hi, will this apply to the mouse as well? I have a tutorial dialog that I want to go away on any input other than things like analog stick deflection or mouse movement.
Gamepad.allControls doesnât seem to be documented anywhere in the gamepad scripting API reference?
I may have missed it but I couldnât find it in any version of the documentation.
Additionally, the 1.0.2 input system doesnât contain a definition for Gamepad.current.allControls.Any
Anyone know how to effectively check for any gamepad input as of Input System v1.0.2?
Searching the forums failed me this timeâŚ
Edit : This very verbose code snippet seems to work. For any practical use, a more elegant solution like Keyboard.current.anyKey would be more convenient though.
for (int i = 0; i < Gamepad.current.allControls.Count; i++)
{
var c = Gamepad.current.allControls[i];
if (c is ButtonControl)
{
if (((ButtonControl)c).wasPressedThisFrame)
{
Debug.Log("Using Pad");
}
}
}
Definitely not a necrobump - Iâm still on the development and now basically still facing the same issue, but pertaining racing Wheel devices.
Which - are seen as Joysticks for some reason.
I wish there was a way to just âget the break pedal valueâ instead of having to buy each and every wheel on the market to make sure itâs mapped to rx, z, y, or whatever else axis (also, why are they unpressed at 1, half pressed at 0, and fully pressed at -1? A pedal?).
I read wheel support has been cut away from the IS and added back to some other major change but - Iâd need it working now, and on PC/XBOX S|X, PSx, etc.
Also, a non-reactive wheel is a wheel which -could- be left as turned 90 degrees - which makes it a bit harder to determine whether itâs actually being used now or just being plugged in and forgot