#🖱️┃input-system
1 messages · Page 48 of 1
same deal - check if you're currently holding W via the same methods
so that means i have to use the "Both" option on the project settings?
you can do this entirely using the input system. how are you currently handling input?
no
of course not
none of what I said above has to do with the old input system
so that means i have to make another input action for holding W separately from the movement input actions?
no
so what do i do?
how are you currently handling the input?
cool, and the behavior on your player input component? (not 100% sure if this matters, but i'm going off of my own experience right now)
just check the current value of your Movement action and if movementValue.y > 0 then you're holding W
ah you're doing it the less easy way, but like praetor said, just check the y value of your movement every frame, if it is greater than 0 then w is held
it works
ahh yup, so that's it
thanks guys
best ide format
not even monospace 
Monospace is a crutch!
Good fonts, a crutch
someone can suggest a complete tutorial for input system 1.0.X to create mobile sticks left-right) and character move-animations?
On Screen sticks are pretty much built in to the new system: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/OnScreen.html#on-screen-sticks
You just need to attach a visual representation (e.g. spriteRenderer) to the same GameObject
hi guys i got small question i try play around with the unity new input system but it working very odd when start it look like player gose off screen i got this code try understand how work with fixupdate with the unity input system https://pastecode.io/s/gofqrx2z the Game.inputs it to gen script of unity new input system
Hopefully a quick question, but I am trying to record inputs on every frame in a session for replays. Is there a simple way I can make it so that the event triggers if a button is being held down? From my initial tests I can only trigger the event when the change in state (pressed/released) occurs, but keeping track on if the button is being held down or how long it's been held down has required me to do some logic an boolean checks for each direction and button. Feels like I'm overengineering it. Hoping I'm just missing some toggle that triggers the event whenever the button has or remains pressed. Any ideas or samples I can look at?
there's a Hold interaction that will essentially delay the performed event until some preset time has elapsed
is that what you want?
if you want to just know "is this currently being held down" each frame - the best approach is to simply read the value of each action you are interested in each frame
It should be relatively straightforward to throw all of the InputAction(s) you are interested in checking each frame into a collection (such as List or array) and just do a for loop over that collection each frame to check if each one is currently actuated.
another option is to put all those actions into a collection, add a listener for all of their started and canceled events (again in a loop) which adds/removes those actions from a HashSet or Dictionary and you check/record the current residents of that HashSet/Dictionary each frame.
How would I setup the Hold interaction?
It doesn't sound like what you actually want
What I'm doing atm is I have class-level booleans such as upPressed, downPressed, punchPressed, etc. Total of 7 booleans for each direction and a function. When the event is triggered for example I store the value if the input value isPressed.
Then in the Update() I'm calling a void function PollInputs() which basically sets an array of length 7 to record current boolean values of each boolean, then calculates and stores the length of time the button has been held given the previous frame's values.
The array is of a custom button class I made which just records the input type, if it's pressed or not, and how long it's held.
I feel I might be doing too much by doing it this way.
Anybody knows why Release() is executed while I'm holding the OnScreenStick?
It seems like program thinks that I let go of the stick when the stick is centered (0,0). Is this bug?
nope that's how joysticks work
canceled happens when the actuation of the stick reaches 0,0
If you did the same thing with an Xbox or Playstation controller it would happen teh same way
it doesn't know you're touching the stick just that it's actuated or not
It seems like I will have to change this control
I have "Jump" as input, but if i push my spacebar which should be connected to "Jump" it doesnt work... what do i need to do to fix it?
how do you know it's the space bar not working and not, say, your ground check
Big brain, but how do i check that, i started like yesterday so i dont know.
Debug.Log would be one way.
Debug.Log($"Jump detected: {Input.GetButtonDown("Jump")}");
Debug.Log($"Is grounded: {isGrounded}");```
do i need to put that in my code? or can i find it somewhere?
im new, idk
what do i need to do with that?
it will print some information to the console
so you can see which one is going wrong
k
you need both of those to be true on the same frame for the jump to work
k, thank u
Hey I'm having problems with the Input System not working for me after I build my game. It works just fine for me in the editor.
Things I've Tried:
- Use "PlayerInput" component with behavior set to "Invoke Unity Events" and "Send Messages" different times
- Implemented the interface from generated C# file
Project Settings:
- Player settings are in the image.
- Input System Pack setting, I've left the Supported Devices empty and another time with them set to Keyboard&Mouse. Keyboard&Mouse input aren't working after the project is built.
Any help I can get would be awesome!
Can you explain what isn't working exactly?
I have movement controls with WASD and get mouse position and clicks. My problem is that after I build my game, the input stops working. It is as though my keyboard and mouse aren't even plugged in.
The game works well with input as long as I am only playing it in the Unity editor and not a built version.
hmm not sure 🤔 I'd just google around
Alright, I was hoping there might be something simple that is commonly missed. Haven't found anything on google yet unfortunately but I won't stop looking.
Wish I could be of more help.
Thanks for taking a look 🙂
Hi all, im not sure how to install the input system 1.1 from github into my project
i would like to get the SaveBindingOverridesAsJson(); into my project
I am not sure which link to use because when I do this I get an error
Cannot perform upm operation: Unable to add package [https://github.com/Unity-Technologies/InputSystem.git]:
you need to also make sure you have git installed
I have git installed
I was able to add another git file
[https://github.com/Unity-Technologies/InputSystem.git] does not point to a valid package repository.
Hello, im very new to unity, could someone help me with input controls?
im not sure how to change/modify them
genuinely not sure if this is suited to this channel but im using the "new" input system and its a problem with my mouse so meh.
im trying to have an inventory slot that knows whether a mous
actually hold on ima try somethign
yeah ok no
im trying to have an inventory slot that knows when a mouse is over it. for optimisation its going to update a bool when the mouse enters and exits it, to determine whether its currently over the slot
ive looked up multiple ways to implement this and all seem to dead end at the same problem: it's insanely inconsistent. it appear completely random when the mouse is over it or not. the systems dont seem to rely on any collider so im not sure what its picking up as "over" the game object
for reference, ive tried inheriting IPointerEnter as well as mono onto the script, and using the relevanrt methods, and rn im also trying event trigger component with the relative setup
both seem viable online but both have the exact same issue. help anyone? :D
in case it's relevant, the slots are on an overlay canvas
i also heard something something Raycast hwen i was looking it up and i just unticked the canvas' "Raycast Target" box but it still randomly knew my mouse was over it as before, maybe cause im in 2D project setup? idk
nvm
my crosshair was blotting out the button so it seemed random because it only did it when the croisshair wasnt over
well i cant figure out how to disable interactions between my mouse and my cursor image (that's blocking out the button that needs to detect whether the cursor is over it). does anyone have any ideas?
they're on the same z axis but i tried moving the crosshair to Z 100 just to put it way behind the slot image, still nothing
just disable "raycast target" on the cursor image
If you are using IPointerEnter etc raycast target will matter. OnMouseOver and similar methods I believe do their own thing and ignore the event system entirely
Also ensure that you have an EventSystem in the scene and that you are using the correct input module (Input System UI Input Module)
For anyone like me that would like the preview package, here is the solution
Enable preview package
You shouldn't be getting packages hosted by Unity off git, but in future if you want to add packages that aren't hosted on a registry (be it Unity's or OpenUPM) that have their packages in subfolders you need to target the subfolder https://help.vertx.xyz/?page=Package Manager/Git Subfolders
Question, I am trying to set up the Input system package. I have it installed from the package manager, and I have regenerated registry package csproj files, but there is no UnityEngine.InputSystem.csproj in my project directory. Am I missing a step to import the system?
I don't have that either
but it works
I'm installing a Unity version rn so I cannot check where it is, but there is a preference you can tick to generate Csproj files for packages
Interesting, VSCode does not recognize the namespace though
what namespace are you using
using UnityEngine.InputSystem;
Pretty sure that's right - opening my project now
Is Unity recognizing it?
Just VSCode not recognizing?
It counts as a compiler error, so the project will not run.
If I check this box, it creates csproj files for all the Unity packages
including InputSystem
try that?
(and hit regenerate project files)
It's a compile error in Unity too?
That shouldn't happen unless the package wasn't installed properly
That was the first thing I tried. It makes csproj for everything but InputSystem.
Seems like it's not installed properly somehow
Can you create InputActions and such?
Yep, I can create them and open the editor and add actions to them.
That's odd. I'd try uninstalling and reinstalling the package
Fair enough. I will see how that goes.
(unity may force you to restart a couple times to deactivate/activate the backends unfortunately)
Yeah, this is a pretty small project so loading time is inconsequential.
I'll just add this as a data point:
- Using Mac osX
- No UnityEngine.InputSystem.csproj in my project folder
- Registry Packages unchecked in preferences
- Input system works fine
- Visual Studio not VSC
Okay, reinstalled the package, I also updated my VSCode integration to the latest as it was out of date. I see now that I have Unity.InputSystem.csproj. But I still cannot import UnityEngine.InputSystem. Or Unity.InputSystem... Wondering if there's something missing in the .sln
No, InputSystem is there in the sln, I am very confused why VSCode refuses to acknowledge it as a namespace.
Have you followed all of the configuration steps here? https://code.visualstudio.com/docs/other/unity
I've never tried VSC personally so can't offer more help beyond that
That's fair, I remember having trouble with configuring VSCode when I first set it up. I'll restart my computer and give it another crack tomorrow. Maybe the answer is I need to switch to using Visual Studio.
Thank you for all your help. I appreciate it.
hey guys, i nknow the old input system had mousex/mousey framerate independent... does the new input system have framerate dependence for mouse deltas?
because if I multiply my input by Time.deltaTime, in the editor it's fine.. but on my build it's fast af
my mouse input *
I use VSCode as my code editor with Unity and it works.
Hey guys! i got a quick question, while trying to make a quick laser-defender style game i used this code in update to instatiate a sprite of a laser, problem is, it spawns it infintely, this is the code : ```c#
{
if (Input.GetButtonDown("Fire1"));
{
Instantiate(laserPrefab, transform.position, Quaternion.identity);
}
}
it just loops infinitely even if im not touching the keyboard
for some reason this always comes out as true: ```c#
if (Input.GetButtonDown("Fire1"));
Check how your "Fire1" Input setup in the Input settings. If it is set to listen to somethings else. Things like joystick axes may have junk inputs sometimes. https://docs.unity3d.com/ScriptReference/Input.GetButtonDown.html
ill look into it, thanks
even if i negate the statement it stills instantiates it :(((
That's not the problem with condition then. You should also isolate things and test them individually
hmm it seems the whole function is working quite weirdly, ill rewrite it again
also should i use newer unity versions? or download the recommended
my version bugs out a lot, the layers dont stay in their place when i close and reopen unity
You should debug it and understand what's wrong, to not make the same mistake again. There's debugging guide pinned in #💻┃code-beginner
ill look for it, thanks for the help !!
which one is newer?...it says update but its a lower preview number?!
Im trying to add 1 health to my character if i press e but i dont know how to do it
new or old input system?
the one you download from the asset sore
(package manager)
Why is there a coroutine?
Doesn't tell us much
can't you just do a
if (Input.GetKetDown(KeyCode.E))
currentHealth--;
What's a W
I accidently put that there
while i was doing screenshot
Doesn't make much sense without the W either. What exactly are you going for
if(Input.GetKey(KeyCode.E))
currentHealth = Mathf.Min(currentHealth + 1f, 100f);
I am trying to add one hp to my character and the longer i hold e the faster it adds health
Guys, need help with something. I'm trying to do a Double tap to run in the new input system.
I set it up like so that Walk gives me a Axis based on Left or Right Arrow and Run is a Passthrough Button that triggers whenever i Press Left and Right with a Multitap of 2.
And it technically works. My issue here is that the Multitap doesn't work every time. It's as if i was pressing it too fast, or to slow, but i doubt i'm too slow because i'm legit tapping really fast my keys... I'm confused on what might be happening e.e
(ScreenShots Inc)
Why a Coroutine? Just check if e is held in Update
I dont know how to do that im new to coding
Try this @sinful warren
If it's intended to be int remove the fs from the code I posted.
ok
I feel like my issue is gonna get lost :/
it didnt work
Show your updated version of the code.
So I'm guessing no errors.
nope
ok lemme try
To detect while button is held.
that sets the health to 100 instantly
Perhaps you should re-post your question in #💻┃code-beginner
ok
Hi. I'm using the InputSystemUIInputModule, and now all my mouse pointer/click doesn't work
What's the right way to set this up?
Some forum post says to add Physics raycaster and whatnot but nothing works for me
Ok it works, setting it to use Both system and restart...
My UI buttons responds to the "enter" keyboard. How can i also make the "spacebar" to also press the button, without setting the spacebar's binding to "submit"?
Actually i remember this was the default behaviour. Now, only "enter" works for this. I cant seem to figure out what could have changed this
So i'm almost certain the space doesn't work since i moved to input system package
I tried adding this entry in the pic, but upon saving it just gets removed?
Listen mode also doesn't seem to work on any keyboard presses..
But input debugger detects it
Ok nevermind.... apparently i've been using/editing the default input setting which is in the package which is read only...
Created my own input setting and everything works properly
Hi there,
I have some issue with the input system, let me explain my scenario first:
I have a little mobile game with a OnScreenJoystick (using Unitys OnScreenStick control) that moves the player. Additionally, if the user touches the screen, the player jumps.
The jump is of actiontype button and uses a Primary Touch/Tap Binding.
So, if the user taps somewhere on the screen, the player jumps. to not jump if the user touches the onscreen joystick, I'm using EventSystem.current.IsPointerOverGameObject, that works as expected.
However, due to the nature of recognizing a tap, there is some delay between the actual "finger is on the touchscreen" until the tap-callback is called. For some users that feels like a input is lagging, because touching and the actual jump is a bit delayed.
To mitigate that, I tried using Touchscreen/touch contact. As soon as the finger is on the touchscreen, my jump method gets invoked.
For whatever reason, EventSystem.current.IsPointerOverGameObject does not recognize anymore, that this touch contact is over a UI object. By that, if the user touches the onscreen joystick, the player also jumps.
Maybe I do something wrong with the setup or there's maybe a bug with EventSystem.current.IsPointerOverGameObject because on TouchContact is does not recognize that the contact is over a UI element.
I also tried iterating through Touchscreen.current.touches and use touch.touchId.ReadValue to feed any touch to IsPointerOverGameObject(touchId) however, they all report false, that the pointer is not over an UI object, but it should report true
Unity Version: 2020.3.14f1
Input System version: 1.0.2.
Does anyone have an idea, what could possibly go wrong?
Something to note: I feed the OnScreenStick into a Gamepad/Right Stick control and read the movement from there.
I need some help. I'm gonna simplify my problem. So i have this 2d Platformer movement in a 1D axis. Anyone has any clue how do i setup the movement on the new input system so that he walks arround with a single tap of Left/Right but if i double tap it starts running in that direction?
this is what i have so far but isnt really working
(ignore the Max Tap Spacing, i was attempting to debug it, assume its default)
Does Inputs.Player.Get().actions get references to the actions? Because when i try to do InputAction.RemoveBindingOverride it does not seem to actually do it
BindingOverride's are not serialized to disk unless you save it as JSON or some such yourself
literally what im doing...but removing a saved one doesnt work
and thats not even what i was talking about, but whatever
lol sorry, question wasn't totally clear
are you saying RemoveBindingOverride doesn't actually remove it? or just that the old binding doesn't work when you remove it?
also 1.0.2 or the newer preview? (1.1-etc)
1.1 prev 5
for the saving, but putting that aside
i rebind a key like this
and then remove the bindings cs if (inputAction.bindings[bindingIndex].isComposite) { // It's a composite. Remove overrides from part bindings. for (var i = bindingIndex + 1; i < inputAction.bindings.Count && inputAction.bindings[i].isPartOfComposite; ++i) inputAction.RemoveBindingOverride(i); } else { inputAction.RemoveBindingOverride(bindingIndex); }
like this
but when i load up a saved binding from a json
for example if i changed the running from shift to V
in the next run of the game, both V and shift will make the player run
even if i do RemoveBindingOverride on it, it will still have both of the keys set as the running ones
actually even without restarting the game and loading from json it seem sthat it will still use the set key alongside with the original one 
Hello
Could you help me to press a button in unity and an image appears
@west oracle yeah so even without using load or save from json, the override key is still being used alongside the default one after pressing reset
went on to use RemoveAllBindingOverrides instead and i think it works now, which is extra weird
still doesnt seem to want to consistently reset bindings though
have you tried enabling/disabling the affected action after removing the bindinmg?
i do remember some quirk about that being necessary if you were only removing a single binding - I don't think it ever became a proper bug report tho
the action is disabled during the binding change
enable/disable then
basically actions get bound to "Users" and its a hairy process that does it
u cant actually rebind an action that is active, it yells at u
yea
give the enable/disable a shot for now
i'll take a closer look at it w/ the new Preview 1.1 packages a bit later today
action.Enable();
action.Disable();
action.Enable();```
what i still dont understand very well is composites
i know it sounds dumb
anyway, i have no idea what they did w/ that system in previews
yeah that doesnt work
but in 1.0.2 it was just borked thoroughly
im doing a similar thing already
i ended up writing my own override/binding system

yep
i wished they put a bit more thought on this input system
Rene-Damm straight admitted on forums my way of dealing with the "Generate C#" thing was something they'd actually consider adopting
it certainly has potential
yea - its so close in many places
especially since the old input was bare-bones as hell even for early 2000s games
i just dont like that most of the properties and fields it uses are strings
i feel like that would hinder performance
99% of them get converted to objects
the profiler also had some extremely derpy looking call for the mouse
where it goes extremely deep into callbacks
yea - i'm neck deep in a project right now involving high end haptic response devices
still slower than just values though, no?
so i'm struggling on whether to use Unity InputSystem at all or just put it in a background service
that can have reliable polling
TL;DR the thing is strong enough to break your wrists and I don't trust Unity lol
like a triggered event
Actions are very nice - yea
so you can just straight up remove update methods in a lot of code
what i need
^ being able to override inputs like this is a huge plus too
is a competent video explaining composites, how they work, and how to use them
lol, i should make one
heheh
have you gone thru my inputsystem vids yet?
which one is marked "isComposite" and which "isPartofComposite"
nice, ill check it out when im not lazy 
i apparently cut my index finger somehow on the keyboard today
fo sho 😛 i made them in context of "I'm a coder that knows how to use old inputsystem"
good job 😛
i barely used the old input
#hazardpay
haha
i just finished assembling most of a flightsim chair
but yeah, old system ,most of the functions i just ended up making my own
dangerous
tell you whats most dangerous though: assembling a cabinet alone
those "one hour to assemble" notes in the manual are an absolute lie
anyway, c heck this out too
there's a more updated one if you want to poke at it, but it approaches rebinding very differently
ah too many stuff 
but...in a sane way that supports local multiplayer with strongly typed classes
have funt rying to get the mouse to behave 😛
oh u mean the random spazzing out it does?
nah
old input system didn't do anything intelligent
new input system does too much
how come 
so you have weeeirrrddd deltas
TL;DR though I suggest you handle input inside FixedUpdate
instead of Update with new inputsystem
(you can force it to poll only inside of FixedUpdate with a pref/setting or poll it manually)
ive actually handled mouse input inside fixed update always
but some people here told me to do it differently in the new input
Praetor? 😛
have fun
private void OnUpdate()
{
Vector2 look;
if(rawInput)
look = GameManager.Instance.Inputs.Player.Look.ReadValue<Vector2>();```
yup, just in Update
oh wow the whole action's binding including part of composites counts into the bindings count 
@west oracle well, i found out why its getting the part of composite and not the composite, and how to compensate; for some dumb reason they ended up having the action.bindings include literally everything ,including the bindings inside a composite, and the composite itself; and since i grab the first binding part inside of a composite, i just return the index by once to get it's actual composite
bindingIndex = inputAction.GetBindingIndex(InputBinding.MaskByGroup("M&K"));
while(inputAction.bindings[bindingIndex].isPartOfComposite && bindingIndex > 0)
{
bindingIndex--;
}
isComposite = inputAction.bindings[bindingIndex].isComposite;```
honestly a very dumb way its done, but i can see the reasons
Hello !
I have an issue concerning action map switching : I have 2 actions map that both have a move action that are connected to the same method, a simple context.ReadValue.
However, if I switch my action map while pressing the move input, sometimes my character will keep moving, sometimes he will stops. It's because canceled is called on the previous action map and started on the new action map. Do you know a way that could solve this ?
Thx for reading !
PS : I use PlayerInput.SwitchCurrentActionMap to do the swaping, in case it helps.
Hi everyone, is there any "out of the box" way to implement button combos for a fighting style game? I understand how interactions work (tap/multitap/etc) but I dont see how to implement such a system using those.
What do I need to use to detect when a player is trying to use touch controls? I need some kind of event call that switches touch UI on or off
@olive loom I would probably start by checking the input debugger to see how it reacts to touches. I would guess it would show up as a input device, which you can most likely check the status of through input system.
Yeah but is there a callback that is being called when an input device is changed?
InputSystem.onDeviceChange seems to just default to Gamepad and thats about it
onscreen gamepad 
Do i need to use this one instead?
it doesnt stop using either of them though
when i go back to keyboard
I cannot figure out how the heck to enable my touch input UI only when attempting to use touch...
Hi, I was wondering whether it is possible use a variable in unity as an input into steam games (so emulate a controller which steam can recognise). I would really appreciate if someone could point me in the right direction for how to do it. Its for an arduino project, although im using unity to process my data. Many thanks!
hey all, im a newer developer trying to design a fighting game style input, wherein each direction is mapped to a number, then on a button press the attack checks to see what the last three numbers in the list were, for example, a stick starting down and rolling forward is a quarter circle forward or a 236.
This all works perfectly on keyboard because each direction can only be called once because WASD are buttons
but upon switching to controller i run into the issue that ever tiny micro angle of the controllers left stick, starts a new input action, resulting in the action of pressing down, filling my list with 2's where it should only input one
until the stick returns to neutral and then pushes down again
any ideas or fixes?
thanks in advance
ideally i dont want to seperate out code for inputs based one one method or the other as everything is based around input actions
@weary orchid dead zone
and a system that waits for a certain direction to stop registering before it can be registered again
the issue im finding is that each tiny little slightly different angle of "down" or (0,-1) can start and stop an entirely new input action even though its the same action and under a normalized vector 2
oh boy
my apologies, i dont understand
admittedly, I'm not experienced with the new input system
what i need is to declare that any angle within a certain realm can only be called once before the stick must reach a new, different angle, or neutral
but with my controller it seems to have say, 30 different spots in each angle each decimally different, even under a normalized vector2 they still cause a call and cancel
yes
could i do that with deadzones?
correct, combination angles are covered in my script, not that im opposed to reformatting
would bottom left be (-1,-1)
yes
so you already have it so that any value where, say, the x is greater than the abs of y is right, etc?
With the PlayerInputManager to spawn in players, is there a way to send a message to the player that gets spawned? I want the player to know which player number it is so it can show the right color
The prefabs you spawn with PlayerInputManager should have a PlayerInput component on it
the PlayerInput component has a playerIndex or something like that
@crisp gyro i used a vector 2 for my movement, but the command inputs are handled by the input of say "LeftStick - Right"
ok, so just to be clear
your ploblem is that LeftStick-right is being fired multiple times in a row even if the player isn't moving the stick?
ploblem
pretty much, when they push down, the controller has, for example, 10 angles that send the input of, down, this means that when pushing the stick down, tiny micro adjustments in the "down" area of the input, causes multiple fires
Ah, I see. I had named my Input asset PlayerInput not knowing that was a thing, so I didn't find anything on it when I checked it. PlayerIndex does indeed solve my problem
ah yep - pretty common occurrence
I would say make it so that the event fire doesn't directly get inputted to the list
only put it in the list if the previous event called was a different direction or (0,0)
right?
Is there a way to change where the PlayerInputManager spawns players or do I have to do that after they're instantiated?
hopefully that wouldnt even affect buttons
yes, but, what if they return to neutral, and then do it again? which i cant seem to get to be its own action
You know I've never actually used it 🤔
yup
uhhh
6,5,6
as long as you can detect the neutral
which i cant figure out how to do
same
cam't you do the poopy way and read inputs every frame or something
you can detect neutral by listening to the canceled event on the InputAction or by simply polling the value each frame
I think that fires after they're already spawned, but I could go test that, but what I really should do is code my players in a way where colliding for a single frame doesn't break everything
that would be awesome if that works
canceled doesnt work as each micro angle performs and cancels
I'd just use a Vector2 composite rather than having different bindings for each direction, and do the math to figure out which of the 8 or 4 directions it's in myself
yes
that detects the new current vector2?
so say you let go of the stick
on the way back to neutral, it fires and cancels the microangles or whatever
eventually when one is cancelled, the vector will be 0,0?
sounds suuuper messy
i may have to just check the vector 2 read and then only allow a given direction to fire once, until a new direction or lacktherof has been done
basically yes
messy, but potentially the only way with the hole ive dug myself in
i will try tomorrow and check back in
I cant think of a better way rn
seems like gamepad is just plain hard to work with in NIS
will do
Input.location doesn't have all the info available in iOS' CLLocation - in particular, CLLocation.speed. Is there any recommended way to get the speed from Input.location in a way that's more stable than finite differences between samples?
I know that there are multiple ways to handle input with the new system. (Input Action Assets, adding input action variables, and directly coding the actions.)
What is the best way to do this. (The one that would fit most projects.)
There's no best way!
The best way is the one you're most comfortable with and works with your project
If you ask 5 different people they will tell you 5 different "best ways"
for example the best way in my opinion is to use InputActionReference directly in scripts that need input
I would say that hooking to PlayerInput component with Unity Events is the best way to get the most of the new input system for the least amount of effort.
If you feel like you are limited by that setup for some reason, you can always peel the PlayerInput/PlayerInputManager layer back and do it yourself. Both of these rely on the public API.
Is there any easy way to check for a key/button/click with the new inputsystem? Kind of how you do the PerformInteractiveRebinding()?
I have a textbox and would like for it to listen if a specific "next" key/button was pressed to continue.
you could subscribe to this event: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_onActionChange
Then check if it's the InputAction you care about and it's the ActionPerformed that happened
Been watching a bunch of tutorials on the input system
Gotta be honest I just cannot wrap my brain around what is going on
If only I knew what questions to ask

I've been documenting my experience on this repository, might have some answers you need
https://github.com/alexandervrs/Snippets-Unity/blob/master/InputSystem.cs
@random geode There are examples bundled in the Input System package, they can be installed from there in the Package Manager.
Yeah I gotta be honest I'm lost
I can't really understand how it is able to differentiate between different controllers
The input system manager that just spawns in player prefabs is okay until you want to have a second player take control of a character that already exists
Had a bunch of great momentum in development but it all just ground to a halt

Now you can't even control one player
There seems to be a lot of hits explaining the problem on "unity input system multiple controllers" search.
Multiple controller support versus multiple controller simultaneously support
Like it's one thing to be able to support multiple controllers, but another to support multiple controllers at the same time
For local multiplayer
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/UserManagement.html
Take a look at the "Initial engagement" section and InputUser.AssociateActionsWithUser in particular.
That seems to be the key to separating controllers.
So, I am trying to make a rebindable key system. I followed a video and now am starting to redue my code to use that new input system (not unity's system). here is the code form my car input handler (https://pastebin.com/qv8T5zc2) (I slipt my scripts up so I don't have like one super long script. Problem is that now I get this error (CS0029 C# Cannot implicitly convert type 'bool' to 'float') how do I fix it?
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.
I'm getting weird errors too
Unrelated thing entirely
But also getting weird errors
If I press WASD on keyboard I get these errors, yet the input still goes through
But if I execute the same command on controller, no errors
@cerulean shoal Does it reference a line in your code?
Yeah, guys I have no idea what the issue is
I have a Player Input Manager spawning in player prefabs
But for some reason the first player prefab I spawn in throws up two errors for every context phase
But it still executes the code just fine
The second player prefab doesn't throw up any errors
And also executes the code just fine
The line of code it is referencing as an error isn't looking like an error to me
Basically this is just "tell the player you're attached to tell us what input you got"
And it does that
But not before throwing two errors
The actual AnnounceInput method is even simpler
So I have no clue what's actually the issue
Hey there, could anyone help me with this FPS camera? I've checked many different tutorials but for some reason the camera is always snappy like this.
Here's the code:
private void Awake()
{
if (!camera)
camera = GetComponentInChildren<CinemachineVirtualCamera>();
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
cameraPov = (camera.GetCinemachineComponent(CinemachineCore.Stage.Aim) as CinemachinePOV);
input = new PlayerControllerInput();
input.Gameplay.CameraRotation.performed += RotateCamera;
input.Gameplay.CameraRotation.canceled += RotateCamera;
}
private void RotateCamera(InputAction.CallbackContext obj)
{
cameraRotation = obj.ReadValue<Vector2>();
cameraPov.m_VerticalAxis.Value -= obj.ReadValue<Vector2>().y * cameraSens * Time.deltaTime;
transform.Rotate(0f, obj.ReadValue<Vector2>().x * cameraSens * Time.deltaTime, 0f);
}
If I remove the delta time multiplication, it (sorta) works, but then the camera rotation would become frame-rate dependant. Is that expected?
This must be a bug with Unity at this point
The player is getting defined but Unity is still reading it as null somehow
Fixed by just doing an if(player != null)

Oooookie doke
Input system is driving me nuts
Any ideas why the Player Input Manager is indicating that a controller is active RIGHT after I press play?
It only happens in this project
I tested in another project and that does not happen
It's set to "join players when button is pressed"
But I can't get keyboard to join because (and I'm only guessing here:) the keyboard controls are already being taken by something
Never mind
Turns out I had another Player Input on something I should not have
My posts here are seriously a crash course in what not to do
Haha
i cant figure out how to use input system cause the controls they change in tutorials look different in my menus
maybe the tutorial is too old?
2 weeks old ;-;
i got the new input yesterday but i wouldnt assume they update that fast
what part is not fitting your setup?
And what are you missing? like whats the tutorial refering to?
the "player" thingy doesnt have it
How do I run my script in unity? I have created a script but nothing pops up in the console
i dunno where this would be
When I click play
wrong channel, but attach your script to some object
I guess its the Action Events
Oh sorry, but thanks
i dont think it is unless it wants me to do it manually
What do they put into that player events?
the player thing has the thing i need to write the code
i think ill just mess around tomorrow cause its too late for me lol
Yeah, you better fix your terms, so we know wha tyou mean 😄 Still thinking, its the action events you can use to mimic what player has done, but dont know the tutorial, dont know the scripts 😄
yea its kinda annoying that literally every tutorial or guide or anything is different but ill figure it out eventually
i cant use terms if i dont know them as well btw
the tutorial is doing something with that player, and it is obviously not "the thing I need to writhe the code" 😉
it is the thing i needed to write the code, all i have to do is get it from somewhere else instead now
thats what I mean with terms, i needed to write the code, that is not even a sentence. No offense, but we cant help, if you dont give more information. What is the player doing in the tutorial, what is the tutorial doing with it, do they open it and show whats inside, is it a script, is it an array?
they take the words that appear when they click player, and use it in some lines of code. how else the hell do i describe this
what does player look like if the click it?
bro whatever i already said im done
alrighty, see ya
Hey, can you show your AllInput asset window? The action map place?
I went through the same bug, I had to restart Unity to get my control maps on that component (also re-added the component) I am confused about action events though.. seeing that for first time (most likely this is because you switched from normal inspector to debug inspector)
is there a way i can allow players to bind the mouse wheels to jump
like you can do in quake where you bind mwheeldown to +jump
Any recommendation tutorials for the new input system using c# and not the player input component? im quite new to unity. thank you in advance.
Anytime 🙂
Could really use some help with creating an Input system, at the point my codes at I should be able to move my character around when I hit play, the issue is they remain frozen in place and nothing happens, I do have a rigid body and a collider setup, I am getting an error on the Unity console, a NullReference exception, images of it, the code, and my Input Actions have all been included in the below link, if anyone can help it'd be amazing because this is driving me crazy.
https://docs.google.com/document/d/1z0knZhNd_EsyE-zcTacNzVPR5JNJNIoQFaQ2k_QrVPA/edit?usp=sharing
please don't share code on google docs T_T
#854851968446365696 has a list of much better sites for sharing code
cameraObject = Camera.main.transform;```
you simply don't have a camera with the tag "MainCamera" in your scene
Adding the camera got rid of the errors, but the movement still doesn't work, sorry about pasting the code into the word document as well
So checking the Input Handler script during play, my Keyboard Inputs are being detected, it's just not moving my character
is your rigidbody dynamic?
(not kinematic)
i dont see the Delta [Mouse] that are in most tutorials anyone help?
nevermind i found it
Hey, I have been having some trouble installing the input system package. My IDE marks "using UnityEngine.InputSystem" as an unrecognized namespace and my project won't compile
I have tried:
- Regenerating project files
- Reinstalling package
- Committing to repo then regenerating files
- Updating IDE interface package
- Switching from VSCode to VSCommunity
- Updating .net framework/SDK
Does anyone know any other things that would prevent the InputSystem from being recognized?
Are you using asmdef files in your project?
I am! I have some for linking to test files.
What am I doing wrong? The method never invokes
public void Click(InputAction.CallbackContext ctx)
{
Debug.Log("aaaa");
}
It works in update like that:
private void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame)
{
Debug.Log("update");
}
}
But not from the player input
Figured it out :P
You have to add the devices to the control scheme otherwise they won't get seen
Would I ask about this here?
I'm not sure what to make of this, I'm not very deep into the new input system, but maybe someone here has seen this before?
searching the web for it now.
I get those all the time for all kinds of packages. Just ignore them.
I see.. The inputs are still not working though.
In what way are they not working?
Its supposed to be connected to a script that applies force to a playerobject.
This script in the tutorial I'm following seems correct.. but the player input is not doing anything
Can you show the relevant code?
Isn't that causing a compiler error since movementValue isn't defined?
I didn't know to use this little circle dot thing to apply the actual input @blissful comet
Would someone be able to get in a VC with me and help me with something? im trying to port this mobile unity game to a different platform and ive never worked with unity before
aight that'll be my next read thanks. Wow that was a phenomenal link, t hanks.
How do I override the methods of the new UI Virtual Joystick?
I get this error:
cannot override inherited member 'UIVirtualJoystick.OnPointerDown(PointerEventData)' because it is not marked virtual, abstract, or override [Assembly-CSharp]
C# methods cannot be overridden unless they're virtual or abstract.
Since that method is not either, presumably Unity did not intend for it to be overridden.
Thank you. That helped. I marked it as virtual instead and made it ‘new’ and it worked
I… don’t know if that will cause problems in the future but we’ll see
Hey y'all, I am seeing something strange in the Input Debugger trying to get a Super Famicom pad working through a USB adapter.
All of the buttons appear to be accounted for, and when I press the X & Y buttons I see event happening, however...
Value on all buttons stay 0 in the middle pane
Other buttons toggle 2 different button values to become 1
That's with just the B button held down
It's a real problem because I seem to be unable to create bindings using certain buttons.
In the test tab of the Windows Game Controllers properties window the inputs are all coming through properly (1 to 1)
Any ideas? Feels like Unity has its wires crossed on a few buttons somehow... 🙃
Okie doke, I searched and couldn't find an answer. The dang Input Action thing will only register one keypress at a time. Example: Holding A, hold F, release A, A action still hapening. The F doesn't even register. I'm following an in depth tutorial exactly so I know I've not done anything wrong.
whats your code
and before that?
sorry didn't know you'd want that
It's a value / vector 2 action mapped to 2D Vector / Digital Normalized WASD
you don't have to set each value of the vector like that, just do moveVector = context.ReadValue<Vector2>()
(this won't fix your issue, just simplify the code a bit)
i just noticed you are setting the z value to y so never mind, my bad
@deft berry It'll automatically translate XY to XZ?
ignore me, i misread it lol
but you should show all of the code, not just snippets like that. Use a paste site like one of the ones in #854851968446365696
I would have if it were more than like 10 lines lol.
is there nothing else in that class besides the two methods you've shown and the class variables?
It's commented out at this part of tutorial
the person is going through 'Player Input' Behaviours
well you're not providing all of the context so how are we supposed to help you?
yeah, we need to see your inputsystem mappings, check how are you debugging, check the context of your actions, etc
~~for the record, unity inputhandling is still atrocious and I would heavily suggest getting some alternative like Rewired lol ~~
you don't need that "Press" interaction
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.
at least not for movement
I understand.
You're also only using two values of the moveVector, so why not make it a vector2 and just set velocity.z = moveVector.y.
I'm pretty sure the issue is the Press interaction actually because it does not use the canceled callback. (someone can correct me if i'm wrong on this)
I found this farther up, same issue
#🖱️┃input-system message
I'll check into that idk
took off the interactino and it didn't fix it
:/
well this is beyond insanely stupid.
After wasting most of today I reverted to old input system. What an awful experience.
can anybody tell me how to make a keybinding system?
As it happens, I wrote up a doc on how I implemented mine several years ago. Note that this is not necessarily the best way to do it, and you may find better success using a plugin, or just using more up-to-date Unity input methods, but it works (so far) for my purposes (Which is a 2D sidescroller).
If you're interested you can take a look
https://docs.google.com/document/d/1NPWXnFNbLgoJf_fx_4Qbu_QRpF76n3QqCjXy9xVfj6g/edit?usp=sharing
Unity3D - Key Bindings Tutorial Charlie McFadden - 26/09/2015 charlie(a)pleasewearahelmet.com reddit.com/u/handsomecharles Introduction Hello! My name is Charlie, and I’ve decided to write this tutorial to attempt to help those who are finding Unity’s default keybinding solution a tad “inflexib...
Also it might be a bit out of date in relation to UI, as I wrote it six years ago 😂
Still works in my 2021 project though
ill have a look tnx
I'm developing for XR and for some reason all the buttons except "menuButton" are functional. Ideas how could I debug what's going on? I wonder if some asset I'm using (like auto hand) is overriding something crazy, but have no idea how investigate it. Tips?
I remember seeing some sort of button mapper dialog but of course can't find it anymore...
Ah, XRI Defaut Input actions was the dialog. But unfortunately adding a menu button does nothing.
Humm, I may have the new input system and old direct XR code conflicted.
Solved. Misleading tutorials/forums got me side-tracked. Rewrote the entire script with the new input system and it's now working.
How do i use the Input System? (My Unity version is 2020.3.16f1)
Unity has an extensive tutorial on it on their YouTube channel.
i'm trying to make it so when my stick is over 40% of maximum distance pushed it counts as a sprint instead of a walk, i set the deadzones to Unity Minimum to 0.401, and 4.02 to Unity Maximum so the deadzones dont overlap, but my character just walks no matter how much my stick is pushed...
Anyone have any clues?
The code receives it via:
// set target speed based on move speed, sprint speed and if sprint is pressed
float targetSpeed = _input.sprint ? SprintSpeed : MoveSpeed;
public bool sprint;
public void OnSprint(InputValue value)
{
SprintInput(value.isPressed);
}
public void SprintInput(bool newSprintState)
{
sprint = newSprintState;
}
You don't need to do anything fancy like that, just take the movement input as normal (Vector2 data), and check the magnitude of that vector. If it's greater than 0.4f, then you're sprinting.
This is from the Unity Starter Assets 3rd person Character Controller (asset store), so was trying to keep it true to it's own setup, but i could give that a shot (still pretty noob at coding)
Hey, anyone know how to detected whether a keyboard or a controller is being used using the new unity input system?
like if the player is using a mouse, I want to do one thing with the mouse's position vector, and if the player is using a controller, I wanna do another thing with the controller joystick vector
solved
Hi all, I'm using the new input system and I'm trying to implement the example shown under "Polling Actions" here: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Actions.html#creating-actions
//public PlayerInput input;
public InputAction moveAction;
public float moveSpeed = 10.0f;
public Vector2 position;
void Start()
{
//input.Enable();
moveAction.Enable();
}
void Update()
{
//var moveDirection = input.OverworldActions.Movement.ReadValue<Vector2>();
var moveDirection = moveAction.ReadValue<Vector2>();
position += moveDirection * moveSpeed * Time.deltaTime;
}
The thing is that I already have an InputAction setup that's being used by my Cinemachine camera and I want to use that. I generated a C# script for that InputAction but I get an null reference exception (Object reference not set to an instance of an object) when I try to use it to assign a value to moveDirection in Update(). The commented lines were my attempts to refactor the code for my usage. Is it better to have multiple Input Actions all handling separate things?
TLDR; How to poll using existing InputAction?
Hello, your moveAction is drag&dropped from the unity editor and it still throw a null ref exception ?
are people doing more than something like this in their input system functions?
public void Move(InputAction.CallbackContext ctx)
{
moveInput = ctx.ReadValue<Vector2>();
}
I feel like the heavy lifting needs to be done in update functions. maybe this applies more to physics related stuff
Not doing much more, I try to get less as possible code in these functions and invoke events when needed
Do you guys know if it's possible to get a UnityEngine.EventSystems.PointerEventData from the InputAction.CallbackContext ?
I can't seem to drag and drop it.
I had something like this before but I couldn't figure out how to do continuous polling for movement. Everytime I held W I would move one unit and then stop until I pressed W again. I tried using Google and came across the docs I linked above which was using it in the Update method
Use InputActionReference instead of InputAction to refer to an InputAction in an existing asset
You can also use something like this ;
this.PlayerInputs.actions["nameOfTheAction"]
If it's mean to be done in code
You can but it would be kind of silly because then you're just using the PlayerInput component as a proxy to reference the InputActionAsset, which you can do directly by having an InputActionAsset field or an InputActionReference field in the script.
I'm looking into your suggestions, thank you!
I've implemented a jump script but when i hold down space the jumping feels choppy its almost not visible on the way up but its very visible on the way down. Does anyone know a fix?
https://pastebin.com/8FEf39tK
https://gyazo.com/4110b3936409a6825b3034bf87a1bff4
your jump code just... teleports the object up by a certain amount each frame
I'm presuming you have a Rigidbody or some other code pushing the object down
I do yeah
so naturally on the way down your jump code is teleporting you up... fighting against that other stuff
and it looks like that
Are you using Rigidbody?
yup
The way to jump with Rigidbody is typically to use
rb.AddForce(jumpForce, ForceMode.Impulse);```
you want to work with the physics engine, not fight against it
Ok thanks, I kinda just used what i used for movement and thought it would work the same
if you're using translate for movement with a Rigidbody you're also... doing that wrong, hate to say it
oh, should I be using addforce for that as well?
I'm only recently getting into programming and the tutorial i found said to do it that way
it's fine for a "this is your very first script" kind of movement, but if you want to get something working with physics and collisions etc you need to use either a CharacterController or a Rigidbody and move via methods on that
ok, tysm for the help
How do i access the value of Movement? i tried controls.Game.Movement.ReadValue<Vector2>(); but i get a "Object reference not set to an instance of an object" error
whatever controls is you didn't instantiate it
seems like you're probably using the generated C# class file
you need to use the new keyword to create an instance.
did you enable it?
how?
.Enable();
Thanks, it works now
Still don't understand why my azerty keyboard is working as a qwerty one
Looing through EventSystem, PointerInputModule, GraphicRaycaster, PhysicsRayCaster. I keep thinking this can't possibly be the right way to separate these. Why is the camera attached to the canvas/raycaster? What if the same canvas can be seen by multiple cameras?
Trying to figure out if I can make UI canvas elements work inside a VR app, with a laser pointer attached to the player's hand
The camera shouldn't be attached to the canvas
GraphicRaycaster goes on canvases.
PhysicsRaycaster goes on cameras
GraphicRaycaster has an event camera field iirc
Canvas has an Event Camera field.
Ah canvas then
pls help
The strange part is that the events that I would want to send to the UI (e.g. OnDrag) send events with coordinates in screen coordinates, rather than world (or relative to the canvas), so I'd have to fake this somehow.
Is C:\Users\CFS a valid path which you can write to?
idk
how
Under the "Location" field there are three dots to the right. Click them and select a different folder.
I don't think there should be permissions issues but it's easy enough to check. Try pointing it to your Documents folder or something
How do I get the instantiated prefab from the PlayerInputManager.playerJoinedEvent callback?
It gives you the PlayerInput component from the instantiated prefab doesn't it?
Yep, but I want the prefab.
That's just a config object right?
Basically I want to control the instantiation myself.
And set up the colors etc.
(Whoever just had their message deleted it was because there is a bot that deletes anything with repeated characters)
That's the prefab
right
Sorry, I mean a reference to the instantiated object.
I'm confused
I mean, what I really want is a player joined event
That doesn't create anything
Or... instantiates the prefab and tells me about it
This second one is the one that you get
YOu get a reference to the instantiated prefab in the event
yeah - it gives you the PlayerInput component of the newly instantiated object, no?
oh... oh whoops!
Ok so
I thought it was a reference to the SO
the one you linked
Okay, cool. I'm silly.
is a UnityEvent
Beautiful.
np
Did you name your InputActionAsset "PlayerInput" 😼
No haha, just new to this
👍
yep
cool let me play it when it's playable
Client work
ah damn
idk how to do this pls help
that is the most vague thing ive ever seen
What do you exactly want to do?
if (Input.anyKey)
{
Debug.Log(Input.anyKey.ToString());
}
Hello, i want to detect what key i am pressing, but now it debugs true. Does someone know how?
Input.anyKey returns a bool
Not sure if the old input system has a true "return any key pressed", there is a https://docs.unity3d.com/ScriptReference/Input-inputString.html for keyboards though.
It can return multiple keys on the same frame though
https://issuetracker.unity3d.com/product/unity/issues/guid/1353866 Don’t know if there’s rules against posting links to issue tracker but in case anyone is having issues with the input system and has no idea why… I went through the pain of being absolutely certain it was an issue with the input system, it’s active now
How to reproduce: 1. Open the "case_1353866" project 2. Open the "SampleScene" Scene 3. Enter the Play Mode 4. Tap Spacebar or Down ...
ive looked into this before, from what i saw in the old input system you litterally have to check every keycode to see which one is down lol
Anyone have issue with touch and SLIDER?
If using the mouse the slider behave normally.
However if I use touch, the handle get selected but only move a little, not following the touch
code
Are there any tutorials you're following? There are a tonne of great intro resources
But you can create new scripts by right clicking in the project window and then under "Create" there is an option for a new script
yes
Can I rebind keys during runtime using the C# generated class? if yes how? if not, how can I rebind things like 2D vectors for movement?
Ok I found the issue with Slider...
Now... anyone have issue when using touch with data being sent to mouse also?
Can't seem to get unity input system to work
literaly nothing happens
I can't even print to console
ive tried about every single setting
invoke unity events, send message
restart unity
button, passthrough mode
Vector2, etcetc
making player a prefab instead of a object
There are many ways to use the new input system, and all of them work a bit differently.
Hard to say what you did wrong
I'm following a tutorial that's telling me to use the "player input" component with the input action
It seems that PlayerInputManager is immediately deleting one of the player prefabs after creating it. Is this a thing?
oh worked it out. What a dumb thing. It calls DestroyImmediate if there's no input device
What a pain in the arse
DestroyImmediate too, which is against Unity guidelines
So I have a game manager object that needs to know of the inputs when a new player joins the game. From what i've seen, I have to have the Player Input component on the Player Character prefab, and can't like programmatically control the events from the Game Manager, so it's aware of Player 1 and Player 2's inputs? or am I thinking wrong, and it would be easily possible?
You can call for public functions on another script by referencing it with a variable , or GameObject.Find()
public GameObject anObject;
void Update()
{
anObject.function_name();
// Or if you don't declare it,
GameObject.Find("GameObject name").function_name();
}
i'm trying to use unity's new input system and i did similar to their official video but when moving the callback is only called once, it doesn't hold ?
you're being very vague, but generally the performed callback for an InputAction only happens when the actuation of the input control changes
In this video, we are showing you how to create a cross-platform character controller using Unity's Input System!
Download this project here:
https://on.unity.com/39WT0iv
For more information about the Input System - click here!
https://on.unity.com/2MJnzj2
Chapters:
00:00 Intro
00:29 Input Manager
01:10 Installing the package
01:34 Using th...
sorry
i have the same function and set up
as him
except his works fine
he shows an example of him moving it around
when i try to move, or even log the function call
if i hold it
you'd expect multiple logs right
i get like 2
His doesn't get called multiple times when he holds it either
there's no expectation of multiple logs
oh how is his moving then
he's writing to this rawInputMovement variable
and using that variable to move the character
so if there's no further calls it continues to use the previous value.
okay i seeee, is there a way to have it act the way i want to or do you recommend just writing the code to make it work like this
the latter
If you want it to work the way you're describing you're better off just reading the current value of the InputAction in Update() and throwing out all the event-based stuff
sort of the same style as reading Input.GetAxis in Update() in the old input system
which, by the way, is a perfectly valid way of using the new input system.
i assume the new style of doing it would be a bit more efficient though right?
It's not really about efficiency
The main benefits of the new input system are:
- Better support for input bindings and different controllers
- Better support for rebinding controls at runtime
- Better support for local multiplayer
- More options for input including polling, event-based, generated C# file, PlayerInput component, InputActionReference and so on.
why do I have 2 users with keyboard 2?
I have one player with keyboard 1
and another with keyboard 2
only the keyboard 2 controls work
and they only control one player
Hey, you mentioned "polling" here... So we just burned like 6 deveoper hours trying to work out how to poll a button (resulted in not being able to implement jump). After a deep dive in to the docs I have come up with this idea... Does this look right to you?
PlayerInput _playerInput;
InputAction _jumpAction;
InputAction _fireAction;
void Start() {
var map = _playerInput.currentActionMap;
_jumpAction = map.FindAction("Jump", true);
_fireAction = map.FindAction("Fire", true);
}
static bool IsDown(InputAction action) => action.phase == InputActionPhase.Performed;
static bool IsUp(InputAction action) => action.phase == InputActionPhase.Canceled;
void FixedUpdate() {
if (IsDown(_jumpAction)) {
// Start jump
} else if (IsUp(_jumpAction)) {
// Release jump
}
not really no. More like:
static bool IsDown(InputAction action) => action.ReadValue<float>() != 0;
static bool IsUp(InputAction action) => action.ReadValue<float>() == 0;```
the phase will only be performed on the first frame that you press the button
and any frame that it changes value while being not 0
thank god
Why do they not include this in the docs
I also saw some of them doing FindAction("*/ActionName") or similar
the thing is - it's only correct if you're using a control type: button value type: float input action with the default interaction (no interactions)
I don't understand this sentence
Too many colons hahah
the way performed and canceled work depend on the interactions you're using
oh, right
Sorry, these are field: value
So there's something wrong with the abstraction layer?
is this not working?
not sure, it's not my task. my colleague just got flustered and went home
ah
so I'm trying to give him some help so he doesn't spit the dummy when he gets back to it
But like... there must be a way to get values out right?
what is the point of the thing
spit the dummy?
heh
Didn't realise that was an australianism
Anyway usually for GetKeyDown/KeyUp situations I would just go event-based
this is actually risky in FixedUpdate for the same reason GetKeyDown/KeyUp are risky in FixedUpdate
So if we put it on a shoulder button with a variable input it won't work?
It can if you use a press interaction
ah, that's okay.
You set an actuation point
Yeah, that seems sensible
Basically we just need to do this:
var input = new InputFrame {
isJumpDown = // ...
isJumpUp = // ...
horizontal = // ... float thing here
vertical = // ... float thing here
}
So doing that with events is not trivial at all
Also... the order of execution of events is not clearly explained... what if it happens after our script for example?
We'd have a one frame delay
Using events for input seems like a terrible idea to me, maybe I'm missing something?
Hi, Here is my problem can someone help?
When people use Unity's new input system do they still use the update method for movement?
or do they use the event functions?
a little of column A, a little of column B
what does this have to do with #🖱️┃input-system ?
Does it make sense for a 2d platformer to have character movement be implemented under .performed?
For my little game I have the .performed starting a coroutine for movement and while the movement key is held down a loop in the couroutine keeps going.
not really, as I mentioned above performed only generally happens when the actuation of the input device changes
so if you're just holding the D key for example, you will only get one performed event
You could certainly generate an input vector in performed
and then use that vector in Update() for movement
you'd have to also listen to canceled to detect when the button/joystick is released and reset to 0 though
Right now performed starts a coroutine that has a loop while keeps going while a bool movementIsHeldDown is true
then canceled sets that bool to false
why not just use Update
that sounds unecessarily complex
to avoid the overhead?
haha probably is. Came back to Unity after awhile of not using it and watched a video of the new input system. The video showed the use of the Event methods.
and I was trying to figure out how I could get my character to move while holding down the key rather than once
but I sometimes get a bug where my player gets stuck. It works 99% of the time but certain movement cause the object to stay still.
so I was thinking doing an implementation with update may fix that.
jw what people usually do and how the new input system is usually utilized.
Vector2 input;
void OnEnable() {
movementAction.performed += HandleMovementInput;
movementAction.canceled += HandleMovementInput;
}
void HandleMovementInput(InputAction.CallbackContext context) {
input = context.ReadValue<Vector2>();
}
void Update() {
transform.Translate(Time.deltaTime * input * speed);
}
Sometimes I do something like this^
but it might be simpleer to just do this:
void Update() {
Vector2 input = moveAction.ReadValue<Vector2>();
transform.Translate(Time.deltaTime * input * speed);
}```
Honestly I think event-based handling is much better for something like buttons
rather than a continuous thing like movement
Gotcha, yea I think im getting weird bugs just because of the nature of performed and cancel lol
e.g.:
void OnEnable() {
jumpAction.performed += Jump;
}
void OnDisable() {
jumpAction.performed -= Jump;
}
void Jump() {
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}```
that works fine
only thing with movement is when I hold the key down I used a coroutine.
Jump would work fine since its typically only pressed once.
Thanks, after thinking about it and then reading your reply, I realized that'd be the best course of action atm. Just an FYI btw, don't use the GameObject.Find() in an Update function.
Hello!
I'll try to be as succinct as possible.
•Pressing an action key will trigger my code on press and upon release.
•This happens when no interactions are set (default == press only)
•This happens when explicitly configured to Press Only
•I am using the Player Input component and OnAction(InputAction.CallbackContext context) functions (see example below).
So, if triggering this function would print "Attack" twice - once on press, and once on release.
public void OnLightAttack(InputAction.CallbackContext context) { print("Attack"); HandleLightAttack(); }
Any help would be appreciated!
You need to check which phase you're in
if (context.performed) {
print("Attack");
HandleLightAttack();
}```
you will also generally get a callback for started and cancelled
but it depends on the interactions you're using
to make what's happening a bit more clear I suggest doing this and playing with it a bit first:
public void OnLightAttack(InputAction.CallbackContext context)
{
print($"LightAttack phase: {context.phase.ToString()}");
}```
Thank you for the help! It sucks to suck (referring to me of course). I might need a little time to digest that.
the new input system is pretty complicated - it will take time to learn the ins and outs of it
It seems that way - starting to question if I made the right choice instead of using the old system.
Sadly, I can't seem to add the following method as an event to the Player Input component 😦 . Most likely because when it's set to Invoke Unity Events it's looking for methods that use an InputAction.CallbackContext as a parameter. Was something updated with that type to support being able to tell if the context has been updated (i.e., if the event was triggered because button was pressed down or the button was released, instead of either)?
Using InputValue is for if you're using the Send Messages mode
Also tried using Invoke C Sharp Events but doesn't seem to be any editor options when that is set
you should use CallbackContext if you want to use Invoke Unity Events
What I want is to be able to tell when a button is being pressed and when it has been released 😦
so that i know how long that it's been held down.
read the conversation we just had above
ok
Doing that and checking for performed and canceled will tell you pressed/released
Sorry, didn't notice the new posts
apologies and will check it out
Hm, so I guess I can use that for the buttons. But Directions get kind of weird. For example, if I press and hold Left (A key) it registers Direction Started and Performed, then press and hold Up (W key) while still holding Left triggers a Direction state of Performed. Releasing either will trigger a Performed state, and then finally a Cancelled state once both have been released. Which feels awkward if I want to know if Left is being pressed and Up is being pressed.
right which is why I mentioned above that events are somewhat awkward for "continuous" things like movement and are better used for things like one-off actions
So you can either use the events to populate a Vector2 variable (or bool variables or whatever you want), or simply poll the InputAction in Update to get the current value
Something like this?
//Debug.Log("Direction");
Vector2 inputVec = input.Get<Vector2>();
upPressed = (inputVec.x == 0 && inputVec.y == 1) || (inputVec.x != 0 && inputVec.y > 0);
downPressed = (inputVec.x == 0 && inputVec.y == -1) || (inputVec.x != 0 && inputVec.y < 0);
leftPressed = (inputVec.x == -1 && inputVec.y == 0) || (inputVec.x < 0 && inputVec.y != 0);
rightPressed = (inputVec.x == 1 && inputVec.y == 0) || (inputVec.x > 0 && inputVec.y != 0);
}```
- Those boolean checks are more complex than they need to be
- Why use 4 bools instead of just a Vector2?
I want to know if the button is on/off
Also, unsure how to tell the Player Input component to call the OnDirection(InputValue input) method atm...
Vector2 inputVec;
public void OnDirection(InputValue input) {
inputVec = input.Get<Vector2>();
}
bool leftPressed => inputVec.x < 0;
bool rightPressed => inputVec.x > 0;
bool upPressed => inputVec.y > 0;
bool downPressed => inputVec.y < 0;
wouldn't that work?
It will happen if you use Send Messages mode and your input action is called "Direction"
and it's set to:
action type: value
control type: Vector2
ok, sorry, i know you said that before, i just glossed over it.
and yeah i hadn't refactored the bools at the time.
the Send Messages is what I had on a previous attempt that worked, but forgot 100% how I set it up before
so at time of questioning I had it set to Unity Events as all tutorials I went back to watch said to do so
@austere grotto The subsequent question you are helping with actually found my solution by switching to SendMessage (at least for the time being). Thank you in general for being so helpful and patient, my dude.
Hi, I'm using unity input system and I'm trying to use touch delta to rotate my player(look around) but the problem is that when i use my on-screen stick which is supposed to move the player around, it also rotates the player because touch is being registered even when I'm using on-screen joystick. Is there any way i can limit the touch screen delta to read touch delta from only the left side of the screen Or avoid reading the touch when I'm touching Ui components such as on screen stick or buttons?
I'm aware of the method where we put an invisible on-screen stick on the right side of the screen. But I don't want to use it because it doesn't feel natural and smooth to me
Hi people. How can i guarantee that AxisControl always returns between 0...1?
should be a range in the settings menu for input axis
It seems they are fixed. (For the gamepad class at least)
I can't seem to find anything related to min/max values
Clamp values, perhaps?
Thank you again - understanding phases between .performed, .cancelled, etc. a bit more now!
How do I get input from a pair of XR (left/right thumbstick) as vars for this: "private void Control(Vector3 move, float turn, float[] actions) "?
it needs: "moving vector (3D direction and length), an optional turning flag, and a one-hot action vector"
Hey all, I'm just trying out Bolt.. any recommendations for tutorials/videos on how to use the new input system with this?
I managed to work out keyboard input, trying to get xbox controller working now 🙂
Hi, I have a problem with setting up my input bindings becose I have there only usages and Listen button dont works. -_-
So im using the input system for a VR based project, but every time I try to read an input action, the main camera stops being able to look around the scene / detaches from the vr headset.
The end result is that when I move my head with the headset on, the scene moves with the headset.
The script is pretty lightweight and the camera issue does not occur if I remove the script as a component of the hand controller it is added to
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class VRActionBasedControllerHandler : MonoBehaviour
{
private ActionBasedController controller;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
controller = GetComponent<ActionBasedController>();
float selectActionPressed = controller.selectAction.action.ReadValue<float>();
float activateActionPressed = controller.activateAction.action.ReadValue<float>();
if (selectActionPressed > 0.0)
{
Debug.Log("SelectAction pressed");
}
if (activateActionPressed > 0.0)
{
Debug.Log("ActivateAction pressed");
}
}
}
Does anyone have any ideas as to why this might be happening? The object that this script is added to does have an XR Controller (Action-based) component
nvm
it was because I didnt have the main project window as the active window
I had console log window active
Do someone know why? I cant find it anywhere how to fix it.
Hi all.
I have the New Input System set up, and i'm reading the Mouse Delta so I can activate a bool to say "Is Looking Around"
The problem is...mouse delta's don't register anything at all if you move them slowly, so if i orbit around my character slowly, it still registers as x0 y0 with a magnitude of 0.
Does anyone know a way around this? unless theres some sort of other way I can tell if the mouse is being used, otherwise ill probably have to ditch reading the input altogether...
This new system have different settings
What if the best for input system
Starter pack used send message
any ideas as to how one would pass in a context value such as .performed, when calling the method? for example my dash method only dashes if context is performed, but for a fighting game i need to have other ways of dashing other than the dash button, so how would i say "if (conditional here){Jump(performed)}
as unity requires a value for context but doesnt seem to accept anything ive given it
The context comes from the events themselves
you don't need to create one
yes, but what if i want to call it, without them pressing the button
void OnDash(InputAction.CallbackContext context) {
if (context.performed) {
Dash();
}
}
void Dash() {
// Do a dash
}```
Just call Dash() when you want to dash from somewhere else
does that automatically act as performed for the context?
wdym?
void Dash() {
// Do a dash
}```
there's no context
just a method that makes your player dash when you run it
How is it that the PlayerInputManager can instantiate a prefab and return it to you before its Awake is run?
That should be impossible by my understanding.
before the prefab's Awake or before the PlayerInputManager's Awake?
The prefab itself
I think I know how
So in PlayerInput's OnEnable() it triggers the notification from onPlayerJoined in PlayerInputManager
And I think the way Awake() and OnEnable() work is that for each component in the newly created object it runs both of those in a row:
So say your prefab has components:
A
B
PlayerInput
Right, I need to move the component higher up
