using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class PaddleInput : MonoBehaviour
{
private PlayerInput playerInput;
[Header("Controls")]
[SerializeField] private string movementActionName;
[SerializeField] private string usePowerActionName;
// Variables
public Vector2 input { get; private set; } = Vector2.zero;
public event Action powerKeyPressed;
private void Awake()
{
playerInput = GetComponent<PlayerInput>();
}
void Update()
{
input = playerInput.actions[movementActionName].ReadValue<Vector2>();
playerInput.onActionTriggered += OnActionTriggered;
}
private void OnDestroy()
{
playerInput.onActionTriggered -= OnActionTriggered;
}
public void OnActionTriggered(InputAction.CallbackContext callbackContext)
{
if (callbackContext.action.name == usePowerActionName)
{
if (callbackContext.performed)
{
powerKeyPressed.Invoke();
}
}
}
}```
#š±ļøāinput-system
1 messages Ā· Page 34 of 1
uhhh i wouldn't use onActionTriggered. It would be better to do:
playerInput.actions[usePowerActionName].performed += OnUsePower;```
that being said I don't immediately see a functional problem here. Can you add some logging? like:
input = playerInput.actions[movementActionName].ReadValue<Vector2>();
Debug.Log("$Read input from {movementActionName} - the value is {input}");```
Okay! one second
Oh thanks! The example I found online made it the other way
This is clearly better
yeah OnActionTriggered is like a giant event that fires when almost anything happens, rather than focusing on a single action
It just doesn't read it from the buttons, only from the keyboard
But the up and down arrows, it reads them normally
Even worse, when I build the project for android, the opposite happens, the buttons that simulate W and S work, and the buttons that simulate the arrow keys don't
š„²
wait do you have more than one PlayerInput component in the scene?
Yeah
that's your problem
Oh, really?
each PlayerInput grabs exclusive ownership over a set of input devices
in this case the virtual keyboard probably
so one of them will work, one won't
Oh, I see. but then why does it work fine when I use the physical keyboard?
Well, I created a single instance of the player input in the game manager and a getter for it to access from the player scripts
And now it works perfectly, thank you!
I am working on creating a XR controller that activates when a headset is connected and when not connected, a regular windows controller is active. The XR controller does activate and the regular player deactivates but the XR player does not work, while I can look around I canāt do anything else, gravity does not effect me and I canāt walk around. I have attached the components on my XR player, if there is any other information that would be helpful please let me know!
@livid valve @forest echo
I came here to Discord looking for a solution and saw that you guys had the same problem as me. The game works normally in Unity Editor and on PC, but on Android it doesn't recognize any clicks when we use the New Input System. I haven't found a solution yet, but I realized that it's something to do with the migration from the Old Input Manager to the New Input System.
My project uses the Old Input Manager, and I'm trying to migrate to the new one, which caused the problem.
I created a new project from scratch, containing only one Input field and one button, using the New Input System, and it worked on a real Android device.
Now I just need to find a solution for this...
please don't ping specific people for help.
do you perhaps have input handling set to both?
I'm not asking for help, I'm sharing what I've found so far.
No, I don't have it set to both, I set it to 'New'
Found the solution, sharing because it can help someone else.
My scene is a remote addressable and I forgot about it, so I had to replace StandaloneInputModule by InputSystemUIInputeModule and update my remote addressable.
hello
i know this isnt technically the input system but i am having some weird issue where OnPointerClick doesnt do anything, it should be firing but it doesnt, OnMouseDown works, but not OnPointerClick, why ?
i made an empyty scene with only a cube with the script in it (see image, the fact that its visual scripting shouldnt matter), a camera with a physics raycaster on it, an object with an evensystem on it, but it still doesnt work for some reason, i did check that everything is on the same layers and stuff but i am stumped, it used to work and it randomly stopped firing today
i couldnt find answers online
mystery solved, i removed some stuff in the input system and i didnt know that onpointerclick relied on that, i thought it was just default unity inputs that you can change around and stuff, thankfully theres a button to bring back the defaults on the even system component, yippie
Have you tried removing it and reinstalling?
Yes, removed, reinstalled, restarted, redownloaded unity
Look up how to find the package cache and see if deleting the package from the cache helps
Thank you, i cleared cache from AppData/Local/Unity/Caches and it worked
nvm, after restart again now all my packages are invalid
just ignore it until the issue is fixed, it's on Unity's side.
Is there any way to put the center of the on-screen stick on the center? I tried changing the pivot of the arrow but it doesn't work.
Can you open the sprite you're using in the sprite editor and show it?
Okay!
kinda weird for an onscreen stick
i'm not sure what the circle in the top left is tbh
the one in the center seems to be the pivot
The circle in the top left is the area on which the stick moves
Idk why it isn't on the center
Can you show the RectTransform settings for it
In the first images I sent
The RectTransform inspector is not visible
wait nvm
hmmm, this is confusing. Why is your stick a tall rectangle? What's the idea with that
ahh the animation works if you click the link, not sure why it's not playing in the embed
I set it with static origin to be able to both use it as a stick or as two buttons if you tap on the sides
I'm unclear what you're trying to do here.
To be honest I think what they basically want is a slider that will count as an input axis.
but without a visible handle
And only provides input when touched
should i use OnClick for buttons to switch gamestates or is that bad practice?
it's not bad practice, and whether it's a good idea or not depends wholly on your game's setup and flow
Hi All, Having an issues with my mouse controls for looking... When running my game the input from my mouse does not seem to be working, Its only after i go into Input Debugger and Enable the Mouse that it works... Although the keyboard inputs work without doing this. Is there a way to permanently enable this? Thanks.
how are you receiving input? are the bindings perhaps set to different control schemes
I created a single Keyboard and mouse scheme, and make it the default on the "player"
can you show screenshots of your setp
you said you had a single keyboard and mouse scheme?
I think so š
seems like you have 3 control schemes, one called keyboard, one called mouse, one called keyboard+mouse
ah wait no hold on
i think ive confused myself
yeah ok i misremebered the brackets being the control scheme, whoops
Hi, we are having an issue in our game where controller inputs are doubled when Steam Input is enabled.
Basically the original controller signal AND the Steam Input signal both reach the game, causing in a frequent back and forth between both Controllers.
Player1 Device switched! Axis:/XInputControllerWindows/leftStick/x
Player1 Device switched! Axis:/XInputControllerWindows1/leftStick/x
Player1 Device switched! Axis:/XInputControllerWindows/leftStick/x
Player1 Device switched! Axis:/XInputControllerWindows1/leftStick/x
Player1 Device switched! Axis:/XInputControllerWindows/leftStick/x
Player1 Device switched! Axis:/XInputControllerWindows1/leftStick/x```
As you can see it switches between XInputControllerWindows and XInputControllerWindows1. One of them is Steam Input and one is the actual Xbox controller.
Is there any way i can ignore the "normal" Controller when Steam Input is enabled?
It might be a setup issue on my side, but I can't find anything in the InputSystem codebase to show me how this should be handled in theory. Is SteamInput supposed to supress the original inputs from reaching the game? Is there any kind of "deactivated" state of a input device i'm not considering?
Edit: also created a Unity Forum topic https://discussions.unity.com/t/steam-input-duplicated-input/1706043
Hey, I'm trying to use Accelerometer as an input, when in Editor using Unity Remote I am able to use it just fine, but when I build and try it on Android the value returns a Vector3 zero
I've tried both "Input.acceleration" in code and also using Input Actions and neither seem to work on the actual build, only in Editor using Unity Remote
perhaps you need to ask for permission to use accelerometer input?
that's a shot in the dark
How are you using Steam Input? I am interested in supporting that, but I've never looked into it
I'm not using it personally, we've just gotten multiple reports of people having issues with it. On some machines it's just activated by default, even though we support all controller types. I was able to reproduce the double input issue by activating Steam Input while the game is currently running, but there are a lot of people who encounter by just having it enabled and starting the game.
I think as soon as you start the game using the Steam Overlay, Steam Input can be enabled in the Steam Overlay Settings
interesting ā does this happen on a Steam Deck? I have one for testing on Linux
I only know about it happening on windows, might happen on Steamdeck too, not sure.
Hey all! What's considered best practice for implementing controller rumble in unity? I hear Gamepad.SetMotorSpeeds() is very very heavy (2 to 4 ms???) so I'm guessing that's not it
I'm seeing surprisingly little info and tutorials for this side of controller implementation online
(similarly enough when last week i was looking for gyro implementation i litteraly found nothing - if someone has leads on that it could be cool too)
The real haptic support is only possible on native platforms which you canāt access unless you have the relevant platform SDKs. Outside that, basic rumble support is available through input system or a custom device implementation which you have to DIY per device.
when you mention, "through input system" do you mean by using Gamepad.SetMotorSpeeds()? I tried an implementation with it and my switch pro and dualshock 4 controller both ignored it completely, while my dualsense controller seems to work with them but ignores about one 3rd of instructions
Im using Player Input ->Events and have a OnInteraction - Action of Button Interaction type. Is there anyway to only trigger it once so you cant hold it? I
I read about InputActionReferences which kind a do what i want. But i was wondering if there is another way.
AFAIK it doesnāt work for the PS5 dual sense. But it should work for the PS4 DualShock. To use haptics on the PS5 controller you need the PS5 SDK and build for that platform. Whether you can work around that by custom implemented input device in Unity and some windows driver, I donāt know. If the device isnāt supported by the OS driver, you need to build or buy the missing pieces yourself.
You also need to respect the hardware latency & inertia of the device. If the controller has a motor, not a piezo, a short enough signal may not translate into any motion.
Generally if you want to work with gamepads, itās best to target the specific device, not the gamepad abstraction
thanks for the info, this is precious
I'm having a big headache regarding keys being held when a scene changes.
I don't even know if it's related to my code, but currently my code is this
āØāØ```cs
bool sprinting => ClientInput.Primary.Sprint.IsPressed();
When the scene changes, if the key is down, the input acts reversed. Pressed is up, and up is pressed. I've tried a lot of things but nothing has really helped.
can you show the rest of the code
Beware, it's a big and messy class cause it's for the 48 hr global game jam
https://pastebin.com/s6XCfLzm
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
The commented lines are things I've tried to fix it
Hey guys i've made a custom virtual mouse however it doesnt allow any interaction with ui. here is the following code:
https://paste.ofcode.org/qLe4GezhrrXTpu8WAtp2Dh
I've properly set up the event system and ui input module yet it doesnt detect ui.
I've properly set up the event system and ui input module yet it doesnt detect ui.
This is a pretty dubious assertion
Is there a good reason you're using control schemes?
Are you doing local multiplayer?
Well I just found it on some source not really
Yes
yes, inputsystem can use arbitrary input devices provided you give it configuration on how to treat it
there might be a package that provides that config to input system, perhaps try searching around in eg upm
Well I have GameCube controller adapter
But it only detectives whether the adapter is the mode "PC", not the mode "Wii U/Switch"
The mode "Wii U/Switch" have the controller of Zadig
Hey
the app on startup doesn't register gamepad input until I move my mouse or press a keyboard key. The lack of focus for the app is a huge problem on SteamDeck.
private void Start()
{
if (InputUtilities.lastUsedDevice is Gamepad)
{
Cursor.visible = false;
this.PlayButton.Focus();
}
}
this code runs and registers the gamepad properly, but the gamepad input is not being recognized. I'm looking for a way to focus the OS on the game with just the gamepad.
I'm using InputSystem and UIToolkit, Unity 6.3, and starting my game with a gamepad.
Please help!
Look into how Devices are binded into users, maybe. From my own experience in my project once there's something a device binded you'll have to manually bind a second one if you want it binded on the same user
This meaning, Unity creates a InputUser with keyboard, it will not bind a gamepad to it, and it will instead create a new InputUser
Though it has been a while since I've done a deep dive like that
I'm having an issue of my own, I currently have some code meant to do something:
[SerializeField] InputActionReference? toggleAction;
if (toggleAction != null)
{
toggleAction.action.performed += OnTogglePerformed;
toggleAction.action.Enable();
}
The action is performed just fine when I have no InputUsers, but the moment I perform a pairing (and thus create a InputUser) it stops working:
newUser = InputUser.PerformPairingWithDevice(pairWithDevice ?? InputUser.GetUnpairedInputDevices().FirstOrDefault());
//Associate the Game Input Actions
var a = new GameInputActions();
a.Enable(); //TEMP: Enable here?
a.System.Enable(); //Enable the System Action map. This should be enabled at all times.
a.Debug.Enable(); //Also enable the Debug action map.
newUser.AssociateActionsWithUser(a);
Is this because I am creating a new action here and is not holding the same reference to the one that my monobehaviour has?
When I copied some of Unity's systems over a year ago or so I had this:
public LocalUserJoiner()
{
// if the join action is a reference, clone it so we don't run into problems with the action being disabled by
// PlayerInput when devices are assigned to individual players
if (_joinAction == default || (_joinAction.reference != null && _joinAction.action?.actionMap?.asset != null))
{
_joinAction = new InputActionProperty(_inputActions.System.UserJoin);
}
}
Then some notes around:
1. Global binding re-resolution: When the user's GameInputActions is enabled, it sets s_NeedToResolveBindings = true globally (InputActionMap.cs:327). This triggers DeferredResolutionOfBindings() which iterates over ALL action states and re-resolves bindings.
2. Full re-resolve disables/re-enables actions: During a full resolve (InputActionState.cs:421-425), actions are temporarily disabled and then re-enabled. If something goes wrong during this process, actions may not be properly restored. ```
So that's why I suspect there's something acting with creating and assigning something through code to trying to use an action because its a gameobject UI element holding a reference
I also suspect there might be something to do with group filtering (Control scheme)
The action itself has a Keyboard&Mouse group filtering, but the way I perform pairing with a Mouse is janky as hell:
Entity JoinPlayer(short playerIndex = 0, string controlScheme = "", InputDevice? pairWithDevice = null)
{
if (!CheckIfPlayerCanJoin(playerIndex))
{
Debug.LogError($"Failed to join player: Invalid index {playerIndex} or max players reached");
return default;
}
//This should create a new user.
InputUser newUser = default;
try
{
newUser = InputUser.PerformPairingWithDevice(pairWithDevice ?? InputUser.GetUnpairedInputDevices().FirstOrDefault());
if (!newUser.valid)
{
Debug.LogError("Failed to create valid InputUser");
return default;
}
}
catch (Exception ex)
{
Debug.LogError($"Failed to pair device: {ex.Message}");
return default;
}
if (pairWithDevice is Keyboard)
{
var mouse = Mouse.current;
if (mouse != null)
{
InputUser.PerformPairingWithDevice(mouse, newUser);
....
}
else
{
.....
}
}
//Associate the Game Input Actions
var a = new GameInputActions();
a.Enable(); //TEMP: Enable here?
a.System.Enable(); //Enable the System Action map. This should be enabled at all times.
a.Debug.Enable(); //Also enable the Debug action map.
newUser.AssociateActionsWithUser(a);
(...)
So that might not be working because the Action is looking for keyboard and mouse and Im not doing that correctly
Oh also this applies if you are using Unity's systems, as what I cloned and remade myself (literally all the stuff I just wrote about my issue) comes from that behaviour
I believe its that monobehaviour UI thing that the manual tells you to use
I've switched over to the new input on a new project, but even after setting up everything I'm still getting this warning in the console
seems like you're using the old input system somewhere still
or it may be a dependency/package
The only non-Unity package I added was UniTask, which shouldn't touch input at all.
I've also not set up any scripts to read input yet, either old or new
This message just comes up when your active input handling is set to Old or Both
even if nothing is actually using it
Check your Active Input Handling setting in player settings -> other
You know what? It was the old event system object buried in my hierarchy, it had the old module in it and not the new one
Would be nice if the warning flagged what component was triggering it, as this has been bugging me for a while
Nope, wasn't getting an error at all from it when I hit play.
odd
well, not an error, just warnings
Nope, still getting the warning after deleting the old module component and the extra event system
It was also this. Switching to the new is so fiddly. Every time I start a new project I forget half the things I needed to do to switch.
I feel like there needs to be more guidance after installing the package, like a popup wizard of some kind to configure everything
Pretty sure Unity defaults to new input system on newer Unity versions
I need help with implementing gyroscope/phone-tilting controls with the new input system. I managed to have simple controls with WASD/Arrow Keys, and now need to do the same with gyroscope. What's the best way to set it up in the Input Action Manager? How do I retrieve the values?
Make a Value/Vector3 action and bind it to the gyroscope
then read the data as you would from any other input action
Stupid question: how do I read the data?
Previously, when I took values from my keyboard, I wrote this:
Vector2 input = playerInputMap.FindAction("Move").ReadValue<Vector2>();
Now I'm realizing that just replacing the action name and vector type isn't really going to work here. Do I need to check and/or enable the device with the gyroscope before I read the values? What am I missing?
Now I'm realizing that just replacing the action name and vector type isn't really going to work here.
why wouldn't it?
Replacing the action name and type will work here
(though, imo you shouldn't be using magic strings to begin with)
unless you mean that your code does not know how to handle a Vector2 for this rotation
'Cause I just did - and no values are being returned
as in, you're getting a zero vector?
does your device have a gyroscope
did you enable the input action?
I'm tiling the phone during the game scene - and all X, Y, and Z values return 0
are you making a build, or are you using Unity Remote
I think so?
Doesn't every phone after 2020 have a gyroscope?
try checking the input debugger to see if the gyroscope is being picked up
for all I know you're using a potato
Unity Remote; it worked for me before
I'm not sure it supports gyroscope
not sure if the input debugger would work through unity remote, never looked into that before
I tried to tick my phone in Input Debbuger -> Remote Devices, and I just got this error:
Failed to connect. Check if there is an app running on the correct device and it was built with Developer Mode enabled. In case of further issues you can enable the player connection diagnostic switch to get more information.
The way I see it, is that it doesn't want to fully connect to the project, even though it recognizes the device?
(I think I'll be taking a break now)
Did you make a development build?
Is anyone else having the issue where their thumbsticks feel 'springy'? I was testing a movement system using root motion and I feed the magnitude of the thumbstick input directly to the animator. What I have noticed is that if I quickly snap my thumbstick from 0 to about 0.5 or so, it will actually reach 1 and then come back down, like the input has some kind of predictive momentum to it.
- Am I the only one who has experienced this?
- Is there a way to turn it off?
My code for reference, but I am not doing anything special here.
Even using the input directly and ignoring the rotated vector it still behaves this way. I have found this problem difficult to search because its hard to articulate it, but I have found no settings that seem to relate to it. I am just using the default Input System settings from a brand new project.
There's no input processors or anything on any layer of the Move action.
Sigh. After looking at my controller configuration in windows, this seems to be a hardware problem. So bizarre. I don't think I've ever seen it before today.
The only way I can imagine around this is by using a convolution filter of some kind, which will introduce some latency. That sucks.
So Iām trying to get into making VR games and Iām currently following a YouTuber by the name of valem tutorials and for the controller tracking I needed to put in an input action reference that is titled XRI left/position, but when I go to the page it doesnāt show up anyone have any suggestions?
Did you create such an action?
No, it was supposed to be part of the XR interaction tool kit, and apparently it was just supposed to be in there
You might be using the wrong input action map. I remember it being a little too well hidden. If you Create a new scene, right click in the heirarchy and add the XR rig or an XR canvas, I think it will pull in the proper Event System and point you to the right asset.
This is where mine was located
OK, let me try that and Iāll get back to you
So another issue that was preventing me from going forward was that when I was trying to get the XR origin it only gave me this option so I donāt know if itās like a new thing. Do you think I should just do that?
Are you pressing the plus sign? Or right clicking in the hierarchy space?
I have found that using the XR menu keeps me out of trouble 9/10 times. But it really depends on what you are doing. If you have your own prefab variants that you based off of items spawned from that menu, use those obviously.
Sorry I didnāt see this message until I got out of work which one should I do?
I mean try them both lol, but right click in the space
Your screenshot looked like you did the plus button which isn't what that tutorial did
Ok ok believe I fixed it. I just had to downgrade to the version he was using. I just didnāt do that earlier because he said that this part shouldnāt change
Hello,
I created a visual interface in my game, and the new input system has started malfunctioning badly... I don't know how to fix it.
If you know how it works in detail, I would be very grateful to hear your explanation because it's a complete mess to me...
(PS: I don't know how to explain it, I'd like to call to demonstrate because I can't find the words to describe it)
I've fix this š
Hello, I have a quick question. I'm using Unity New Input System in my Project and I'm using Linux OS.
I have a problem, I'm trying to display current key binding on action so player can rebind it. Im using GetBindingDisplayString() and it returns correct key name + some gibrish that I have no idea where it come out from
And that part after W appears in all of the keybids
Only mouse buttons are correct
https://www.youtube.com/watch?v=OMVMqFZV03M
may be use that for to help u ?
Getting started with the New Input System: https://youtu.be/ONlMEZs9Rgw
Join our Discord: https://discord.gg/WSus22f8aM
Get me to coach your game & gamedev career: https://calendly.com/bitemegames/gamedev-coaching
Thank you to our Patrons:
Stephane Gregorysatha
Sander Zwaenepoel
evykdraws
Anthony Lesink
Jon Bonazza
Gabrielle Edwards
AdriƔn...
use you a Rebinding UI ? it's in sample of package Input System
Im rebinding like this
i've never used that, but I think it's importent to see
Im 99% sure its a OS problem
may be
But I have no idea how to solve it
do u use a rebind action UI script ?
When you log the value is it actually outputting like that or is it only in your UI
It's also logging
It's logging even if you just get the string from the input system without modifying it in any way?
Bizarre
I know XD
Ow and on Windows in works fine, my friend checked that
It's just Linux case
Can you post the extra characters here?
Wdym?
The 3 characters that are being appended
your key it's D for D@7B ?
have u see in input debug if it's that ?
I just want to search for them but I don't know how to make the first character to search it
have u try with the exampl of input system package ?
that
OW SIHIT
YOU ARE RIGHT
But how the hell to fix it
all right
hum, i don't know, i search
what's ur keyboard ? (AZERTY ? QWERTY...)
for sur
But Im clicking to make it english and it dosent solve issue
don't fix ? mmmh, wait
for exampl it's my keyboard layout
no, it's all keys... the order
nice, it's good XD
u are in linux or OS ?
Kurwa... pls kill me
Linux
Okay but RebindUI still uses GetBindingDisplay to show string
And thats result of that sample
so delet the text after ur string about the key ?
yes try it
Okay I wrote parser based on effective path
If anyone ever needs Im sending code
private string GetBindingName()
{
StringBuilder sb = new("");
string keyPath = inputActions.asset[targetAction.name].bindings[index].effectivePath;
string keyName = keyPath.Split('/').Last();
// Handle mouse buttons separately
if (keyPath.Contains("Mouse"))
{
return keyName switch
{
"leftButton" => "LMB",
"rightButton" => "RMB",
"middleButton" => "MMB",
_ => throw new System.Exception($"Unknown mouse button: {keyName}")
};
}
// Add space before uppercase letters (except the first one)
for (int i = 0; i < keyName.Length; i++)
{
if (i > 0 && char.IsUpper(keyName[i]))
sb.Append(" " + keyName[i]);
else
sb.Append(keyName[i]);
}
return sb.ToString().ToUpper();
}
I'm on 100% sure there exists edge case that it may fault
But better this then fighting with OS
doesn't inputsystem already have this
@elder pine have you tried these?
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.18/api/UnityEngine.InputSystem.InputBinding.html#UnityEngine_InputSystem_InputBinding_ToDisplayString_UnityEngine_InputSystem_InputBinding_DisplayStringOptions_UnityEngine_InputSystem_InputControl_
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.18/api/UnityEngine.InputSystem.InputActionRebindingExtensions.html#UnityEngine_InputSystem_InputActionRebindingExtensions_GetBindingDisplayString_UnityEngine_InputSystem_InputAction_System_Int32_UnityEngine_InputSystem_InputBinding_DisplayStringOptions_
if the anchors don't work, it's the displaystring methods
huh you did say you were using this before?
Are you using Windows or Linux?
Technically true. Mac's are unix based.
I would love to know
This was the output when I used GetBindingDisplayString
(confirmed, btw. GetBindingDisplayString eventually uses ToDisplayString)
this isn't relevant btw.
it seems like there are some stray invisible/corrupted characters there after the displayname, if you could log out their charcodes that could help debug the issue
(though if using ToDisplayString directly doesn't have an issue you could absolutely just go with that and not worry about it)
Yeah, probably I will do it
I have other tasks to do
But thanks for that method
You are a life saviour
Figuring out how to write a unit test for testing input took a while. Either google's AI was giving me a hallucinated result or I mistakenly thought for some reason yesterday that it was telling me to have "using UnityEngine.InputSystem.TestFramework" to use the Press() method....turned out I should have been inheriting from InputTestFixture...
It also took me a while to figure out how to get a ButtonControl directly from an Input Action, so I don't have to know what button's are bound to the action. You do something like this: YourActionButton = [YourAction].controls.ToArray()[0] as ButtonControl and pass that into Press();
The examples typically test by calling Press(keyboard.spaceKey) or Press(gamepad.buttonSouth). But I think that makes a unit test pretty fragile. it'd fail when testing if the action was triggered just because you changed the binding to something else.
Now that I have figured that out I can finally actually get back to figuring out how to refactor the Unity Tank Tutorial's code to use the new input system....
Are there any best practices or typical solutions for handling multiple joysticks for the same player? Say I want to support a HOSAS (Hand-on-Stick-and-Stick) in the new input system. Each sticks is their own USB device, and such their own joystick device.
This would be generally handled in the control scheme
just by setting both joysticks as required devices in the scheme.
Although IDK how those particular devices are considered/identified in the input system
input system has only a very generic idea of what a joystick is. you often have to make a semi custom action map for the specific model you have, if you want to support multiple different models, you regularly need to make a custom driver for exactly those and map to a custom generic abstraction. but you can have mutliple ones by using the PlayerInput component and addressing them individually as a split-screen multiplayer input. Or you can ofc DIY that, player input can give you orientation. Generally there are no strong best practices for that kind of thing.
Hmm... I don't know which combination of joysticks the players will have. I plan to have Keyboard, Mouse and Gamepad as normal controllers, then controllers more generic with custom bindings so players with crazy joystick setups can configure it themselves. There is only 1 player on the same computer.
For example, I know someone who has a flight setup with 8 controllers and who could then configure 2-3 controllers for use in my game.
generally, if you want to support joysticks (more than axis + 2 buttons), that joystick support is a whole project onto itself
rewired (asset built on top of input system) can help with that joystick support
Can't use rewired sadly. OpenXR requires the new input system. Using both causes mouse clicks to no longer be reliably registered in rewired
You will/may probably have to build your own device - to - player mapping layer
for a game like this, your players would demand such a system anyway I believe
at the end of the day joystick support is nothing magical, it mostly boils down to button and axis mapping, which all report as weird names which you have to know so you can map them properly to your action maps without the user having to do it all manual.
I think the main issue you're going to run into is a binding disambiguation problem. If Unity's input system sees all of these devices as just "joystick" then binding something to "Joystick/Button1" for example will be ambiguous between all Joystick devices
Yes, I trying to tackle the binding disambiguation problem atm. My current thought is to use the joystick.deviceId to add new bindings and then prioritize them.
Thank you for your answers. Was help
This may be helpful:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.18/manual/ActionBindings.html#choose-which-devices-to-use
But seems to imply that different actions need to be in separate action maps to be properly disambiguated between devices?
Basically... I'm wondering if the Actions abstraction provided by the input system makes this impossible and you might have to make your code actually manually read input from different devices
which would kind of suck
e.g.
void Start() {
// Assume devices were paired in the order: Left, then Right
// The 'user' property holds the list of all hardware assigned to this player
var devices = _playerInput.user.pairedDevices;
if (devices.Count >= 2) {
_leftDevice = devices[0];
_rightDevice = devices[1];
}
}
void Update() {
if (_leftDevice is Joystick leftJoy) {
Vector2 leftInput = leftJoy.stick.ReadValue();
// Apply Left Track movement...
}
if (_rightDevice is Joystick rightJoy) {
Vector2 rightInput = rightJoy.stick.ReadValue();
// Apply Right Track movement...
}
}```
Looks like I can use inputAction.PerformInteractiveRebinding with only completing the action when the right device is selected.
.OnPotentialMatch(operation =>
{
if (operation.selectedControl.device == targetJoystick)
{
operation.Complete();
else
{
operation.Reset();
}
}
ah yeah that might do it
I'm using Unity 6000.3.6f1 and Input System 1.18.0. When I modify an existing Action or add a new ActionMap to an InputActionAsset and click Save Project, the asset is not dirtied and no changes are reflected.
Save project or save asset?
Save asset is not available in the Project Settings.
correct
Save Asset is a button in the Input Action Asset window
would new input system be suitable for something similar to goat sim? or should I stick to old?
main features:
-enable/disable ragdoll
-attack npc, enable their ragdoll/ send them flying
from what I understand I can do the first feature, but second I'm not sure
the new input system can and should be used for any kind of game involving input from a player.
the features you're discussing have almost nothing to do with input processing itself
the input system is nearly a superset of the old system, save for built-in axis smoothing afaik
ah I mixed up with something else then, thank you very much š
Does anyone know how to fix this? I got a PlayerController script from youtube and I tried adding SmoothDamp and making forward relative to the main camera rotation but now I have this bug where it ignores the SmoothDamp and holds the key for a bit longer after I let go before it stops without using SmoothDamp. I tried using AI to help but it didnt help me fix it.
!input
How to Set Input
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
⢠Input Manager (Old): Use the original Input settings.
⢠Input System Package (New): Uses the new input system package.
⢠Both: Use both systems.
also yeah don't use AI at this stage in learning lmao
Posting code
š Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
š Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
it's because you're doing smoothdamp and then normalizing the result of the smoothdamp
so now instead of having a smooth slowdown, you just get full speed until smoothdamp finally reduces you to 0
normalization always sets the magnitude to 1
So you have something like this happening:
Smoothed Actual (normalized)
1 1
.8 1
.6 1
.4 1
.2 1
0 0```
Oh i see
It works perfectly now thanks
its really hard for me to understand movement
Vectors confuses me
It's one of those things that requires spatial reasoning and spatial reasoning is one of those things that some people are just good or not good at
But with practice it should get better
ahh alr
I'm a beginner in Unity, and I had an old movement system. It uses the old input system, which is deprecated. I plan to make a large project that will last 1-2 years, so should I rework the movement system right now to move to the new system? Or is it okay to stick to my old system.
It's probably fine to stick with the old
Is there a way to detect if the player hasn't done any actions or inputs?
{
idleCount = (!hasMovedMouse && directionVector == Vector2.zero && !pressedJump && pressedMouse) ? Mathf.Min(idleCount + Time.deltaTime, idleTime) : 0;
isIdle = idleCount >= idleTime;
}```
I'm currently using this custom code to detect if any actions werent taken in a certain time, and I was wondering if there is a better way to do it without having to add a new condition every time I add a new action
you could iterate over all the input actions in your input action asset and make sure none of them had any input this frame
Or if you're using PlayerInput you could use C# events mode and subscribe to the onActionTriggered event
But the iterate over all actions thing could be as simple as:
private bool CheckForActiveInput(InputActionAsset asset) {
foreach (InputAction action in asset) {
// IsPressed() is true if a button is held or an axis value is non-zero
if (action.IsPressed()) {
return true;
}
}
return false;
}```
@sean_patrick015 muted
Reason: Too many messages in multiple channels
Duration: 29 minutes and 57 seconds
IsPressed checks if the value is above the pressPoint, not sure that would work for axes?
especially going negative
It should IIRC but if not an alternative could be formulated
i have this binding which enables a bool InteractPressed if performed. i set a really high deadzone for it just to test if the deadzone worked. even if i very lightly press up on the stick, InteractPressed is set to true. is this intended?? i figured action.performed would only run if the binding was past the deadzone
is this a value type action?
it seems like it may make more sense to be a button type action, and then set a pressPoint
this seems to work as i desired! thanks :]
per the docs, if a composite vector is set to Digital or DigitalNormalized, each value is set to 1 or 0 depending on if the stick is greater or less than the press point.
i set the press point to 1.1 (which, im pretty sure is impossible to reach on a stick as the maximum is 1) but im still getting outputs as if there was no press point at all. if i very lightly push the stick, it registers a non-zero vector
The press only interaction isn't really designed for non-button actions
Hmm. Does that mean there exists a button which can be used in a digital/analogue composite vector? I don't understand why the docs would mention this if it couldn't be used on sticks
Or is there some other way to access the press point for this purpose that doesn't require the press interaction
I used the rebind sample to add keyrebinding and I adjusted the script to save and load the key but its inside the script and the loading only happens if you open the menu. Is there a way where i can get reference to the rebindUI script so I can just call the loading stuff when the game loads as I don't want to in the same frame at the start open and close the settings menu on that page?
https://paste.myst.rs/w78sytyr this is the script with my changes
a powerful website for storing and sharing text and code snippets. completely free and open source.
What are you trying to accomplish here?
I basically want the stick to register 0 while in the deadzone and then 1 while out of the deadzone
I've done it via code but I was hoping the input system itself would have that functionality
Hello i'm sry to bother you but i have a small prob. I tried to use a key to use a spel on my project and i told on it to only be used during the press and not the press and the release. Then i send event on my Playmaker state but it still send it twice, on during press and one during release do you know why?
Press Only means it'll be "performed" only on press
with callbacks, you get events telling you when actions are started, performed, canceled, with a field on the CallbackContext telling you which one happened
Ah ok thanks you !
goys
i got this issue
The new unity input system is not reading the mouse delta in a windows build for some reason
im calling the readvalue in update
Change the new input system to old or change it to both.
I answered your question already in the other channel:
#š»ācode-beginner message
would someone be able to help with this?
im trying to make controller work on a pause menu but its not working. I was following a tutorial and this error happened
What is InputManager in the tutorial?
That's not a built in Unity type
so it would be something from the tutorial
i figured it out but thanks
I was researching how the input system works and came across a reddit post where someone said this. Why would you not move the character inside of the OnMove method? that's what i've been doing so far and it seems to work fine š¤·āāļø
or maybe i h avent and im dumb
Because OnMove only runs when the move input actuation changes.
What is the approach when input must be contextual? For example, a confirm for building placement will be a movement order in another context. Should I switch between maps for each context? Or I just need a lot of specific actions disregarding their wiring to buttons?
separate maps per context is a solid approach. you may want to look at "modal application design" principles as guidance on what works well and what doesn't.
mind that spearate action maps isn't the whole solution, you also need to build your systems in a way that separate maps actually work, and your modes need to enable/disable these maps consistently.
if you have a state machine somewhere that controls your modes or mode flow, maps will naturally slot into that
I have a controller with a single active mode at a time, but the idea was to switch them with an input and a valid condition.
I think having a single general "confirm" action that can do multiple things is fine for this example.
There are several ways to handle the context switching stuff
for example a state machine or maybe having the various contexts inject their action into the input listener with delegates
Having a single input listener sounds like a great idea! As of now, I construct each context with it's own set of actions and switch map OnEnter to make them active.
this is probably a dumb question, but is it possible to have two different input systems with the same action and the same keybinds? I'm trying to make it so that the camera moves with A and D but the player can only move with W and S. I put the camera under an empty object with a player input component. The camera works but the player isn't moving for some reason
wdym by "two different input systems"?
Did you have two PlayerInput components in the scene at once?
Each PlayerInput component is meant to be mapped to a single human player - and will take exclusive control of one set of input devices (as defined by your control schemes)
If you're not making a local multiplayer game, you should not be putting more than one PlayerInput in the scene
that must be the problem then, I have a player input on my camera and a player input on my player object. What's the alternative? I'd like to keep using the input system if possible, not the old input manager stuff. I need to be able to control two different objects. Is it ok to just use .Find() in the player object to find the camera and control it that way?
Sounds like you're still strugging a bit with unity basics
like referencing other scripts and calling methods on them
I would not recommend using Find, no
Just directly reference it
oh wait im dumb ofc
There is no reason to ever use the old input system
And just for your knowledge - the PlayerInput component is only one of many ways to use the new one
what are some other ways? thanks for the help lol
š«”
how do i create a player camera with the new input system
You're going to need to ask more specific questions if you want help around here.
Cameras have nothing to do with the input system
I have a weird bug where if I press the join action on my keyboard, the prefab is destroyed instantly. this doesnt happen in my controller mode though weirdly enough
Your keyboard join action key may also be bound to something else that is causing the destruction
its every key im trying, even ones i know arent being used
Well it's going to be something in your code
so find all the places you're destroying anything, and add logs to them
DESTROYED...
UnityEngine.MonoBehaviour:print (object)
PlayerInputController:OnDestroy () (at Assets/Scripts/PlayerInputController.cs:85)
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
this is the stack trace
looks like its getting destroyed by the input system?
it's being destroyed by you, from a method triggered by the input system
oh that's a message, whoops
This is just the OnDestroy yea
no, but i fixed it
the scheme i was trying to use had the mouse required, but i disabled the mlouse as a supported device
so i guess it just deletes itself
so i removed the mouse and it works
i have a horizontal layout group, and when i press control child size it just sets all the widths to 0. why could this be happening?
Is there anything in the children?
Control child size will essentially take over the children's sizes based on LayoutElement and/or Graphic components in the children
If they're just empty rect transforms I could see it making them 0
Try adding layout elements
CharacterSelections is the group, and CharacterSelection is the child
okay, turns out i have to force expand
You have two options:
- Force Expand to make them take up all available space
- Add Layout Elements to the children to determine how much space they should take up by setting up the Layout Element properties
I get the error InvalidOperationException: Cannot read value of type 'Vector2' from composite 'UnityEngine.InputSystem.Composites.AxisComposite' bound to action 'Player/Move[/Keyboard/a,/Keyboard/d]' (composite is a 'Int32' with value type 'float') when I Try to test out my 2D movement input
this is the Code:
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
public float movementSpeed = 10.5f;
private Rigidbody2D playerBody;
private Vector2 direction;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Awake()
{
playerBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
}
private void OnMove(InputValue pls)
{
direction = pls.Get<Vector2>();
Debug.Log(pls.ToString());
}
}
You configured the input action incorrectly if you want it to be read as a Vector2 in your code
looks like it's set up as a 1D axis
it is
Well if you want to be reading Vector2, that's wrong
what should I use instead?
It depends
what's your goal here?
do you want a 2D axis, or 1D?
If you want 2D - fix the input action
If you want 1D - fix the code
I do want 1D
but where in the code did I go wrong?
The part where you made your field a Vector2 and did Get<Vector2>()
A 1D axis will simply return a float
so replace Get<Vector2>() with Get<float>()?
Yes but also:
private Vector2 direction;```
with
```cs
private float direction;```
you probably want to be doing Debug.Log(direction) not pls.ToString() as well
Well it now gives me the values I want but the RigidBody wont move at all
Updated code:
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
public float movementSpeed = 10.5f;
private Rigidbody2D playerBody;
private float direction;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Awake()
{
playerBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
playerBody.angularVelocity = playerBody.position.x * direction * movementSpeed * Time.fixedDeltaTime;
}
public void OnMove(InputValue pls)
{
direction = pls.Get<float>();
Debug.Log(direction.ToString());
}
}
your code is setting angular velocity instead of linear velocity?
it's also...
oddly using the player's current x position as part of that?
likewise also oddly multiplying Time.fixedDeltaTime into it
there's a bunch of weird things here. But if the object is at x = 0 at the start here, it's definitely not going to do anything, not even rotate
since 0 times anything is 0
My suspicion is that what you actually want is:
playerBody.linearVelocityX = direction * movementSpeed;```
(double check that movementSpeed is not 0 in the inspector as well)
but when I try to use playerbody.linearvelocity.x it gives me the error that rigidbody2d.linearvelocity is not a variable
that's not what I wrote
Try what I wrote instead
How can I move an "On-screen stick" using the stick of a gamepad?
something i've noticed on the input system, if you try and spawn a player input using the player input manager, and you dont have the required devices available, it will spawn and then immediately delete the object silently. I feel like there should be a warning or error for this
doesn't that defeat the purpose of an on screen stick?
I'm having trouble with using virtual mouse, the pointers dont work. I know its not the issue with the UI elements, because if i add the mouse as a supported device, the hover stuff works fine. what am i missing here?
Only working with virtual mouses and pointers
Not sure I understand what you mean.
DO you mean creating a virtual cursor controlled by a phyisical joystick? Or do you mean making an onscreen joystick respond to a physical joystick?
The second
But it's late
I create my custom script to moving stick on screen using to phyisical joystick
Why would you ever want the second one?
I want create an application about "Testing the Gamecube controllers", so I needed moving sticks both
@austere grotto i've been making great strides in this virtual mouse business. as it turns out, I need to give each Virtual Mouse their own user specific input action reference. They were all using the global one, which meant everyone could control them. Another issue I had is that if there were 4 active UI Input modules but only 1 marker, that marker drove all 4 of them. If there were 2, Number 1 would only use the first UI Input module, but number 2 would have 2 3 and 4. as such i'm just disabling and enabling these as necessary
this took so long to figure out š
nice!!
now I know for the future
this shit is not for the weak
also when i click it seems to also instnatly click the button
but thats soemthing i will figure out tomorrow its too late lol
I don't understand why I can't get the input system to work.
It detects the key:
if (Keyboard.current.wKey.isPressed)
Debug.Log(āWWWWWā);
But it can't read from the input.
public class PlayerMovement : MonoBehaviour
{
PlayerInput playerInput;
InputAction moveAction;
void Start()
{
playerInput = GetComponent<PlayerInput>();
moveAction = playerInput.actions.FindAction(āMoveā);
if (moveAction != null)
moveAction.Enable();
}
void Update()
{
if (Keyboard.current.wKey.isPressed)
Debug.Log(āWWWWWā);
Move();
}
void Move()
{
Debug.Log(moveAction.ReadValue<Vector2>()); // always 0,0
}
}
show your console window when the game is playing
Can we also see how the individual bindings in the 2d vector composite are configured?
also show how your events are setup
well they simply aren't
but what they're doing in the code should still work ostensibly
always print 0,0
It was my first project, I wasn't afraid to delete it, so I deleted it and created a new one. I tried again and it worked.
Ok... it probably would have been easier to just figure out the issue here and fix it
Plus we would have learned something
Heyo, I've encountered a weird issue in the old input system, where it seems I can't properly combine modifier keys with numpad keys..? Namely, say I try to use Shift + Keypad8 (via Input.GetKey).
- with numlock turned on, Unity properly receives Shift being held down, but the moment I press Keypad8, GetKey on shift returns false, and returns true again once I release the num key
- with numlock off however, things behave as expected..? Except with numlock off, shouldn't the 8 behave as an UpArrow?
In both cases, UpArrow key isn't recognized as being held, and in both cases Keypad8 is being triggered correctly, the only issue is Shift not working alongside it, and only if numlock is on.
I have honestly no idea what causes this and didn't find anything on this. It doesn't seem like it should be like this, no?
Edit: Switching from Shift to Control fixes the issue and things behave properly with both numlock on or off, so I guess this is a non-issue now, but I still don't get why the weird behavior.
Possibly a hardware limitation on your keyboard
Try to test these key combinations in a tester like: https://keyboardtester.uk/ghostingTest.html
Find your keyboardās rollover limit and spot ghosting in real time. Free & no install.
Web-based tool for testing keyboard keys, as well as which key produces which character and level of key rollover.
is there a way to get devices and their values that aren't connected to a player input yet? I want to use the cumulative values of the sticks to control a marker
I don't think they would be connected to input actions just yet, though
there is, but honestly its much less intuitive than using the new input system
id highly reccomend connecting it to inputactions
I do connect them to input actions later on in the flow, I just wanted any to get the actions unconnected first if possible
how do you use the new input manager? i tried following with an official guide, but unity still was telling me that i'm using the old input manager in my code.
unity will say that if there's some usage of Input, even if you're also using the new system
so it may just be that
actually, there's quite a few warnings/errors that say something along those lines. i may be thinking of a different one. could you show the exact message you're getting?
oh, then it's the guide i was using is outdated/worng.
it told me to use "Input.GetKey("a")"
then how is the new input manager used?
thats definitely legacy input system
this is the new one
is it specifically 3d?
no
thanks
wassup ppl
Iām trying to create a movement system for my character, does anyone know any good tutorials out there?
(The game Iām working on is similar to games like Super Mario 64 or A Hat in Time)
!learn
:teacher: Unity Learn ā
Over 750 hours of free live and on-demand learning content for all levels of experience!
In this video, you will learn how to implement the new input system in Unity, as well as the mobile controls in your Unity project. This time, you will be configuring a 3D project, which is slightly different in terms of settings for the new input system. This video is the continuation of the 3D platformer tutorial series, which was paused in Ap...
quick google search
skimmed through it, seems okay
implement something for moving the camera around as well if you'd like
I have deleted the default Player input action map and created a new one called Board. Why is this not being updated to the actual asset visable on the right? I have pressed save and it does nothing. When I reimport the file my changes get removed and replaced by the old ones. How do I solve this?
Do you have auto import / auto aasset refresh disabled?
right click and reimport it
I'm not sure. Where can I find this setting?
Project Settings -> Asset Pipeline -> Auto refresh
(or maybe preferences, IDR)
Auto Refresh is enabled
When I right click > reimport then my changes get removed and replaced by the defaults.
wait
I know the issue
you're trying to edit it from the Project Settings -> Input System settings menu, since it's the project-wide actions asset
you should just open the asset directly and edit it there
It's buggy if you try to edit it from project settings for some reason
The edit button just opens the menu in the project settings.
double click the asset in the project window
here
After double clicking this new window opens, this window has my custom input, but I still dont see them on the right??
Oh I clicked save and now it works!
Thankss
BTW are you actually using the "project wide actions asset" thing?
That's only in use if your code is using InputSystem.actions somewhere
if you're not using it, you could consider removing the asset as the project-wide asset, and then you won't fall into this trap again
I use it by dragging some Input Action Reference into the inspector and then use them in code like click.action.performed += ctx => OnClick();
Then you're not using the project-wide actions feature.
Ahh ok
Hi! I have the new input system set up and now I'm trying to find a way to detect which kind of input the player is using so I can dynamically swap my button prompts (Xbox controller, Dual Sense, keyboard, etc.). Is there a resource for how to do this? Anything is greatly appreciated!
I believe there's an example of this in the input system samples:
https://github.com/Unity-Technologies/InputSystem/tree/develop/Assets/Samples/RebindingUI
GitHub
An efficient and versatile input system for Unity. - Unity-Technologies/InputSystem
(this is a sample for a rebinding UI but it also has icons for xbox and PS controller buttons etc so I think they do what you're talking about in here too somewhere)
thank you so much I'll check this out right now!
I just look up the exact InputBinding in a big dictionary.
I was going to say that I also used the current control scheme name, buuut
I don't :p
I have a bunch of IconSet SOs; each one tells me the sprites for a list of bindings
(i have multiple sprites because i've got colored/uncolored and outlined/filled icons)
I want to add 'Z' and 'Space' to the UI button click control.
I tried to do that by adding Z and Space to both the 'Click' and 'Submit' actions in the Input System settings (see attached image), as well as adding Enter to 'Click'.
(Note: Upon further testing, it seems that the keyboard button press is governed by 'Submit')
I expected all three keys to have the same effect, but only Enter seems to work. For example, I have a pause menu where the player can select an action (e.g. Restart Level) and then press it to reload the gameplay scene. However, it seems that only Enter works as intended, while Z and Space do nothing (i.e. they do not trigger the OnClick() action).
The EventSystem and Button components are not meaningfully modified from their default values, and the correct EventSystem object is linked to the buttons.
Detecting the actual input through something like the following code shows that the input action itself is correctly detected, and the problem is that the button does not recognize Z and Space.
InputAction pressAction;
InputSystem.actions.FindAction("Submit"); // Also tested for "Click"
if (pressAction.WasPressedThisFrame())
{
Debug.Log("button press control pressed"); // Correctly logged when pressing Z or Space.
}
Try opening the input action asset directly from the project window by double clicking on it instead of from the project settings window
Make sure the changes actually got saved there
it is indeed saved there
I found the issue
Apparently, the actions assets is set to whatever this is
I have no idea where it is on my project (it doesn't even show up when i press the circle thing) but apparently it does
no, i just changed it to the project settings version
iirc the circle selection menu will only show project assets, there's an eye icon that lets it show package assets as well
so uh I have a very simple problem with the new input system. I'm using Gamepad.current != null to check whether or not there is a controller connected. Even though there is no controller connected, it still detects one. What gives?
Have you tried any debugging? Like printing out any details about the gamepad?
Are you using on screen controls
no on screen controls and yes I tried debugging by using Gamepad.all.Count (it's 1) and the name, which yes is the name of the controller I'm using
from what I'm seeing it's because Unity keeps a record of registered controllers?
@amit013140 muted
Reason: Too many messages in multiple channels
Duration: 29 minutes and 57 seconds
The gamepad last used/connected by the player or null if there is no gamepad connected to the system.
Seems valid
I'd set some breakpoints in the input system itself to see where it goes wrong, and what it's detecting.
Good chance the OS is sending it the bogus gamepad, though
so you are using a controller? or you're not?
Thank you, that's probably it. It registered the controller when I connected it and kept it when I disconnected
public void OnGrab(InputValue value)
{
GrabIsPressed = value.isPressed;
}
So my GrabIsPressed isn't resetting, even if i have GrabIsPressed = false; after the value is being checked
how is Grab set up?
Like in the input action map?
yes
what type action is it, do you have any interactions
is this meant to be held down or pressed and immediately released
It is meant to be pressed down
so as a plain button action, it'll only be calling OnGrab when you initially press it
if you need a boolean of whether it's held down right now, add an interaction and set it to press & release
Okay thanks
If they're using SendMessages (judging by the InputValue, they are) it should be calling OnGrab on both press and release by default š¤
iirc no interaction is equivalent to press only, no?
no
the default is:
started/performed on press, canceled on release
is that not press only
Ah I see what you mean
Sorry, what's actually relevant is not the phases but how SendMessages works
no way, googling "unity input system" gives the first result as the latest version of input system
which if I understand sends it on both press and release - but maybe you're right maybe it only activates on performed š¤
i remember reading the decompiled code and it checked some specific stuff to decide whether or not to send the release message
and i'm fairly certain that's how it works because i'm using messages in my own code and for most button inputs i don't even receive the inputvalue
-# (referencing old code because i haven't actually written unity in quite a while)
yeah you might be right about this - it probably just proxies performed - meaning another way to fix this would be to set it to "Pass Through"
private void OnActionTriggered(InputAction.CallbackContext context)
{
switch (m_NotificationBehavior)
{
case PlayerNotifications.SendMessages:
{
InputAction action = context.action;
if (context.performed || (context.canceled && action.type == InputActionType.Value))
{
SendMessage(methodName, m_InputValueObject, SendMessageOptions.DontRequireReceiver);
}
break;
}
}
}
the logic is basically this
(a lot omitted but not rewritten)
I see so it would work for joysticks and axes but not buttons
I rarely use SendMessages so I guess my mental model here was wrong.
yeah hence a solution being to set press & release interactions, since that gives performed on both press and release
yep makes sense
Or changing the input action type to Pass Through which makes everything trigger performed
that's cool to know. i don't think i've ever touched passthrough
(though that could have side effects if it's an axis being used as a button like a shoulder trigger)
i work primarily with sendmessages and it wasn't very clear about behavior so i went to the internal code a lot lol
how can I lock a virtual mouse to the bounds of the screen?
I have these markers, but the player can just fly out of the screen
and I don't know how to make it so its always within bounds. i can clamp the position of the graphic, but not the actual input
What is this warning blabbering about?
I've got an issue with the virtual mouse, where its calling onpointerenter while its moving, but onpointerexit while it stays still. why might this be?
Also, I set my Player Input compoenent with Invoke Unity Events as the behavior, but I'm not seeing any of my actions available. Just device lost and stuff
Bruh restarting unity fixed the issue
Is it better to put my code in separate chunks and then run it in the fixed update, or put all of the code directly in the fixed update, and does it make a difference?
wdym by "chunks"?
I have an Input Asset, which contain two Input Maps
I would like to be able to enable and disable the input asset, and still have each input map keep its state.
Right now, enabling an input asset seems to automatically also enable all input maps within. Is there a workaround for this?
the simple fact is that there is no enabled/disabled state for the asset itself
Enable() and Disable() on the asset simply enables/disables all of the action maps (and actions) in it
Can you explain your use case?
I think you probably will just need to track the state yourself.
I have two input maps, Player and UI
When I restart a level, both should be disabled (to prevent sccidental input during screen transition)
When the screen transition is finished, UI needs to be enabled (so that the player can pause and exit if they wish), but Player needs to be disabled (so that inputs aren't registered before the player character enters the screen)
I did fix it by just enabling only UI when restarting the gameplay scene
(note: Player off and UI on is the default state in this context, as the player is assumed to be in the pause menu)
don't crosspost, ive answered you already
i asked wdym
you already asked somewhere else, and you've been answered already
what ok but i've been trynna fix it by finding out everything about action maps so im just asking it here
i told you what to check
ik
and what was the result
nothing
anyone know what thsi might be?
okay as it turns out I had a graphic on the marker with a raycast target still on it...
fixed now
I'm getting an IndexOutOfRangeException when I try to confirm a button, only when using controller.
IndexOutOfRangeException: Index was outside the bounds of the array.
UnityEngine.InputSystem.InputAction+CallbackContext.get_control () (at ./Library/PackageCache/com.unity.inputsystem@57d0e36f6123/InputSystem/Actions/InputAction.cs:2140)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.OnSubmitCancelCallback (UnityEngine.InputSystem.InputAction+CallbackContext context) (at ./Library/PackageCache/com.unity.inputsystem@57d0e36f6123/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:2262)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray1[System.Action1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at ./Library/PackageCache/com.unity.inputsystem@57d0e36f6123/InputSystem/Utilities/DelegateHelpers.cs:46)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
I'm not exactly an input system expert but nothing here looks particularly strange.
This is a button on a loading screen, so there could be something going on there, but I don't think we ever load or unload a control scheme.
IndexOutOfRangeException while executing 'performed' callbacks of 'In-Game UI/Affirm[/Keyboard/enter,/Keyboard/space,/Keyboard/numpadEnter,/XInputControllerWindows/buttonSouth]'
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
(the second error that contains the button name)
My game doesnāt support localization yet, Iām using custom sprite based fonts and they current only support english characters. When players with different keyboard layouts use our input rebinding menu, or are presented with tutorials that display inputs, players with different language keyboards are presented with localized strings for these inputs. More often than not this just ends up causing confusion, and for languages with non-English alphabets, the strings canāt be displayed at all. Is there a way to disable this localization? Even once the game is fully localized I canāt guarantee my fonts will be able to support every language.
That is definitely odd... Can you show how the Affirm action is set up?
How would you use the new input system in VS?
In VS?
Visual Studio?
The IDE you are using has no bearing on how you use the input system
Sorry Vs as in visual scripting
Is there no way to multiply each of these with a different value by default?
The gamepad is fine but the mouse (delta pointer) is too fast.
Currently using this:
Vector2 lookValue = lookAction.ReadValue<Vector2>();
or do i have to constantly ask which one of these it is and scale it in my code?
If so then how do I know which of these is currently being used?
I found it š Just add a Processor
I'll just point out that no matter what you're going to need to provide the player a menu option to adjust mouse sensitivity, because everyone has different mouse hardware and operating system settings.
Soon⢠as I don't have a menu even this will suffice until then
Is it just me or is switching to the "Invoke Unity Events" behavior bugged in Player Input? Every time I switch to it, I have to restart the editor to get access to the actions I set up.
Weird, why is it that when I set up a mouse control, my keyboard controls just... stop working?
And by stop working, I mean like even the start of their associated callbacks aren't even being reached
Oh, I guess I needed to make a custom control scheme? Kind of weird
An quick question
How can I debugging the rumble the controls?
Is there a specific windows?
keep in mind that one of these you have to multiply by deltatime (gamepad) and the other you do not (mouse)
hi, every time i close and re-open unity, the new input system window doesn't save my action maps and i have to re-add them every time. is there a way to fix this?
i'm using inupt system v1.19.0 and unity v6000.3.10f1
@vale barn do you need clarification on that, or...?
make sure you're saving your actions, i guess?
i can't find the save button š„² i'm spamming ctrl+s every time though but it's not doing anything
try double clicking the asset?
nvm i understand what u mean now
but then i still have to somehow know which one is currently being used which is annoying
Is this what you mean?
you should use processors so that all forms of input are either:
- an absolute change (use a processor on the joystick)
- a rate of change (use a processor on the mouse)
I prefer going to the former, because that's a multiplication by deltaTime
this prevents bad behavior if you get a zero-duration frame
(notably, the recorder package can cause this)
IIRC, Cinemachine comes with a "delta time" processor
I do not remember which way it goes though š
sorry for late reply, thx this works! (idk why this is hidden behind double-click
)
double click is just opening the asset
the window you had open earlier was accessing the asset indirectly, through options (and having it set as the default)
i c
so basically this was equivalent of opening up shadergraph or vfx graph or some other separate window
For some reason, PanCamera is not firing. It's the only callback that's not sending out a log or showing in-game action. Any ideas why?
Cab you show screenshots of how the action is configured and how any bindings are configured?
I figured out what the issue was... kind of. Didn't make much sense to me but here it is: the input asset had only one control scheme that I set up: keyboard and mouse. Removing it and leaving it on "No control schemes" makes it work now O.o
yep, I would have told you that if I saw it
control schemes are not necessary if you're not doing local multiplayer, and they add unneeded complexity
Ah okay. Good to know lol
Still a little confused on why specifically one action wasn't working though (and why the issue seemed to bounce to different actions when I was messing with other components and things)
My immediate assumption is that particular action or binding was not included in the control scheme.
Another possibility is that you had multiple valid devices plugged in and your PlayerInput component was picking up a different set of devices each time
that would be further exacerbated if you happen to have multiple PlayerInputs in the scene
Gotcha, I originally did in fact have multiple PlayerInputs. Not this time around, when I was posting the problem though, so it's probably the first few things you said
@deft berry If I don't have project-wide inputs enabled does that mean only one of the components will work?
consider reading the documentation for the component
oklemmecheck where i left it
it says here they will be disabled
they work fine ingame (currently, they're not assigned as project-wide) so im not really getting it
the PlayerInput component handles enabling/disabling actions so that isn't something you need to worry about when using it
- Boxfriend, 6 minutes ago
oh okay and what does that do for my script
like when triggering an event or does it do that
huh? i am purely referring to the actions being enabled by the PlayerInput component. i don't understand what you are asking here in relation to that
it doesn't do anything for your script
okay so i dont need to use that at all whenever im working on inputs?
use what? what specifically are you referring to here?
enabling/disabling actions
okay
For actions defined elsewhere, such as in an action asset not assigned as project-wide, or defined your own code, they begin in a disabled state, and you must enable them before they will respond to input.
this means specifically the ones i make at runtime?
no, that means input actions not set as the project-wide one. as i've pointed out the player input component is handling the enabling and disabling of your input actions so that is not something you need to worry about when using the player input component
you know, the component you specifically said you are using to manage your inputs
nah, not that i mean specifically input system
im not worried about player input just yet
that's even less clear
this is all part of the input system
that is an input actions asset
i mean the actions
what about them?
this
jesus christ
okay whatever moving on
if i get a problem i'll come back to discord and complain
and do you know where to find a description
of each of these
i was scourging api and couldnt find it
i mean, the api wouldn't show that. it's in the manual
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.19/manual/Pointers.html
okokthankyou
How can I check if any device is pressing / holding down a button?
like a certain action
Make an input action and bind it to a broad swathe of devices using input control paths: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.19/manual/Controls.html#control-paths
Then check if that action.IsPressed()
awesome, thank you! I thought it might be something like that
e.g. <Gamepad>/* will bind to all Gamepad buttons
you could bind it to like <Keyboard>/* and <Gamepad>/* and that will cover most things
yeah, basically I want to check if the "back" button (B, escape etc) has been held down for more than x seconds when player inputs have been made.
you would just have an action that uses the "back" input
or might be called "cancel"
there's one that handles the respective "cancel" buttons for various devices
I see, so I can have a script that checks if back is pressed and have the input action reference as a field?
i feel like you have it backwards
you would have the input action check that
and then the script just receives infoĀ from the input action
oh right, yeah that's what I mean
is there an event i can subscribe to for when a controller gets connected / disconnected?
My new input system is working fine, but there's a weird issue where my input manager doesn't detect a button being held down if it was held while loading into the scene. You have to release and then press again for it to register, which people reported to be an annoyance. One of the controls uses "WasPressedThisFrame" which yeah I understand why that wouldn't trigger, but even an action with "IsPressed" has this issue
I have to imagine this is a known thing but yeah was wondering if there was any insight into how that happens
iirc there's a checkbox in the input action for that?
You mean in here?
initial state check. But only for Button actions
this is a Value action
Is initial state check a function or something?
just a tad too slow š
It should
I havea virtual mouse. If I disable it's gameobject, and reenabled it, it acts as if 0,0 is in the middle of the screen, and not the bottom left as it was before. how can i fix this? (ignore the last 10 seconds of the vid thats me ttrying to turn the video off)
the arrows are the virtual mice
Hey shebb!, When you re enable the virtual mouse GameObject, Unity's Input System resets its state , including the cursor position , so it defaults to (0,0) which in screen space is the center. To fix this, after re-enabling the GameObject, manually warp the virtual mouse position back to where it was (or to your desired default) using VirtualMouseInput.cursorTransform.position or by calling InputState.Change(virtualMouse.position, yourDesiredScreenPos) in OnEnable
so it defaults to (0,0) which in screen space is the center.
do you have a source for this? according to docs,
Screen space is defined in pixels. The lower left pixel of the screen is (0,0). The upper right pixel of the screen is (screen width in pixels - 1, screen height in pixels - 1).
hey, im not sure about this because usually, it treats 0,0 as the buttom left. when I reenable it in the video, i physically cant go any further left or down than the center
also, cursorTransform is a RectTransform, i don't think you're supposed to change its position? or is this specific to the virtual mouse
Ah yes. you're right ,my bad on the (0,0) thing. Screen space (0,0) is indeed bottom left, not center. What's actually happening is that the VirtualMouseInput's internal device state resets to Vector2.zero on re enable, but the cursorTransform (which is a RectTransform) interprets (0,0) as its anchor point, which is likely set to the center of the screen. And also yeah, you shouldn't set cursorTransform.position directly. The correct fix is to use InputState.Change(virtualMouse.position, cachedScreenPos) right after re enabling, so the input device state is restored and the RectTransform follows naturally. Cache the device position before disabling, restore it in OnEnable
i gotta ask, is this from a chatbot
maybe i'm just tired but it kinda seems like it to me
Ngl I was thinking the same thing
Not sure though
Nooo, I'm using ai for translation lol. english is not my first lang.
Maybe this is why
Ah I see
this is the transform of the marker
it can go into the negatives normally but
when its reenabled it seems to be stuck at 0,0?
and it just literal translates it
can you try to cache the position before disabling and call InputState.Change(virtualMouse.position, cachedPos) in OnEnable to restore it
doing this mousePos = mouse.virtualMouse.position.ReadValue();
Now just call InputState.Change(mouse.virtualMouse.position, mousePos) in OnEnable after re enabling and it should restore the cursor to where it was
i already do this, the video shows the results of that
I thought you changed that. It was supposed to work.. can you re check everything?
Maybe VirtualMouseInput's own OnEnable is probably running after yours and overwriting the position back, i can't think of anything else :/
InputState.Change(mouse.virtualMouse.position, mousePos);
print("SET INPUT TO " + mouse.virtualMouse.position.ReadValue());
this is what it looks like when I print
i think it needs to save the position before the GameObject is disabled
save it before calling SetActive(false), not in OnDisable
i save the position way before i disable it
did you directly set the cursor's anchoredPosition to where it was before disabling?
im not setting the cursor's anchored pos anywhere, im just using the input system and letting the virtualMouseInput class handle the actual positioning
don't disable the GameObject , can you just hide the cursor image and ignore input?
in that way VirtualMouseInput never resets š¤
Yeah š
still does the same thing š
which is weird because i literally do this already and its fine
i'll debug some more
Okay! I hope you can solve it š
is it worth it to use the new input system? i'm a beginner and i find it much easier to find tutorials on the old input system
yes
what are the benefits
because it has all the features you typically need to finish a game. old input is not sufficient and you always had to build a custom wrapper.
if you just want to get input for a small thing, you can use the new system like the old one, e.g. Keyboard.current[Key.Space].wasPressedThisFrame, from there you can make a input action asset where you can define input bindings similar to the old system but with a lot more options. from that you can generate a class that gives you actual C# events to subscribe to and query, or you can use the PlayerInput component to give you generated unityEvents to hook into.
you can also go the proper route and reference an input action directly in a serialized field in a script. you can do rebinding, local multiplayer, and swap whole input schemes by just referencing a different config asset (if you set up your code that way)
the key thing to understand about InputSystem is the InputAction abstraction. If you think of input actions as buttons, you will have a miserable time with it.
this is the important part: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.2/manual/Actions.html
i've found it to be super pleasant to work with
It's quite complicated and the right way to use it isn't immediately obvious
there is that large start-up cost, yeah
But yeah, the old one is unshippable in some very common cases
I.E. supporting more than one gamepad, or rebinding
It lines up well with real-world input needs of games. I haven't used the old input system in a very long time, but I'd be sad to see it deprecated for how easily it lets people get up and running.
I'm not sure there's a good way to fix the up-front difficulty of the new input system, other than just telling people "use this one input method and don't even think about anything else"
Maybe a higher level API that sits on top of the new one would be a better answer for beginners
I find InputActionReference to be very easy to understand, but you still have to turn on the actions at some point
i used to have a vestigial PlayerInput lying around strictly to do that
It's useful that you can disable the old input system. Perhaps a high-level API could be kept in with strict warnings that it shouldn't be used in production games?
(now I explicitly turn each map on and off, so PlayerInput is gone)
However, force bindings for EventSystem using the new system?
Or just do the Unreal thing and provide a set of templates
So all you have to do is hook into "movement" or whatnot
The default input action asset does cover a decent number of bases.
okay but one thing it really needs to sort out is mouse vs. joystick input
you have to write a processor to scale one by deltaTime
well, by unscaledDeltaTime :p
i shouldn't have to do that
I mean, Input System pretty much does that much, about as exposed as C# interface bindings might let such a system be exposed.
Cinemachine comes with a processor for this, but I don't think the Input System package comes with one
are you talking about the "Generate C# Class" option on input action assets?
My first thought was on the generated class method of using it, yeah, but I guess "templates" using the system could be packaged in other ways, too.
Cinemachine is a great example for how input system controls can be plugged in, yes.
It's relatively contrived for someone just getting up and going, but in the sense that you can pass input actions as references to objects, it tracks.
I have this line of code at the start of this scene, enabling a global action for everyone to use.
back.action.Enable();
I use the player input manager to spawn in player inputs, but for some reason the first player that joins seems to hijack this action, and no one else can press it but them. When I remove all the player input users, it seems to work again. How can I fix this?
So full disclosure: I don't use any of Unity's own or built-in networking offerings, but I expect that if back.action is an InputAction that it would need to be enabled on every client expected to call it.
Like, if "spawn in player inputs" means that you're spawning an object for each player that commands input actions for those players... that might not be the best way to go about hooking up controls. I hope I understand what you mean here.
sorey, should clarify, this is for a local multiplayer game
so I'm not doing any networking stuff
Player input manager is for local input
Okay, got it. No spawning objects over a network for secondary callback setups or whatnot lol.
Well, my first thought is about the action <=> bindings relationship. back.action.Enable() should enable the action for everyone if there is only the one action. The question then becomes what all is bound to it, which isn't exactly player-owned.
You should be able to check back.action.bindings[] to see what exists there.
How are you setting callbacks for the action? I'm wondering if you're writing over instead of adding to an event or something.
Hello, I'm trying to get raycasting to work with the new input system, currently I'm trying to get the name of an object the raycast hits, with the raycast appearing from the spot where the player touches. The method I was using on an older version was:
if(Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hit
}
Then I get hit.transform.name and use that string. Issue is this isn't working on unity 6 and I'm guessing it has to do with the new input system, but I'm not sure. To be clear this is for an AR app on android.
hi!
public void Fire(InputAction.CallbackContext context)
{
if(context.started)
{
// Code to run
}
}
is there a better way, w the new input system, to run code only when the button is pressed? if i take off the context.started check, it runs 3 times, once for press, once for held, and once for released, & i only want it to run when pressed.
Hey everyone. I'm the sole linux guy on some school projects, and we've noticed weird idiosyncrasies with controller support. Essentially, the game and builds all work fine on windows, but the control layout gets all confused on linux.
I was able to address some of that by launching it through steam, however we have a ready up canvas panel that is just "press A to ready up" and it won't trigger. The A button works fine in all other menus, and it even supports switch pro controllers as well as Xbox correctly. A button means A button.
Any ideas?
there are many ways of using the new input system, i tested a few of them, the easiest in my opinion is to use PlayerInput
[SerializeField] PlayerInput myPlayerInput; //add this component to you object and assign it
InputAction fireAction;
void Start()
{
fireAction = myPlayerInput.actions["Player/Fire"];
}
void Update()
{
if (fireAction.IsPressed()) Debug.Log("Button pressed");
}
if you're going to do this why not just use inputactionreferences
to avoid the magic strings
explain
-[SerializeField] PlayerInput myPlayerInput; //add this component to you object and assign it
-InputAction fireAction;
+InputActionReference fireActionRef; // assign in inspector
void Start()
{
- fireAction = myPlayerInput.actions["Player/Fire"];
+ fireActionRef.action.Enable() // or enabled in some other way
}
void Update()
{
- if (fireAction.IsPressed()) Debug.Log("Button pressed");
+ if (fireActionRef.action.IsPressed()) Debug.Log("Button pressed");
}
works too, yeah i mean if you want to avoid using string by any means sure
i don't think using a playerinput just to retrieve and automatically enable inputactions really makes sense
you can do practically the same thing just assigning inputactionassets
(and you don't have to manually enable it if it's the default/global input actions asset, i don't remember what it's called)
as i said many ways of doing this. didn“t even know InputActionReference was a thing
yeah just saying i don't think this is easiest
it's got an amount of indirection there
sorry if that came off as argumentative, i read it as trying to showcase the easiest way you found and i saw ways to make it easier
or at least simpler, to further that goal
all fine mate, i learnt something new
I apologize if this is a common question, but what is the project-wide actions asset used for? In the tutorials I've done, I just attached it to the PlayerInput component but that gives me a warning. The documentation says that "most projects only ever need a single action asset" which implies that I should be using the project-wide action asset that was created with the project. But again, that causes the warning. Also, the action asset already has an action map for the player, which makes me more confused. Why does the project-wide actions asset have a player map, if I'm not supposed to use it with the PlayerInput component?
so generally you'll want to have a input actions asset somewhere, so you can use input actions.
making it the project-wide asset means the asset enabled automatically.
using it in a playerinput means the playerinput enables the asset automatically.
so that's what the warning is about - "if it's used in a playerinput, no need to have it as the project-wide actions. you have access via the playerinput, and it's enabled for you."
The documentation says that "most projects only ever need a single action asset" which implies that I should be using the project-wide action asset that was created with the project.
i don't think that's what it implies
the default asset is a nice starting point for beginners, but i don't think it's ideal
It's for being able to access it like this in your code:
InputSystem.actions```
good explanation, thank you
when I was doing my tutorials, I used functions like "OnMove" or "OnJump", whats the difference between using InputSystem.actions and using those functions?
they're different ways to receive input
well, InputSystem.actions isn't a way to receive input. it's just a way to access an inputactionsasset, just like playerInput.actions
The difference is you use those functions and the PlayerInput component instead of accessing the asset through InputSystem.actions
I remember seeing somewhere that you aren't supposed to handle the actual operations of the object inside of the OnMove, etc functions. Is that true? Why would that be? The way I saw it done was they adjust a float value based on the input and then move it in Update by using Translate and multiplying a vector based off the float.
Also, is it best practice to handle input actions (or the results of input actions i guess?) inside of Update? It feels like after a while Update would get very big and things would slow down because its running a million if statements every frame
Handle the actual operations of what object
The way I saw it done was they adjust a float value based on the input and then move it in Update by using Translate and multiplying a vector based off the float.
If they are doing movement that needs to run every frame, they used Update. Update runs every frame. That's why they used Update.
Also, is it best practice to handle input actions (or the results of input actions i guess?) inside of Update?
It depends exactly which input you are handling
If it's some kind of "continuous" input handling like a joystick for movement, Update makes a lot of sense. If it's a button press, update makes less sense and event-based input handling might be a good idea. But you can still use traditional polling style input handling either way if you wish.
What's important is you understand what your code is doing, when, and why.
what exactly do you mean by event based input handling? do you mean just moving inside of the OnMove function?
not just that
What you're describing is one form of event based input handling yes
the new input system supports many different workflows
What you're describing is using the PlayerInput component in Send Messages/Broadcast Messages mode. It is indeed one example of event based input handling but not the only way to do it, and not even the only way to do it with the PlayerInput component.
I followed along a tutorial and got my player input set up + wrote the script but it doesn't move and I'm not sure why if anyone has any ideas or leads for me on what to look into, the playerInputs move action is set to value and 2d
I'm confused
why do you have your PlayerInput component in Send Messages mode and then your code is instead manually trying to read the data?
Anyway - you need to keep your Console window visible at all times
make sure there are no errors in your console when you play
not seeing any errors and I'm not sure why its in send messages mode, I didn't change anything about the behavior after creation
Created it just by pressing "create actions" after I added the player input in
The PlayerInput component is what I'm talking about
Start debugging your code
A few simple log lines and we can see what isn't working here exactly
Hey all, i've been trying to add MIDI input to my project using keijiro's Minis MIDI Input extension, but it seems like Unity doesn't recognize my device. Windows itself does recognize it because i can find my device in the "device management" tab of windows. Yet when i try to Listen to key presses or look for any sign of my device in Unity i don't see anything. I realize this is probably quite a niche question but i'm hoping for a helping hand as i'm quite stuck.
I have this mouse hovering over an image, and IPointerExit fires but Enter doesn't. How could this be possible?
fixed it by changing the player root of the event system
how can I perform an interactive rebind with local multiplayer?
the way i have it now, if one controller starts an interactive rebind, the other controllers can interrupt that rebind with their own presses
currentRebind = action.PerformInteractiveRebinding(bindingIndex)
.WithControlsExcluding("Mouse/position")
.WithCancelingThrough("<Keyboard>/escape")
.WithExpectedControlType("Button")
.OnMatchWaitForAnother(0.1f)
.OnComplete(op =>
{
action.Enable();
currentRebind.Dispose();
currentRebind = null;
if (SequenceActivated)
{
BindCompleted.Invoke();
}
KeybindName.text = PlayerInputAction.name;
KeybindValue.text = InputBindingName;
Debug.Log($"Rebind complete! New binding: {GetCurrentBinding()}");
panel.isRebinding = false;
})
.OnCancel(op =>
{
action.Enable();
currentRebind.Dispose();
currentRebind = null;
if (!SequenceActivated)
{
action.ApplyBindingOverride("");
}
else
{
CancelSequence.Invoke();
}
KeybindName.text = PlayerInputAction.name;
KeybindValue.text = InputBindingName;
panel.isRebinding = false;
Debug.Log("Rebind cancelled.");
});
this is my current code
Add an OnPotentialMatch callback to the rebinding operation
e.g.
.OnPotentialMatch(operation => {
var device = operation.selectedControl.device;
if (!playerInput.devices.Contains(device)) {
// If another player presses a button, ignore it
operation.RemoveCandidate(operation.selectedControl);
}
})```
I tried adding this, but I think it cancels the operation too?
lemme check
yeah this cancels the operation
i would like to keep the operation available
That sounds like a bug š¤
is it not meant to do that?
I'm curious
what happens if you take out the .OnMatchWaitForAnother(0.1f) call?
Still broken. when the input changes is when i use the intended controller, and when it doesnt change is when i use the other one.
Instead of OnPotentialMatch maybe this?
string devicePaths = "";
foreach (var device in playerInput.devices) {
if (devicePaths != "") {
devicePaths += ",";
}
devicePaths += device.path + "/*";
}
var rebindOperation = actionToRebind.PerformInteractiveRebinding()
.WithControlsHavingToMatchPath(devicePaths)```
now it just works on both controllers š its weird because there are distinct controller names
does the order of the edxtension methods matter at all?
ugh - i guess both controllers have the same name so using the device path doesn't distinguish them
oh wait they don't though š¤
XInputControllerWindows and XInputControllerWindows1
so that should work I thought
thats what im thinking. this is my full script if you want to check it out, not sure if anything else im doing might interfere
https://pastecode.io/s/35r2xcea
hey guys
running into a bug with my playtesting where people with a virtual joystick program (e.g. vJoy) installed are getting phantom input
even when the joystick is unpluged
is there a way to tell unit to ignore this?
Sounds like a vJoy problem.
But you could probably just install vJoy yourself, figure out what the devices are named, and write some code to ignore that device.
i have big issue. using generated input class. And rebinding from new input system samples. Found this forum "https://discussions.unity.com/t/rebind-not-working/788889/2"
what actual issue are you having?
because im using generated c# input class. It doesnt apply rebind
Sure it does, as long as you apply the rebind to the actual instance you are using
yeah, but rebind is in menu scene and input class made from generated is in game scene
you need to manage a single instance across those if you want to preserve the rebinds, or serialize them and reapply
okay, thanks
Should i change rebind code to pull out action from singleton with reference to input instance?
I made my game twice as complex with adding generated class
adopted a similar approach, just configured the game to ignore any input outside of Gamepad, Keyboard & Mouse from the project settings
big thanks
can i somehow make it scriptableobject and pass reference of scriptables to rebinder?
Yes that's a very common pattern
Sure, that's also possible but less useful IMO.
Another question, why rebinding doesnt detect keys like "Esc"
that's for cancelling rebinding, by default
should the UI for the new input system be a separate input asset and not a ActionMap in the main input asset?
moreover, what could cause the right button held from mouse to not affect cinemachine anymore?
Can you try to rephrase your first question? I read it like three times and I don't understand what you're asking.
i understood it to mean whether input actions for UI should be a separate asset vs a separate action map
For the vast majority of games you don't need to make your own custom input actions for UI