#🖱️┃input-system
1 messages · Page 25 of 1
Hello, I am doing a school project an on Unity XR application for the mobile, I have set up my XR environment with the AR session, XR origin and a simulated environment.
I would like to implement the strategies for handling touch-screen input, mainly single-tap for select, swipe rotate, pinch for resize.
The problem is that disabling the AR Input Manager breaks the surface recognition.
Does anyone know how I could attempt my own seprarate input manager while keeping the rest of the features intact?
Have you looked at the enhanced touch API?
No, can you explain in short what it allows? I will document on it separately if it's what I need
How do you find the correct InputControl for a InputDevice given a binding path such as "*/{Submit}" or "<Gamepad>/buttonSouth"?
Alright seems like InputControlPath.TryFindControl(inputDevice, bindingPath) was exactly what I needed
using UnityEngine;
public class MainMenu : MonoBehaviour
{
public Animator mainMenuBookHolder; // Animator for the book UI
public GameObject canvasInventory; // Reference to the Canvas that holds the menu
private bool isMenuOpen = false; // Track if the menu is open
void Start()
{
canvasInventory.SetActive(false); // Ensure the canvas is hidden initially
}
void Update()
{
// Listen for Escape key press to toggle menu
if (Input.GetKeyDown(KeyCode.V))
{
if (isMenuOpen)
{
CloseMenu(); // Close menu if it's open
}
else
{
OpenMenu(); // Open menu if it's closed
}
}
}
// Open menu with animation
public void OpenMenu()
{
canvasInventory.SetActive(true); // Show the canvas
mainMenuBookHolder.SetTrigger("OpenMenu"); // Trigger the "OpenBook" animation
isMenuOpen = true;
}
// Close menu with animation
public void CloseMenu()
{
mainMenuBookHolder.SetTrigger("CloseMenu"); // Trigger the "CloseBook" animation
isMenuOpen = false;
StartCoroutine(DisableCanvasAfterAnimation());
}
// Disable the canvas after the "CloseBook" animation finishes
private IEnumerator DisableCanvasAfterAnimation()
{
yield return new WaitForSeconds(1f);
canvasInventory.SetActive(false); // Hide the canvas
}
}```
i think it s not detecting my input i have no output errors
Debug.log to find out for sure
guys i'm having a problem with the new input system and cinemachine, i want to use the action map that i created for the mouse movement and i when i pause the game i disable the input so the camera is not moving, but the camera continues to move with my mouse when i disable the input, any ideas?
you'd have to show how you set everything up
for example how did you hook the input up to the camera?
And how did you "disable the input"?
the problem is you're not disabling the action maps on the correct instance of the input action asset
the input action reference on the axis controller refers to the asset itself in your assets folder
the one in your code refers to the new copy you created of the C# wrapper class with new()
how do you determine if the key was pressed once (GetKeyDown) in the new input system the Move works but it fires every frame
public void Fire(InputAction.CallbackContext callbackContext)
{
if(callbackContext......) <<
}
```` something like that
ah never mind it is performed
and now how do you get the getkey event
it only fires 2 times but not every frame
set a flag when it's pressed and clear that flag when it's released
it only fires 2 times when pressed and when released
yeah, and you can set something to 1/true when it's pressed and then set that variable back to 0/false when released
i get what you say but this is kind of tricky. why is there not a predefined soloution
because inputsystem is stateless, you have to keep track of the state yourself, and in doing so, you get a much cleaner state where it's clear what you're recording
with the old inputs, the state was internal to Input
granted, inputsystem isn't fully stateless, it still keeps track of like, hold duration for interactions, but you're the one driving
thanks.
to fire something every frame you would use Update
or a coroutine
It's a misconception people have that the new input system doesn't support polling input in Update
THe new input system supports both polling and event based input handling.
but the problem is that i am binding the Fire butotn to the Fire action,
i need to assign a method, no idea how to use it inside update
how are you doing this "binding"?
You mean you are using UnityEvents
instead of sendmessage event yes
this is for event based handling, yes. You have two main options:
- do what you're doing now and just set a bool:
bool isFiring = false;
public void Fire(InputAction.CallbackContext ctx)
{
if (ctx.started) isFiring = true;
else if (ctx.canceled) isFiring = false;
}
void Update() {
if (isFirting) DoSomething();
}
- Don't use the event-based handling at all. Just poll the InputAction directly in Update:
[SerializeField]
PlayerInput myPlayerInput; // assign this in the inspector
InputAction fireAction;
void Start() {
fireAction = myPlayerInput.actions["Player/Fire"]; // assuming your action map is called Player
}
void Update() {
if (fireAction.IsPressed()) DoSomething();
}```
with the 2. method i need to press the "generate class" or
no, that's another thing altogether
that would be to not use the PlayerInput component at all
oh boi what a mess 😉
why did unity decide to go for sucha user unfriendly method. i mean it requires so much testing nd trying aaround and of course reading docs and watching videos.
with the generate class thing you could get rid of the PlayerInput component entirely and just do this:
MyInputClass myInput; // assign this in the inspector
void Awake() {
myInput = new MyInputClass(); // the generated script, whatever you called it.
}
void OnEnable() {
myInput.Enable();
}
void OnDisable() {
myInput.Disable();
}
void Update() {
if (myInput.Player.Fire.IsPressed()) DoSomething();
}```
which approach do you use usually
It's not user unfriendly in my opinion.
What it is is a little more complex, and has a little higher learning curve.
In exchange for this complexity, the system is a hell of a lot more flexible, more compatible with actual use cases people have, more compatible with networking, testing, UI-based input, etc.
THe old system is really easy for a newbie to learn and make a prototype but when it comes to making a real production game, it's insufficient
yeah the cross plattform support is really superioir
It depends what kind of game i'm making
If you are making anything with local multiplayer, I stick to PlayerInputManager/PlayerInput, because it makes it way simpler to handle players/devices joining and leaving.
For anything else I usually use the generated C# class with a singleton input manager that manages a single instance of the generated class.
the singleton is not to do input handling in one place, it's juist to manage the instance
I let individual scripts get direct access to the single instance of the input class so they can choose to do event based or polling input as needed
ty Praetor i learnt something new 😉
seems to be by far the easiest and best method to use
so i need to set the input action reference to the input actions of my object, do you know any way i can solve this issue? because i'm trying right now different methods and i get some errors
ok forget about it, i fixed it, thank you!
Hello everyone,
I have a problem with new Input System acceleration.
I am creating simple 2D game on Android but when I am shaking phone it is not working.
When I am playing it in OLD input it works perfectly... but I have to many scripts related to new input and you can't choose both for android game...
this is code on which I am testing the acceleration.
using UnityEngine;
public class ShakeToVibrate : MonoBehaviour
{
// Sensitivity for shake detection
public float shakeThreshold = 2.5f;
// Time interval between shakes to avoid continuous triggering
public float shakeCooldown = 1.0f;
private float lastShakeTime = 0.0f;
void Update()
{
// Check if enough time has passed since the last shake
if (Time.time - lastShakeTime >= shakeCooldown)
{
// Check if a shake is detected
if (IsShakeDetected())
{
// Trigger the vibration
Handheld.Vibrate();
// Update the last shake time
lastShakeTime = Time.time;
Debug.Log("Shake detected! Vibrating...");
Destroy(gameObject);
}
}
}
bool IsShakeDetected()
{
// Get the current acceleration (device motion)
Vector3 acceleration = Input.acceleration;
// Calculate the magnitude of the acceleration vector
float accelerationMagnitude = acceleration.sqrMagnitude;
// Log the current acceleration magnitude for debugging
Debug.Log("Acceleration Magnitude: " + accelerationMagnitude);
// Check if the magnitude exceeds the threshold for a shake
return accelerationMagnitude >= shakeThreshold * shakeThreshold;
}
}
This code uses the old system
If you are set up to use the new system, this will not work.
You have to migrate the code to use the new system.
Can you help me how to do it?
Even my teacher form University is using the old input and have no idea how to fix it yet...
i fixed it
thx for help
I didn't enable the input on start...
can you poll inputs from a PlayerInput object?
You can poll from its InputActionAsset instance
Which you can grab with the .actions property on it
how do you do that? im current using inputs as a generated C# file, and doing this.
i need to have a list of "Input"s from different player input objects
If you're using the generated C# file, you are not using PlayerInput
those are two completely different workflows
how does the generated c# file work? from my usage it seems to just use all inputs from anything thats connected
example of polling "from a PlayerInput":
[SerializeField]
PlayerInput pi;
void Update() {
InputAction upAction = pi.actions["Play/Up"];
if (upAction.IsPressed()) // blah blah
}```
it's just a convenient wrapper file around the input action asset
and it makes a new instance of the asset when you new it
does this mean i have to make a new Action for every action in my asset?
so like 10?
which input does it bind to when its created though? like if i have two controllres connected
I have no idea what you mean by that
The appeal of PlayerInputManager/PlayerInput is to automatically handle binding individual players to input action instances.
If you aren't using those, you have to handle it yourself
This explains how that manual process can work: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.11/manual/UserManagement.html
will i have to do a new InputAction x = pi.actions for every one of these?
Up to you
If you want individual variables for them
is there a way to like
That's the thing the generated C# class conveniently does for you
i see
i dont feel like manually pairing actions with devices
so i'll just do it the long way
You can always just do pi.actions["Play/Up"].IsPressed() on demand
there's no requirement you make a variable for it
compare that with myActions.Play.Up.IsPressed() in the generated class
it gives you a little compile safety
is the string lookup not like inefficient or anything?
I'm sure there's overhead associated with it
like anything in the world
unlikely to be significant but you can always profile it
The record I have asked Unity for this feature which would/could give us the best of both worlds:
If you want it too you should give me a like/bump 😜
just liked 😉
why are these diabled?
i wasnt getting any inputs from the controller so i checked the debugger
and theyre all disabled
You probably need to call Enable() on the action asset
If you're not using default player input components
for camera control on the mouse, the path used to be called Delta [Mouse]
does anyone know the new path for the input system?
Nothing in the input system specifically deals with cameras
You could and still can create a binding for mouse delta
Nothing has changed there
If it's not showing up you probably didn't configure the action correctly
It needs to be Value/Vector2
is there no equiliant to GetAxis in the new input system. I only get the normalized value when using ReadValue so 1 or -1 but not the range as used before in the GetAxis
changed the option to analog on the playerinput map doesn´t work either
what are you expecting, exactly?
is GetAxis supposed to go over magnitude 1?
GetAxos included built in smoothing
There's no equivalent to that smoothing in the new system
It's extremely simple to write it though
It's literally just Mathf.MoveTowards in Update
allright thanks, was just wondering
Is using OnScreenControl with UI Toolkit still viable solution? Or there is alternative to?
Yes it's viable
I'm struggling a bit with an issue regarding the input system. I had a friend set it up for me, and I don't think I fully grasp how to work with it.
In my game, I switch between UI and Player action map, which is fine whenever there's UI enabled. However, I also have some "in game" UI that I want to be able to interact with on mouse button press while the Player action map is enabled.
I have made this button that "slides" in the inventory from the right on press, and slide it back out of the screen on another press. This only works once, since the game starts with both UI and Player action map enabled, for some reason. After that, it doesn't work
As you can see in this recording. I've put two squares on the screen. Top one shows green if Player action map is enabled, bottom one shows green if UI action map is enabled. How should I tackle this?
Can I make a button independent from the UI action map?
public class PanelSlider : MonoBehaviour
{
public RectTransform movablePanel;
public float slideDuration = 0.5f;
public InputActionAsset inputActionAsset;
private bool isPanelOpen = false;
private Coroutine slideCoroutine;
private InputActionMap playerActionMap;
private InputActionMap uiActionMap;
private Vector2 openPosition;
private Vector2 closedPosition;
private void Awake()
{
if (inputActionAsset != null)
{
playerActionMap = inputActionAsset.FindActionMap("Player");
uiActionMap = inputActionAsset.FindActionMap("UI");
}
openPosition = new Vector2(-movablePanel.rect.width / 2f, movablePanel.anchoredPosition.y);
closedPosition = new Vector2(movablePanel.rect.width / 2f, movablePanel.anchoredPosition.y);
}
// Method to be called by the button
public void TogglePanelPosition()
{
if (slideCoroutine != null)
{
StopCoroutine(slideCoroutine);
}
isPanelOpen = !isPanelOpen;
Vector2 endPosition = isPanelOpen ? openPosition : closedPosition;
slideCoroutine = StartCoroutine(SlidePanel(endPosition));
if (!isPanelOpen)
{
SwitchToPlayerInput();
}
else
{
SwitchToUIInput();
}
}
private IEnumerator SlidePanel(Vector2 endPosition)
{
Vector2 startPosition = movablePanel.anchoredPosition;
float elapsedTime = 0f;
while (elapsedTime < slideDuration)
{
movablePanel.anchoredPosition = Vector2.Lerp(startPosition, endPosition, elapsedTime / slideDuration);
elapsedTime += Time.deltaTime;
yield return null;
}
movablePanel.anchoredPosition = endPosition;
}
private void SwitchToUIInput()
{
playerActionMap?.Disable();
uiActionMap?.Enable();
}
private void SwitchToPlayerInput()
}
Here's the script for the button, if needed ( had to delete SwitchToPlayerInput() cause my message got too long).
Why not just leave the ui map enabled all the time?
Also is it really necessary to create your own UI action map instead of just using the default one on the input module?
I think I will try this
this game looks cool looing forward for your success.
Hey thank you, I appreciate it!
Your welcome.
Anyone know why tap gets negated if touch is held?
is there any easy way i could just accept the tap immediately
specifically talking about touchscreen controls
For anybody wondering in the future, theres a [press] input for touchscreen
for future reference "tap" specifically means a quick tap, without holding
do you happen to know what the input hierarchy looks like?
specifically which type of inputs fire before others
There's no hierarchy
how can i be sure that my press action will fire after touch position action?
as in I always need it to be UpdateTouchPosition => PressTouch when tapping the screen
Pretty sure its implicit so i shouldnt worry about it... was just curious
I would just be directly polling the touch position inside the press touch handler instead of using event based handling to update a variable
How do you access the touch position from inside the handler?
With a reference to the input action for touch position
What field do you access inside the input action?
Does press return you vector2 position??
No
Press is just for the press
You read the position from a separate action bound to the position
Right, but weren't you saying you wouldn't do this?
No
I specifically said I would do this
I said I wouldn't use event based handling for the position
how is reading the position from a seperate action not event based handling?
.performed is quite literally an event
Because we're not subscribing to performed
For the position
Only for the press
We're directly polling the value for the position action
Instead of subscribing to an event on it
How do you do that?
I just told you
Again, just told you
And that readvalue<> call would invoke the action?
I have no idea what you mean by invoking an action
It simply gets you the current touch position
Which is what we want
What are you reading a vector2 from bro 💀
Press doesn't return vector2 afaik, so we need to have two actions, click which reads touch/press and point which reads touch/position no?
I have said we need two actions the entire time, yea
Remember?
Ok what were you responding to when you said that?
It seems were in agreement
My question was whether not there was a way to ensure they invoked in that order, position, then click
But I said I'm pretty sure it's already implicit
As in position will always fire before press
I'm saying if you do it this way I'm describing it doesn't matter
All of the input values get updated before any of the events fire. So if we just read the position directly rather than from a variable we update with an event, we are guaranteed to get the most up to date value
When you say "A variable we update with an event" are you referring to this?
What would i have to do to this code to do it the way youre referring to, where you arent required to cache the position with an event?
ohhh i see, you can reference the data directly!
I thought you could only read from actions with the CallbackContext which is why i was confused
Makes sense
I do think unity has an implicit input hierarchy however, cause this method seems to work every time as well
Yeah I've been trying to say that the whole time!
Is it possible to set processor to on screen controls? Like add deadzone to on screen sticks
On Screen Controls act just like normal input devices. So you can bind them to input actions that have processors on them like any other device
But to be able to add processor you have to get InputAction reference while OnScreenControls works with string that is converted to InputControl using attribute.
I'm not sure I understand where the issue is
Are you trying to set this all up in code or something?
OnScreenControls works with string that is converted to InputControl using attribute.
Yes - and then you later bind that InputControl to an InputAction like any other control
I'm building stick control using ui toolkit.
I want to add deadzone to this on screen stick by assigning deadzone processor
I can't find a normal way to achieve my goal
You add the processor to the input action like normal
by double clicking on your InputActionsAsset
you can also add it to this specific binding
Let me try something
Or a binding
there's nothing special about doing this when using an on-screen control
Added UGUI on stick control and deadzone processor is working. Gonna debug my code. Thanks for help
alala input-system, what a thread xD
Hi ! I'm trying to get data from a virtual joystick ( image with On-Screen Stick component ), I well added the same control path as in my inputasset action, I can well move it but when I debug value it's always 0.. I have no errors :/
did you ever call elevationInput.Enable();?
I m using Unity 2022.3.47 with input system. and I noticed that if I put the ref to the module there it says I m not using same actionmap and ask me to fix it but after doing that all my UI are ded
nop !
Well, you need to
trying that now, thx
you don't need to do this unless you're doing local multiplayer
The code you showed a screenshot of does not use uunity events
It's completely unrelated from your PlayerInput component
with Enable() I still don't get anything else than 0 on debugging :/
You don't need PlayerInput if you plan on using InputActionReferences
Can you show how the Action itself is set up?>
Also it's only set up on the mobile control scheme
what do you mean by that ? in the input manager ?
yes that's exactly what I mean
that part looks ok
I suspect it's a control scheme issue
hmm I m using simulator and when I debug the left pad it s correctly receiving data
gonna show u
y and x well shared
the PlayerInput has a reference to the InputActionAsset. Something strange happens when I enter play-mode, and the InputActionAsset is named Inputs (clone) instead of jsut Inputs. When this happens it also stops detecting input.
This happened after a restart of the editor.
in play-mode I tried swapping the Inputs (clone) for my actual InputActionAsset in my assets - but to no avail. The inputs still didn't come through.
I've also checked the hierarchy, and found no conflicting InputActionAssets that could be interfering with the one in the scene.
The PlayerInput component creates its own personal clone of the InputActionAsset
Hmm - this isn't the same for all my projects though. I have another one where the game runs fine and detects inputs. Here it just says "Inputs" without "(clone)".
Maybe the fact that it says "clone" isn't the problem, but it started happening when the inputs no longer register.
It will depend on the control schemes you're using and the devices connected
as well as the number of PlayerInput components in the scene
(btw you should only have one such component in the scene unless you're doing local multiplayer)
Keyboard and mouse are connected. No controllers.
Yeah, I only have one PlayerInput component. I learnt this the hard way before :P
searched the entire hierarchy in play-mode. There's only one.
How can i change asset of this module via script ?
I am adding this component in runtime but when first run it finds default input asset reference in packages...etc etc
When i stop game and restart always give this error because its not reassign input asset reference anymore , how can i solve this issue or how can i set asset
InvalidOperationException: Action 'UI/Cancel[/Keyboard/escape]' must be part of an InputActionAsset in order to be able to create an InputActionReference for it
UnityEngine.InputSystem.InputActionReference.Set (UnityEngine.InputSystem.InputAction action) (at ./Library/PackageCache/com.unity.inputsystem/InputSystem/Actions/InputActionReference.cs:88)
Input System 1.11.2
Why are you adding it at runtime
I wanted to add it automatically instead of checking if it was in the Game scene
Instantiate it from a prefab instead of crafting it manually in code
@austere grotto Yes that's exactly what I thought there's no other way i guess , thanks 👍🏼
With the new inputsystem, it's possible to do InputSystem.DisableDevice(Keyboard.current).
Is there a way to do something similar but with a single key (or multiple) and without manually catching each input?
Or alternatively, only enabling a single input button with everything else disabled
Or maybe I can create a fake/virtual "Keyboard" that serves as a proxy, send all the key strokes to it, unless I disable that bridge
What's the end goal here??
Hi, I've just updated the Input System package, but I'm getting nothing but errors — a relaunch of Unity hasn't done anything, and I'm not sure what to do next. Any help would be greatly appreciated!
Upgrade Unity to the latest version, update all packages to the latest versions, and delete your library folder
Maybe just start with the library folder
Is it possible to ignore the system's touchpad natural scroll settings?
it feels quite jarring to scroll through the hotbar of my game when users have it enabled and scroll on the touchpad, at least if they're running Linux with Gnome like myself, in which case it seems to register as more or less a reverse scroll
I know an application should be able to ignore it since Minecraft does so
the question is if the new input system can do so
im using xr grab interactor but i need to disable the thumbstick to push it or pull it the object pls does somebody know how to disable it?
Has anyone else run into an issue where InputAction.IsPressed() returns true on initial button depress, but then flips to false even though the input debugger continues to show expected values?
Once it returns false, it stays "stuck" in that state, frequently until I change input modes to a different device and then back.
Specifically this is for a composite action that is mapped to Dpad / L stick / WASD.
Currently using Unity 6000.0.28f1 Input System 1.11.2
It will likely depend on how you set up the input action
Select it, then click it again and wait without moving your mouse
It will likely depend on how you set up
Doesn’t work
It just says <No Binding>
Hello, I want to have 3 different actions when the user holds, when they try to drag and when they click. Is there an easy way in the input system to determine what the user is doing? (holding, clicking or dragging?)
Hey, i have a game where there is a chat. Whenever the player types in the chatbox, the keys can still trigger movement and other things. Is there a way to disable inputs for everything else when writing in an input field?
Sure - disable the action map and/or or the script that does the movement when you're focusing the input field
I have quite a lot of scripts that have actions, would i need to disable all of them one by one or is there a better way?
As I mentioned, you can disable the action map
i didn't use an action map, i just used keycodes
if you're using the old input system your options are limited. You pretty much have to handle it manually
disable scripts, or have your scripts check a bool before doing the thing.
ok thanks
How do I unset UNITY_INPUT_SYSTEM_INPUT_MODULE_SCROLL_DELTA for the input module? This code is erroring on the latest unity version
#if UNITY_INPUT_SYSTEM_INPUT_MODULE_SCROLL_DELTA
const float kSmallestScrollDeltaPerTick = 0.00001f;
public override Vector2 ConvertPointerEventScrollDeltaToTicks(Vector2 scrollDelta)
{
if (Mathf.Abs(scrollDeltaPerTick) < kSmallestScrollDeltaPerTick)
return Vector2.zero;
return scrollDelta / scrollDeltaPerTick;
}
#endif
This code is erroring on the latest unity version
What error?
Can't find a suitable method to override
Show the actual full error
Library\PackageCache\com.unity.inputsystem\InputSystem\Plugins\UI\InputSystemUIInputModule.cs(2305,33): error CS0115: 'InputSystemUIInputModule.ConvertPointerEventScrollDeltaToTicks(Vector2)': no suitable method found to override
- try deleting your library folder
- make sure you're on the latest version of the input system
I think I figured out why? Seems like it needed the ugui package to be 3.0+, since it's actually defined there
Hi y'all I'm trying to figure out the new input system, and I have it set up so that every time you press the interact keys it calls a function that for now just displays something to the logs. I'm having issues, because whenever I click, it activates the function twice, and I was wondering if I was doing anything wrong. The code is here:
What you're doing wrong is simply not understanding.
This behavior is expected
ah
Add this to help understand what's happening:
Debug.Log($"Action phase is {context.phase}");```
Alright thank you, how can I get it to only trigger once the action is performed?
use an if statement
if (context.performed) // do something
Thank you
How can i use trigger this space action in mobile with ui button ?
If i use on screen button premade script it doesnt work .
And i write my main input reader like this , i want to share all events fields in one point.
And i dont use PlayerInput class also on my player.
I tried this class to extend but not worked onPointer events works well but input action doesnt triggering and my main InputReader not pressing that consumable pressed etc.
[AddComponentMenu("Project/In Game Button")]
public class InGameButton : OnScreenControl,IPointerDownHandler, IPointerUpHandler
{
protected override string controlPathInternal
{
get => m_ControlPath;
set => m_ControlPath = value;
}
[InputControl(layout = "Button")] [SerializeField] private string m_ControlPath;
public void OnPointerUp(PointerEventData eventData)
{
SendValueToControl(0.0f);
}
public void OnPointerDown(PointerEventData eventData)
{
SendValueToControl(1.0f);
}
}
On screen controls button is the way to go
There's no reason you need to write your own control
any idea how to make the On-Screen Stick "stay in place" after it's been let go?
it always resets the position, and I'm using it for rotation meaning it will always snap back to 0, 0, 0
anyone know how to disable the built in input manager in Unity 6? for some reason i cannot find the setting for it that was available prior to Unity 6
you can change the action name by clicking on the "New action", which is the current name
the bindings will be automatically set when you specify bindings, in the select menu labelled "Path"
oh thx
wait how do i delete a binding property
like the <No Binding>
you can delete it normally, just backspace/delete/rightclick, one of those should work
what is input actions even for
i dont have a headset and im testing out with the XR Device Simulator
because im using XR Device Simulator but im not able to move around
can you check if my file structure and everything looks fine
Its also not worked for me not triggered the event for the path that i give
Okay now its working i found i forgot to enable my actions ... but now it gives 3 log when i press with this setup
public class InGameButton : OnScreenControl,IPointerDownHandler, IPointerUpHandler
{
protected override string controlPathInternal
{
get => m_ControlPath;
set => m_ControlPath = value;
}
[InputControl(layout = "Button")] [SerializeField] private string m_ControlPath;
public void OnPointerUp(PointerEventData eventData)
{
SendValueToControl(0.0f);
}
public void OnPointerDown(PointerEventData eventData)
{
SendValueToControl(1.0f);
}
}
ok found again context include started canceled performed therefor i think 😄
Does anyone know a good way to implement Post Acceptance Delay to inputs? Basically if you double click twice within some timeframe it counts as only a single press
Conditions such as Parkinsons, essential tremor and cerebral palsy can reduce likelyhood of defined single presses, with slippage or shakiness common. This can result in unintended multiple presses, which can be a significant issue if interacting is already a drawn out process. If aiming for elderly or motor impaired players, including a simple ...
I'd rather not implement it manually on everything that uses it, so if there's a way to have a global processor that can handle it then that'd be cool
Looks like processors can be put on controls directly, which might be the best option... Question is if they're allowed to contain state or not
Huh, I managed to add a processor to an input action, but it doesn't actually do anything? Does subscribing to "performed" ignore processors?
Ah, looks like it doesn't use processors if there's no interactions on it. And that processors shouldn't have any state. But doing a custom interaction might be what I want instead.
interaction worked! guess I'll just have to apply it to all actions programmatically
Do you use some InputHandler component, which listens to input events and then distributes them? If you do, you can just hook into that and implement your timer(s) there, preventing distribution of input events when a cooldown timer is still active
Kind of, but not really
It would be ugly to put it there, with the way it's set up
maybe that's better than
guys why i can't use my game pad right stick to move the camera when i try detect the input of it in new input system it only detect Rz and z
Should I use the unity input actions or normal input detection inside the scripts?
I'm new to unity and I'm still trying to figure things out 😅
the input system is a lot more versatile and handles a lot of things for you (device changes, input mapping for different devices, actions and interactions, durations of presses needed etc). But if you really just want to play around and prototype something, the inline input queries are just fine, using Input.GetKeyDown() etc.
Im trying to get on the train of Using ScriptableObjects to handle input. But i have a big problem.. I cannot read what control scheme is curently active if i dont have a PlayerInput component. is there xome other way to read what control scheme is active..? or if you are using keyboard/mouse or gamepad?
What is the best method to do the following with the input system.
Movement input: WASD
Menu input: WASD
Only have one or the other action map active, one for gameplay and one for menus.
I want to use the same inputs to control menus when they come up on screen, could be inventory, pause menu, etc. I'm trying to use two ActionMaps, but cannot get anything to work. Reading it may have something to do with instancing, but SwitchCurrentActionMap and FindActionMap("actionmap").Disable() aren't working.
in input actions my action just says <No Binding>
when i double click on it, it doesn't let me rename it
how do i rename it
renaming is done by selecting it then clicking once and waiting a second
No binding means you haven't added any bindings to it
not related to its name
ok thx
For some reason the inputs that I get from the action inputs are different than the input debugger says :/
I have a Nintendo switch controller connected but the joy stick isn’t doing the right values
It works if I directly get the values from the game pad instead of using the input actions, but I know that’s not very scalable and not ideal
Is 2kb/frame of GC normal for just listening to input callbacks? Seems very high
looks like possibly your callback function?
Yeah looks like that was it! Was creating an InputAction for each one (forgot it was a class, not struct).
Separate issue but it's crazy how slow InputSystem.FindAction is when passing it a string - quickly fixed this by caching guids to string names of actions in a dictionary but seems very strange Unity doesn't do this by default, a single button lookup using nothing but the inbuilt function was taking 0.4% of frame time. Went from 0.68ms to 0.01ms after fixing it.
I doubt that's the input system's fault. That'll be the difference between the GetHashCode and Equals implementations of strings vs GUIDs
The old input system could get a button down with a string argument passed to it without this massive issue, so it's very silly IMO that the new one can't.
Why not just cache the InputAction reference though
I did - but users shouldn't need to write a caching system for the primary path of getting an input in a game engine, is my point.
Looking up actions by strings every frame isn't really the primary path of getting input though
Not with this system
Hey guys, what's up...?
Is there an equivalent to GetKeyDown...? I'm using Invoke Unity Events I think it's called
Something like this in my code
Because when I jump or wall jump, I can basically cheese it by jumping forever as long as I press and hold the button
I want it so that the player can only jump when they tap the button
Read the wasPressedThisFrame property which resets in the next frame and needs a button release to trigger again. (may be named slightly differently)
Can this work with the Invoke Unity Events behavior or should I switch the Input behavior to something else, like Send Messages...?
SendMessages makes it much harder
If you're using events like this you should not write the value to a bool
just do the jump thing inside the callback directly
That was actually what I had a month back and the jump was working
But it was weird having the code there because I thought I should move all the logic to update
Ok that makes sense, I'll redo it in the callback function, because it was much easier that way before
You need to make whatever event you need. You can also write that trigger bool to your stuct. Tweak the naming, design something that works for your problem. Input system is meant to adapt to your needs. You can do really whatever you want.
I guess it might be easier if I write the movement code directly inside of the Callback function...
The only problem with that is what if I need to call that method in Update for something
I tried that, that was one of the reasons why I tried moving all my movement code into their own seperate methods and put them in Update
the update method is way better in the long run, you decouple yourself from the concrete source and make an explicit statement what inputs are needed/expected, but for a quick project it might be too much boilerplate
Yeah I'm trying to make a platformer game, so maybe Update might be better...?
maybe, certainly helps with sequencing
I don't know, I joined Unity maybe two months back so all of this stuff is new to me
I don't know what behavior to use, whether to use Update or FixedUpdate, and all of those other confusing stuff
Then do t worry too much about getting it right, just keep your eyes open for options
Try another one next time
That is indeed confusing and a boilerplate recommendation won’t help. Best you understand the problem you have and why fixed/update exist, then pattern match your problem to the options the engine gives you
If Update is better...is there a way to store the CallbackContext as a variable so I can use WasPressedThisFrame() in the Update method...?
Wouldn’t recommend it but you can do it
What would you recommend is the best way...? I'm not sure how exactly to organize my code, especially with having those type of un-callable methods...
I’d just store the result of that method in the struct on event and reset it myself in update.., or some other way. There is really no best way.
Personally I prefer a component that only deals with input for a given system and writes an input-struct each update to the actual system component that implements the logic that needs input
that struct is minimal and only contains fields that system needs
I don’t like to have input directly call methods… but that’s probably just something i don’t do out of habit because it turned out to be the easiest thing in previous projects, but ymmv
Yeah true, I mean I could have used the older input system but I came across a YouTube recommendation where they talked about Unity's New Input System and why I should use it (since it's easier to deal with controller/keyboard and changing bindings I think)...
They all said it was easy but I still don't understand it to be honest
What's the best way to use Inovke Unity Events...?
Because I heard that using Invoke C# Events might be the worst one to use since it's overly complicated
And Send/Broadcast Messages are ok, but I don't know them too well
You gotta build so much stuff yourself with the old system and you end up with reinventing the wheel in a bad way each time
Don’t use those
They are going to make everything difficult
Because having methods for each input just specifying the buttons for every action is kind of tedious and wastes lines
Is there a better way to write it than this...?
best use send message only for debugging and ‚hacks‘
You can read all of them at once and store the values in a struct variable
if you want to use the events then you gotta type that boilerplate
So basically I can write all those boolean variables in one Input Callback function and maybe use that...?
as mentioned before, in a small project it’s usually fine to do your handling inside the event
You can do it in update
This is what I have in the Inspector
Oh, you are using your player input
Yeah that's how they taught me in the tutorial I watched a month or so back I think...
I find that component is extremely misleading
Is there a better way to do it than PlayerInput...?
playerinput is fine
it’s almost entirely unnecessary
everything's unnecessary if you don't want the easy way 🤷
the inputsystem is based on inputactions, unlike the old input module which just let you detect keypresses directly
the inputsystem still lets you do that but it's not exactly the intended way to get most of your input
inputactions are fed through playerinput, or through a generated class iirc? im not sure about that latter method
You should maybe not talk about what’s best if you don’t actually know
what do you think is best then?
Whatever solves the project‘s specific problem without causing problems later
right... and there's 2 routes to doing so, playerinput or the generated class
there are way more options than that
for example you can use input action references in the components that need the input.
anyways, playerinput is fine for the general case, so unless you have a good reason to choose something else specifically, you can use it just fine
Ok that works, thank you guys I appreciate you, I'll probably try reworking the code a bit
Hey yall, I’ve been using Unity’s old input system in my project, I think it’s referred to as Legacy now? Anyway, it works perfectly and I even set up custom key bind support with it (for keyboards). But the issue is, the old input system is very hard to use with controllers, as buttons seem to randomly map in different controller types. From what I’ve heard, the new Input System does not have these issues, but as I’ve already got everything set up perfectly for keyboards using the old Input System, are there any specific drawbacks to utilising both the old and new input systems in one project? (I want to use the new input system for controller support)
the drawback is that you can't
Is this not it? Not on my computer right now but I found this online
And I’m fairly sure I’ve tried it out in the past
i must be mistaken then, mb
in that case; the drawback would be that you have inconsistent input handling in your project, which may make maintainance harder.
Well if won’t significantly impact the game’s optimisation or storage requirements, I’m willing to work with it
i'd recommend eventually migrating to inputsystem though, it's generally regarded as a replacement rather than an alternative
Yea I would’ve started using it sooner if I had known about it. Just don’t wanna mess with the current keyboard input system in this project in particular since it works as intended.
Will definitely use it in a heartbeat for future projects tho
Can someone please explain to me why my player sometimes Jump when I press the Dash button. I can't understand why it keeps happening.
Is it dashing when you use the keyboard or the controller
Both when I Dash using controller and keyboard it goes to jump every now and then. More often when dashing on controller.
I also set each to false when ever I used them
Owhh I'm using a different method from the one you are using
You're not using Unity Event?
Not this?
Nope I didn't do it inside the input actions
and made an input manager instead
onFoot.Sprint.performed += sprintCtx => playerMovement.Sprint();
where this line will be called whenever the sprint key is pressed and released
then I have the sprint function that sets the value to true or false
public void Sprint()
{
isSprinting = !isSprinting;
}
Okay, hmm. I'll have to reconsider my input system maybe.
It's really weird how 2 different actions / buttons
can trigger the same function even when its not assigned to it in Unity Events.
yeah I'm not sure about that too
Maybe other ppl can help
Hmmm are you on the latest unity version?
My best guess: unity is triggering all the events or both of them at least, and since the check is on context started instead of performed, you end up in a race condition with no control over which executes first
The question becomes: if that is true, why is unity doing that?
If you are on the latest unity, I can try playing around with it and see if that happens to me too
Though, I usually do it the way xuann did it (using c# events)
for this specific project im using 2022.3.15f1
Installing 6000.0.22f1 now
thanks, Ill keep you updated.
I think Ill uninstall and reinstall the new input system once I got the new Unity version down
Sure, you can try that
Updating the Unity version solved it...at least what it seems like 🙂
perfect 😄
How can you have inputs only register once even when you hold them down for seconds at a time?
Im doing a pause menu and when you press esc, its registered multiple times such as 10, and if you hold it down for a second, its registered 900 times because of each frame.
Show the code that's responding to the input.
although, first: how are you receiving the input?
- A
PlayerInputcomponent? - A class you generated from your input action asset?
using UnityEngine;
using UnityEngine.InputSystem;
public class PauseMenu : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
public GameObject pauseMenu;
InputActionMap inputs;
void Start()
{
Cursor.visible = false;
inputs = InputSystem.actions.FindActionMap("PlayerControls");
pauseMenu.SetActive(false);
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
if (inputs.FindAction("Escape").ReadValue<float>() == 1)
{
if (!pauseMenu.activeSelf)
{
Time.timeScale = 0f;
//Freezes time ingame
pauseMenu.SetActive(true);
Cursor.visible = true;
}
else
{
Time.timeScale = 1.0f;
pauseMenu.SetActive(false);
Cursor.visible = false;
}
}
}
public void quit()
{
Application.Quit();
}
public void resume()
{
Time.timeScale = 1.0f;
pauseMenu.SetActive(false);
Cursor.visible = false;
}
}```
Okay, so you're directly talking to the input action here
yeah
if (inputs.FindAction("Escape").ReadValue<float>() == 1)
This is true as long as the "Escape" action is being pressed
which will flip-flop every frame
fortunately, you have...
WasPerformedThisFrame()
er, actually, go with
WasPressedThisFrame()
That's what you actually want
It won't matter unless you're using input processors for things like "press and hold"
You can also call IsPressed() to check if it's pressed at all
Also, here's an easier way to do this!
[SerializeField] InputActionReference pauseActionRef;
void FixedUpdate() {
if (pauseActionRef.action.WasPressedThisFrame()) {
// ...
}
}
InputActionReference lets you directly refer to a specific input action
Rather than fussing around with finding an action map and action by name
You can also use action.triggered.
how would I apply it to if (inputs.FindAction("Escape").ReadValue<float>() == 1)
use WasPressedThisFrame instead of ReadValue
inputs.FindAction("Escape").triggered
oh, that's nice
didn't know about that one!
but now I know where I got the idea that "triggered" was a phase like "performed" or "cancelled" :p
I consider it deprecated
InputAction had triggered before WasPerformed/Pressed/ReleasedThisFrame all were introduced
hello there
does anyone know a way to listen for input control scheme changes?
wdym?
nvm, found it
InputUser.onChange offers that
I have two questions, most likely they were asked many times before:
- Does input system support multi touch actions like pinch on WebGL?
- Is there a way to simulate pinch action on editor to test if code works?
Hi, nice to meet you.
I'm programming a remap menu with the new input system.
I learned how to do it with an input that has only one binding, but I don't know how to do it for a vector2 input that I use for movement.
My code is this one.
So what is the actual question here? You want to be able to make a 2D composite binding?
Or something else
I made a vector2 input, what I want to know is how to program a remap system in my script so the Player can remap that input.
You basically need to PerformInteractiveRebinding for each part of the composite individually. You target each bit with https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/api/UnityEngine.InputSystem.InputActionRebindingExtensions.RebindingOperation.html#UnityEngine_InputSystem_InputActionRebindingExtensions_RebindingOperation_WithTargetBinding_System_Int32_
They have a (recursive) example in the samples in the input system: https://github.com/Unity-Technologies/InputSystem/blob/cd53351875d52d1029c59685c41345b6f4446e5e/Assets/Samples/RebindingUI/RebindActionUI.cs#L243
An efficient and versatile input system for Unity. - Unity-Technologies/InputSystem
Thanks, I'll take a look at that and see if I can get it working.
Hello! I'm trying to make a platformer using the new input system, is it considered good practice to set flags like this for instantaneous actions, or is there a better way to do it?
This won't work properly
Update could run twice before a single FixedUpdate frame, and you will miss the jump
e.g.
Frame 1: FixedUpdate runs - jumpPressed is false, no jump
Frame 1: Update - triggered is true so jumpPressed becomes true
Frame 2: Update - triggered is false, so jumpPressed becomes false
Frame 3: FixedUpdate runs, and it sees jumpPressed is false, no jump
You need to do:
if (playerInputMap.Player.Jump.triggered) {
jumpPressed = true;
}```
or shortcut:
jumpPressed = jumpPressed || playerInputMap.Player.Jump.triggered;```
Thanks! Updated my code like this
from debugging it does look like it's more controlled
other than that though, is setting flags like this okay, or is there still a better way to do this?
I've seen some people who assign the action press itself into a context function
I mostly use callbacks for button-style events
it'll be more-or-less equivalent here
I don't know when callbacks run when compared to the Update loop
I tried using callbacks but had issues with FixedUpdate not being in sync with it
You'd be setting flags to true in the callbacks, just like you are doing in Update here
yeah figured I'd needed to do the same thing
still don't know if callbacks run on its own time sync or if it checks on the Update() frames
Whenever I add a new Action to the input system, I always get stuck on this iteration and this keeps going on forever. (Unity 6)
Oh that’s just a bool value I put in to toggle debugging
For the left/right move inputs
the conditional attribute is really neat
It completely omits the method call, including any expressions that are part of the call
OnlyInEditor(ThisCrashesTheGame());
This won't do anything in a build
Hey, so i have a third person character camera that is moving with cinemachine free look with this component, it works, but the sensitivity is too high and also the movement is very choppy and when I lower the gain value (which multiplies the speed of rotating the camera) it is no longer choppy, but the sensitivity is too low. How can i adjust the sensitivity without it being choppy?
also the horizontal side seems fine, but vertically it is choppy and for some reason has higher sensitivity
Almost none of this question seems related to the input system
But you should at least show how you set up the input actions
i mean it is using the new input system but i also posted it into #🎥┃cinemachine
why do you have the deltaTime scale on it
that's your main issue I think
get rid of all the processors
ok, but it was there by default
did you save
yes
ok good
I mean when i dont adjust any sensitivity in cinemachine nor in the input actions it is smooth, but it has very low sens
I think the rest of the isse is probably due to the cinemachine settings now
but Cinemachine 3 is kinda unfamiliar for me so idk
i just increased my mouse sens with my software to very high and tested it and it works perfectly, but how can i adjust the sens in game for it to work without chopping?
Did the generated class from the inputactions asset change in Unity 6?
I think i see what i was doing, it didn't change i just am using it wrong
So i switched from cinemachine 3 to 2 and hoped it would solve the issue but now its doing something even weirded, it is chopping in some weird way, i have not modified any values in cinemachine and i even tried in a seperate project with older unity version the same thing and it was also chopping, what am i doing wrong??
Cinemachine 3.0 introduces a DeltaTimeScaleProcessor. This divides absolute inputs (like mouse deltas) by the unscaled delta time, which turns them into a velocity.
There's also the "Cancel Delta Time" option on the input axis controller, which which something very similar -- it divides by delta time
(This is incorrect. It should be the unscaled delta time)
Without that, your mouse input will be choppy
Longer frames will have more mouse movement, causing Cinemachine to move the camera faster than during shorter frames
so what should i do to implement that?
you'd attach this processor to your Mouse/Delta binding for the Look action
(specifically that binding! if you add controller input, that should not be processed in the same way)
Ah, I missed it. Okay, that should be fine, then
thats alright
Removing that processor should have dramatically changed your sensitivity. Did you observe that?
yeah i think it did
okay, so it was working, at least :p
At 100 FPS, removing it would reduce your apparent sensitivity by 100 times
yeah i get that
i also changed to cinemachine 2 and it is also doing some weird chopping, but if you find some solution i would switch back to CM 3
I would bump it back to 3
Are you actually using your own input action asset here? I ask because the default asset has identically named maps and actions
ok so i just realised that it actually works on cinemachine 2, but only if i maximize the game window, and also i would happily use CM 3, but if it doesnt work then i have no other choice
that's probably because the game is running at a more consistent framerate
Part of this could just be that the editor is hitching regularly
you'd want to look at the profiler window to check
yeah it is mine, but i coppied some of the actions
yeah thats possible, even tho i have a really good pc
i just realised it is doing the same choppy thing as CM 3 but it has higher sensitivity so it is not as noticable but still
Update back to Cinemachine 3.0 and get it set up with your input action asset
make sure that you have the delta time scale processor on your mouse delta binding
yeah but that does the same thing
i had that before
right, and I want to make sure it's still there
especially after downgrading and upgrading Cinemachine
and also how would you change sensitivity with CM 3?
You can change...
- The scaling on the Delta [Pointer] binding
- The scaling on the entire Look action
- The gain on the input axis controller
I would change one of the latter two
In my game, I accept both mouse and joystick input
I have the individual bindings scaled so that they both feel...roughly correct at a given sensitivity
yeah i did all of those things and they make the sensitivity higher but also it is more choppy
and then I scale the entire action to let the player adjust input sensitivity
a higher sensitivity will cause a big jump to be...well, bigger, so thats tracks
and in your game you dont have any chopping when you move very slowly with your mouse?
I do not.
You should look at the Profiler window while the game is running. Do you see large spikes in the graph that coincide with the jumps?
no, i dont
oh, that earlier example wasn't actually using the new input system :p
it was using the old input manager
yeah i changed it to the new one afterwards and it was still chopping
i just changed to CM 3 and i will try it again
given that the hitching is happening with both input providers (the new input system and the old input manager), I wonder if there's something wrong outside of Unity
your mouse cursor is moving around pretty normally though
ok so i figured out whats wrong, when i used the default input actions it works normally but when i use mine it starts chopping
but the thing is it is practically the same as mine
Do the processors match?
okay, i just made everything match and it works, there is no chopping, but when i change the gain value or the vector scale in the input actions to increase sensitivity it starts chopping again
I'm going to want to see the actual input data. Add this to something in your scene:
public class InputTest : MonoBehaviour {
[SerializeField] InputActionReference actionRef;
void Update() {
var data = actionRef.action.ReadValue<Vector2>();
Debug.Log($"{Time.frameCount}: {data} - {Time.deltaTime}");
}
}
This will log the input value every frame, along with the deltaTime value
Assign the player look action into the inspector
(make sure you get the right one)
okay
no, that is the correct member -- InputActionReference.action gives you an InputAction
you need to assign an action into it in the inspector, though
so first i did it normally when it works without chopping and the i increased the vector scale and it started chopping
That's really interesting. Most frames have zero input, and then some have a catastrophically large movement
This is from the first half. It's a bit weird that many frames have exactly 0 X input, but it's oterhwise sensible
I'm seeing camera movement during periods where the logged value is [0,0]. Hm.
yeah its weird and whats even weirder is that i have not changed any setting before and it is a new project
but it could just be that the console is scrolling very quickly
Oh, are you moving the mouse very slowly in the second half?
i can try to make a new project with the same unity version and with CM 3 and try to do the same thing
It looks like your mouse has to move pretty far before any input is recognized at all
almost like there's a "deadzone"
How much did you scale it up by?
what?
what numbers did you put in to the scale processor?
ah, my aggressive skipping-around missed that -- okay, so it's 10x
and it started at 0.1x
so there's a 100-fold difference between the two
yes
That's going to be the issue, I think
yeah i mean if i move by lets say 1 unit and it moves by 100 units it will be choppy, but how do i make it smooth then?
I think your mouse just isn't providing input precisely enough. Blowing it up by a very large scale factor means that you get very jumpy movements
notice how many frames of input have a zero for one axis
it suggests that Unity is getting no input at all if the mouse only moves slightly on one axis
yeah, isnt there like a minimum move distance for unity to register?
that could be it
Do you have your mouse set to a low DPI along with a very high input sensitivity in Windows, by any chance?
i have mouse sens to 600dpi and windows to 8
that is a little low sounding
Can you increase the mouse DPI and reduce the mouse sensitivity in Windows? See how that feels by comparison
yeah, but my mouse cant be it, it works normally in other games
i tried it and it is still the same
@supple crow i found this on the internet
🤔
"don't go above 1 (but it's ok)"
does this have something to do with it?
and also if you scale the vector by 100 in your game, does it work normally?
(which is not attached, hopefully..)
If I scale it by 100 my mouse sensitivity goes completely crazy
I have it scaled by a completely arbitrary 0.18
yeah obviously but is it chopping?
It does get choppy, yeah. It's a lot like what you're seeing, which makes sense
The smallest possible input is now a very large camera movement
yeah exactly
yeah thats what im getting
Are you moving your mouse by very tiny amounts with the 10x sensitivity?
yeah
ah, yeah, then that's just how it's going to work
your mouse is not able to provide inputs that are small enough and frequent enough to look good at that sensitivity
if the mouse can only ever say "I moved by 1", and you multiply its movement by a big number, you're going to get chunky movements
okay, i will leave it like this, because if somebody else plays this game and changes the sensitivity, it probably wont be choppy cuz they will have a reasonable sens
yes
I was under the impression that you were still moving the mouse a decent amount!
that would be more confusing
yeah no
okay, but thanks for the help
i just tried this in pubg, i put the sensitivity to the highest (which is only 2x multiplier) and in is also choppy
so i was trying to solve a problem that cant be solved
okay this is rad, thanks for letting me know!
How do I disable this error? the game works exactly as expected using this so I don't care if it's "technically" not the correct method.
Or is there a method on how you're supposed to do it in the new input system?
What are you trying to do? If you are trying to get your UI to block mouse clicks or something you should be using the event system to process your clicks instead of doing it manually
(that goes regardless of which event system you're using)
I have a click action with a click that then does like the following simplified code
void OnEnable()
{
playerInput.onActionTriggered += HandleInput;
playerInput.onControlsChanged += OnControlsChanged;
}
void OnDisable()
{
playerInput.onActionTriggered -= HandleInput;
playerInput.onControlsChanged -= OnControlsChanged;
}
private void HandleInput(InputAction.CallbackContext context)
{
if (context.action.name == "Fire1" && context.performed)
{
OnFire1();
return;
}
}
void OnFire1()
{
if (!DoingSomething() && timeStamp <= Time.time)
{
if (GameState.instance.inMenu == false)
{
Interact();
}
}
}
void Interact()
{
if (IsPointerOverUI())
return;
// DO STUFF
}
private bool IsPointerOverUI()
{
return EventSystem.current.IsPointerOverGameObject();
}
Yeah so like I said - instead of handling this manually with an input callback
you should use IPointerClickHandler to handle it
you will get the "UI blocks interaction" behavior for free.
Ah okie
Which is why you're doing if (IsPointerOverUI()) in the first place
I'll look into adapting my code to that then :D
Nope, still the same issue. The issue doesnt appear when I jump and dash with kb, maybe it's my controller that effed up? I chose the action as a button, I add nothing else to it inside the input controller.....maybe I should?
I don't have my controller on me (I can get it on the weekend) to test it, but try a different controller.
I dont have unity open right now but I'm assuming either the controller is fked or some sort of deadzone setting is not working right (I don't have the settings in front of me to check what buttons have or dont).
So my first guess is try another controller and see if it happens.
If it does => config issue (either your project or unity messing up)
if not => 99% controller's fault
Howdy folks. I am trying to upgrade my unity 2D project to use the New unity input system, due to a bug with some tablets where finger drags miss pixels :/ But man this has been a trip. I'm currently fighting an issue where my cursor is invisible all the time. I have an extensive set of cursor images/sizes depending on what the cursor is currently over in game. To make this work previously I had to lock the cursor and force it to software. But now, nothing seems to work to make it visible again. Any ideas what might be going on?
Looks like this is my problem here, without any reported solution: https://discussions.unity.com/t/new-input-system-doesnt-update-the-mouse-icon-on-the-screen/837124/7
Hello there, does anyone know the way to specify a "global" speed scale on all inputs ? The way I see it, we might need to iterate all the map at init time and specify some postprocess programatically. Any other thoughts ?
wdym by scaling inputs?
Yes sorry, I knew it was not clear, that's why I said speed scale. Basically I want to reduce the speed of all non binary inputs ( sticks / triggers / mouth delta)
basically smoothing analog inputs?
But I want to do it with a single entry point, I could as well create a postprocessor that would handle this on the specified inputs; but had no luck creating processors
mmh yes definitelly smoothing, linearly (or any curve)
Well I guess I'll try make a custom processor nevertheless. I'll report here.
yeah seems like there isn't a built-in way to do that
There are actually two usecase, one which is an infinite analog input (like panning), that can be simply scaled down, and one which has a finite range (such as trigger) and which need to be actually smoothed. The issue beeing Processors are stateless
The best option I can see is to iterate over your input actions and attach processors as the game starts up
There isn't some kind of "global" processor that applies to every single action of a certain type (that'd be a bit weird)
I created Scale Processors child classes that checks for a cli arg in order to apply its scale or not. I just added the processor to any input that need that behaviour. It indeed seems I'll have to handle every bits individually. Not sure about the weirdness of global processors on inputs though. It actually seems quite handy to be able to have global callbacks/plugins, more tool always better imo.
it would be strange to filter every single Axis-type action, since you can have very different kinds of axis inputs
You should be able to do this at runtime.
(I haven't done that before, mind you)
@supple crow is this what you were talking about
Yes. You can assign a specific input action in the inspector
and then how would you use it
would you read it the same?
it gives you an InputAction
yeah
you can then subscribe to its events or read its value
that just turns entire input action maps on and off depending on the current game state
so it turns off the "Humanoid" action map if you aren't controlling a humanoid entity
and turns on the "Menu" action map if a menu is open
There is no InputActionMapReference, so I just find them by name from an InputActionAsset
so you have like just 1 method for turning off and on?
or multiple for each map
I've looked everywhere to find the documentation for this but for the life of me I can't figure out how to make input overrides apply to only one specific player input component for local multiplayer. I want to allow both players to rebind their controls at runtime, but any time I try to alter the overrides it applies to a project-wide version of the input actions rather than the private local one and I don't know how to work with it.
See the test class below
public class RebindTest : MonoBehaviour
{
public PlayerInput testInput;
public ControllerInput controllerIn;
private void Start()
{
if(controllerIn.ControllerID == 1)
{
Debug.Log("Rebind for id " + controllerIn.ControllerID);
testInput.actions["jump"].ApplyBindingOverride("<Gamepad>/leftTrigger");
}
}
}
When I remind the testInput player input, both controllers in my local multiplayer game get rebound even though I want to ask it to rebind only controller 1's controls. I'm sure I'm just missing something here but if someone knows what the issue is here please let me know.
It's checked in Update
I have not actually done multiplayer yet. My first instinct would be to instantiate the input action asset that each PlayerInput is using
But that'd need to be done before it subscribes to all of the events on the input actions
This was the closest documentation I could find in some unofficial github guide but the link to the private instantiation section doesn't elaborate further
ah, so it instantiates the asset but doesn't expose the copy
(or maybe it instantiates all of the actions individually -- same general idea)
am i thinking correct?
Roughly, yeah. I check a few things to decide if each map should be active or not
I only switch the map on or off if it needs to change
yeah
I'm not sure if calling Enable every frame would be a problem
maybe check if its disabled first
So, for example, if I have an active menu of any kind, the menu actions get activated
ah, but that's InputSystem.actions, not anything on the PlayerInput component.
is there a method to only enable 1 action map and disable the rest?
You could check if the actions from the two different PlayerInput components have different instance IDs
I don't think there's one to do that. Note that you might want many action maps active at once
oh wait im gonna need a few active at a time any way
I have some actions that are universal and some that are context-specific
Two different instance IDs it seems
Interesting. I wouldn't expect the binding overrides to apply to both
{
public PlayerInput testInput;
public ControllerInput controllerIn;
private void Start()
{
Debug.Log(testInput.actions.GetInstanceID());
}
}
Actually, what is testInput.actions?
I was thinking of looking at individual actions
is it an InputActionAsset?
how do you grab the action map though? what else do you reference for that
Yup
You can't serialize a reference to an input action map
So I just do it by name
For reference with the previous test script this is the console output
Even though the instance IDs are different for each one's testInput.actions, whenever the script runs the jump key that I have bound on keyboard normally gets overridden for player 2 even though only player 1s testInput.actions are getting overriddent
(not just the ID of the entire input action asset)
I assume the id for the action is just under ID since there is no getInstanceID function
Anyways seems identical (I removed the if qualifier for this test)
That tells me what's going wrong specifically but I have no idea how I would even begin to go about troubleshooting it
Ah, right, it's not a unity object
what am i doing wrong
Property or indexer 'InputActionMap.enabled' cannot be assigned to -- it is read only
how do i disable/enable it then
the PlayerInput docs mention the concept of rebinding, but don't explain how that would happen. How annoying
got it InputActions.FindActionMap("Driving").Disable();
read the docs for InputActionMap
it has methods to enable or disable
ye
Yeah that's what's making me lose my mind
Basically every tutorial I watch is only for single player applications and black boxes imported packages so much I can't even begin to try and build it for my own purposes
Not that I'm aware of. Iterate over all of the maps and disable them
what does that disable then?
I'm eventually going to try to do splitscreen multiplayer, so I'm going to have to figure that out..
well, I guess it does exist after all :p
yeah, Disable disables every map
which disables every action
Currently I'm working on building a smash bros style "Name" control selection UI. Basically controls are tied to a player profile that I intend to save to a json file. Players can then load a player profile from the list of "names". This will then apply the override to their controls from the base using the specifications from the json file. If I can just figure out how to change the controls at runtime I think I'm set but this issue is driving me crazy.
Would that help with the problem they're having? Rebinding on one player's action is changing the other player's action
Yeah this isn't my problem
This is
I'm already familiar with json save and load (I'm probably going to make custom versions of these functions)
My main issue is rebinding in a local multiplayer environment
Because when I rebind for one playerInput it rebinds for all of them
well this is mildly interesting
Are you using PlayerInputManager?
public InputActionAsset actions
{
get
{
if (!m_ActionsInitialized && gameObject.activeInHierarchy)
InitializeActions();
return m_Actions;
}
// setter
}
This is the "private copy"
Yes
Maybe your code is just running on all the players at once
I'm wondering why the actions are identical even if the InputActionsAsset is different
But the docs claim that actions is somehow different from the "private copy"
It isn't I checked
well, it sounds reasonable enough -- the action itself is just a name, a type, and some bindings
that action would have to actually be connected to something to do anything
Oh!
I know what it is
The InputActionsAsset has a different ID but the actions themselves don't
The first one uses the og?
I was kind of suspecting that earlier, but I wasn't at my computer and couldn't check it
I think I've seen hints of that before
So if you do anything to that player's actions, it'll affect any subsequent players' actions

It probably makes singleplayer easier to deal with
you could instantiate the input action asset before giving it to the first player's PlayerInput
actions = Instantiate(actions);
player1.actions = actions;
player2.actions = actions;
etc.
this is definitely why -- in that case, instantiating the asset wouldn't achieve anything, and it would make it mildly more annoying to affect the player's actions
good to know for when I start doing this stuff..
Where would I even do this?
Would I add a script to my PlayerInputManager object that does this?
You'd do it here
You should be able to just do:
testInput.actions = Instantiate(testInput.actions);
I guess it'd be ideal to only do this for the first player
but the cost should be negligible
Ok so I tried this and now every time I press an input every it tries to create a new playerInput from the playerInput manager?
Ah, I bet that's becaues it doesn't understand that a playerinput already exists for that device
I wonder if you need to do this
(For reference the player input manager tries to create a prefeb for the controller whenever I press a button until it reaches max capacity)
I don't quite understand this, but I have a feeling it affects which specific InputDevice is being used by
var oldActions = m_Actions;
m_Actions = Instantiate(m_Actions);
for (var actionMap = 0; actionMap < oldActions.actionMaps.Count; actionMap++)
{
for (var binding = 0; binding < oldActions.actionMaps[actionMap].bindings.Count; binding++)
m_Actions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]);
}
This is how the PlayerInput component copies an input action asset
I'm confused
that makes the two of us!
I haven't looked very closely at how multiplayer works before
I'm going to cry why did they design it like this 😭
Maybe this is the problem?
for (var i = 0; i < s_AllActivePlayersCount; ++i)
if (s_AllActivePlayers[i].m_Actions == m_Actions && s_AllActivePlayers[i] != this)
{
var oldActions = m_Actions;
m_Actions = Instantiate(m_Actions);
for (var actionMap = 0; actionMap < oldActions.actionMaps.Count; actionMap++)
{
for (var binding = 0; binding < oldActions.actionMaps[actionMap].bindings.Count; binding++)
m_Actions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]);
}
break;
}```
Ok so if I comment it out like this it works
// Check if we need to duplicate our actions by looking at all other players. If any
// has the same actions, duplicate.
//for (var i = 0; i < s_AllActivePlayersCount; ++i)
//if (s_AllActivePlayers[i].m_Actions == m_Actions && s_AllActivePlayers[i] != this)
//{
var oldActions = m_Actions;
m_Actions = Instantiate(m_Actions);
for (var actionMap = 0; actionMap < oldActions.actionMaps.Count; actionMap++)
{
for (var binding = 0; binding < oldActions.actionMaps[actionMap].bindings.Count; binding++)
m_Actions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]);
}
//break;
//}```
The problem is that I have no idea how to change input system without unity freaking out and reverting it
ah, so now you're manually making the duplicate?
and not allowing PlayerInput to do that
Oh, I misread
PlayerInput is checking to see if the InputAction already exists and if so it duplicates it
you're unconditonally having it copy the asset
Hey, I am a very beginner unity user, and I was wondering if there was anyone who would be able to help me with some problems I've encountered through making my project. I've been trying to follow tutorials, but most are outdated or vague
But IDK how to change a unity package to work 😭
quite simple! you just have to embed it
Every time I make the change it goes "NOPE"
Copy the folder from /Library/PackageCache into /Packages
Packages that are installed normally through the package manager are put into the Library
When you put that folder into Packages, Unity recognizes that you've got a copy of the package in your project
You're allowed to do whatever you want with those files
If you delete the folder from Packages, Unity will put a copy of the package back into /Library/PackageCache
I used to just kind of...do it twice? That tricked Unity into keeping the change
But it would break the next time it recreated anything in the package cache
Wait so if I do this will the component still work as intended?
Like do I have to do any weird finageling with duplicate packages or anything of the kind
Unity will see that the package is in the Packages folder and get rid of the copy in the package cache
It's really painless
I embed a number of packages. I've made some tweaks to Splines to make it perform better for me
Dope
(i frequently modify splines every frame, so doing lots of work to cache data for the spline is pointless because it gets thrown out immediately)
Now, if you want to update the Input System package in the future, you'll need to get rid of the folder in /Packages and then update through the package manager
So this adds a little wrinkle to updates
no prob! i got to learn something as well :p
Is there a (straightforward) way to not register clicks that occur within my UI Toolkit UI in my input handler? Basically i dont want to attack an enemy if the player was clicking on a UI element, for instance
hmm, with UGUI, you can ask the event system if the cursor is over a UI element
I'm not sure if the same applies to UIToolkit (it does use the event system..)
Hey, i need to use a keybind for two actions. One simple press, and it does something, but if i hold, it only does another method, but not the first one.
I tried to do with two actions, with the same keybind, one with hold interaction, and one without. However, when i hold, it does the first action, then after a few seconds, the second one.
Does anyone have a solution for this? Thanks 🙂
You need a "Tap" interaction on the other action
This prevents it from performing if the button is held for too long
Oooh okay, thanks a lot 🙂 i'm gonna try
That's awesome, great thanks
This new input system is really insane
It's a bit intimidating at first -- mostly because it gives you so many ways to receive input
I really like it
I can automatically construct a hint popup for any input action
That's huge
InputActionReference is also very nice
I just plug in the relevant action wherever I need an input
i have DigitalNormalized selected for the 2D Vector
and when i walk sideways by holding W and S for example
this is what shows up
is that correct?
does that block the player from walking faster sideways?
or would it have to be 0.5, 0.5
That's correct.
0.707107^2 is almost exactly 0.5
sum two of those up and you get 1
This would be too small of a vector
it doesnt show the ^2
thats why i was confused
I'm just writing the math out by hand
The magnitude of that vector is not 0.707 + 0.707
It's 0.707 * 0.707 + 0.707 * 0.707
which is roughly 1
yep that's preceisely sin(45 degrees) and cos(45 degrees)
sqrt(0.5)
Does anyone know a possible reason why, despite the on screen controller being present and working per the input debugger, the script cannot read any values from it?
I've checked everything and the actions seem to be set and work correctly when using a keyboard
For anyone that's interested, the problem was me using two PlayerInput components with the same actions because I mistakenly thought that any object would need that to use the input action reference correctly.
No idea why it would block only mobile controls but I'll take it and leave
Each PlayerInput is considered a separate human player and will get different devices assigned to it
Got it, thanks
I have a rather peculiar problem with input: I'm building a R/C flight sim on the Meta Quest (Android) and as such want to support R/C controllers as input device. I have gone so far as to query all axis and read out the value and position in the StateBlock buffer coming from the controller. I have one controller that on the path "/rightStick/y" is providing me with the incorrect offset (off by 8 bytes) in the StateBlock. I'm on 2022.3.54. Before I was using an older 2022.3 version and there all gamepads had the same issue, so I hacked the system to automatically correct the offset for that axis. In the newer version however, a bluetooth gamepad and an XBOX controller work correctly out of the box (so my hack will break it). So now I am left with no way of knowing the correct offset for the rightStick/y axis.
I have a hunch it's either an issue with Unity or the Quest because on a "Game Controller Tester" app on my Android phone, the controller is read correctly.
is there a way to trigger an input system action from code?
Well there's the API for unit testing... https://docs.unity3d.com/Packages/com.unity.inputsystem@1.11/manual/Testing.html#writing-tests
Do you mean in a build though?
You could make a custom device and trigger it whenever you wish I imagine https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Devices.html#creating-custom-devices
and bind your custom device to the action
Sorry more up to date doc: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.11/manual/Devices.html
You could also take a peek at how OnScreenControls work and do something similar: https://github.com/Unity-Technologies/InputSystem/blob/develop/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs#L193
hmm alright
euuugh idk how to set this up with GenericDropdownMenu items
since I don't get access to that visual element in the AddItem function
class HalfEdgeDropdownMenu : GenericDropdownMenu {
public void AddItem( InputAction action ) {
string keyBind = action.bindings.First().ToDisplayString();
string label = action.name;
if( string.IsNullOrWhiteSpace( keyBind ) == false )
label += $" {keyBind}";
base.AddItem( label, isChecked: false, () => {
action.performed.Invoke(); // <-- I just want to do this ;-;
// ClickEvent e = new ClickEvent();
// e.target = ???
// InputSystem.FindControl( "mouse" ).WriteValueIntoEvent( );
// _ = 0;
} );
}
}```
Hmm - an extra problem here is that I think things like performed generally only happen as part of an input system Update. Out-of-band events are not really a thing without calling e.g. InputSystem.Update manually.
You'd also need to construct a phony InputAction.CallbackContext for the event parameter if you didn have a magic way to invoke the event.
Maybe figuring out some side channel to do this is better
side channel?
oh, maybe yeah
the goal is to have a menu item at the top of my application that can perform the same actions you would if you pressed that hotkey
Reflection is, of course, always an option but terribly hacky...
Oh yeah I think an OnScreenControl is basically what you want then - but I have no idea if there is such a thing for UI Toolkit
Ahhh that's only for the event system... oops
Yeah OnScreenControl is a MonoBehaviour >_>
I think your best bet is reading the source for OnScreenControl and seeing if it can be adapted to UITK
guess I'll just make a whole wrapper thingy
as in like, the script that hooks up inputs to actions also hooks up the menu items while it's at it
I might have to do that anyway to add menu item enabled/disabled validation
I am also interested in doing this -- mostly in the editor
I want to be able to fuzz my game by just spewing random actions at it
it'd be nice to have in builds too
My FPS camera controller is working weirdly.
This is not the first time this happened.
I once made a third-person camera system with Cinemachine, and the same problem occurred, where the camera would egregiously tilt downwards in the first frame.
Plus, for some reason, the camera aim is not consistent. If I move my mouse slowly, it moves just fine, but if I move it quickly, it overshoots - is this mouse acceleration?
I'm using the old Input System, and I'm thinking of moving to the new one. But I'm not too worried about that for now unless that can solve the aforementioned problems.
Here's the source code:
using Unity.VisualScripting;
using UnityEngine;
public class CameraController : MonoBehaviour
{
[SerializeField] Transform CameraTransform;
[SerializeField] Transform PlayerTransform;
[Space(10)]
[SerializeField] Vector2 Sensitivity;
float xRotation;
float yRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
xRotation = transform.eulerAngles.x;
yRotation = transform.eulerAngles.y;
}
private void Update()
{
MoveMouse();
}
void MoveMouse()
{
float mouseX = Input.GetAxis("Mouse X") * Time.deltaTime * Sensitivity.x;
float mouseY = Input.GetAxis("Mouse Y") * Time.deltaTime * Sensitivity.y;
xRotation = Mathf.Clamp(xRotation - mouseY, -90f, 90f);
yRotation += mouseX;
CameraTransform.localRotation = Quaternion.Euler(xRotation, 0, 0);
PlayerTransform.localRotation = Quaternion.Euler(0, yRotation, 0);
}
}```
It works just fine except for those two concerns pinpointed above.
My FPS camera controller is working
You should not be using Time.deltaTime with mouse input handling
Removed 🫂
If you're unsure of why that helped -- mouse input is an amount of movement, not a rate of movement
You multiply joystick input by deltaTime because the value tells you how far the stick has been tilted. It's how fast you want to move
The mouse tells you how much you want to move
Want to bump this and ask again. Seems like something that's a pretty common use case
Is there a way to make clicks that hit UI Toolkit documents not hit the world?
Ooooh good to know
But do you know anything about the downward tilt?
The jarring movement could be caused by locking or unlocking the cursor
the cursor gets pinned to the center of the screen
I had a problem with that in my game -- when closing the debug menu, which re-locked the cursor, the camera would suddenly move quite a bit
I have a static field that tells me that the camera was locked this frame. I ignore all Look input when that field is true
Use the event system for your clicks in the world too
i want in my 2d game to make player press mouse button, read value of the mouse position and cast a spell from player to position. The problem is i can either make input action of value vector2 type and constantly be reading position of the mouse or type button but not read the position of the mouse. How do i combine those two so that the position of the mouse is only read on mouse click?
Make two different actions
one for the position, one for the click
ty
Oh yeah, I didn't think about that. It could be that I moved my cursor while I was loading the game. Do you think it's recommended for me to disable mouse movements for the first frame?