#🖱️┃input-system
1 messages · Page 28 of 1
Is this code in Update?
I know with Input.GetAxis you shouldnt be multiplying with time delta
yes
then it's fine
make sure there's no processors or interactions on these actions either
Hello
I follow a tutorials to implement the input system but I don't understand the difference to use .start and .canceled in OnEnable and OnDIsable and WasCompletedThisFrame() in the Update() for activate a button. What is the difference between theses 2 methods ?
private void OnEnable()
{
Input = new InputMap();
Input.PlayerInput.Enable(); //Enable the player input actions
Input.PlayerInput.MovementInput.performed += SetMovement;
//if the input is canceled, set the movement to zero
Input.PlayerInput.MovementInput.canceled += SetMovement;
Input.PlayerInput.ActionInput.started += SetAction;
Input.PlayerInput.ActionInput.canceled += SetAction;
}
//Subscribe to the input system
private void OnDisable()
{
Input.PlayerInput.MovementInput.performed -= SetMovement;
Input.PlayerInput.MovementInput.canceled -= SetMovement;
Input.PlayerInput.ActionInput.started -= SetAction;
Input.PlayerInput.ActionInput.canceled -= SetAction;
Input.PlayerInput.Disable(); //Enable the player input actions
}
private void Update()
{
MenuInput = Input.PlayerInput.MenuInput.WasCompletedThisFrame();
}
Huh. Yeah, not seeing it there either. I could have sworn I had this working with a previous project...
Well there's your problem!
"started" and "canceled" are two possible phases for an input action
In short:
- Started means that something is happening, but the action hasn't been performed yet. For example, the action could have a "Hold" interaction on it
- Performed means that the action has..been performed!
- Canceled means that we've stopping trying to perform the action -- e.g. we let go of a button or let a joystick return to the neutral position
You generally want to use performed, not started
But you might want to, say, start playing a sound during a one-second hold interaction
that would be an appropriate place to use the "started" phase
Hmm... still not certain why it shows up under the debug.
Oh, there's a difference? 😅
a gamepad is like an xbox controller
a joystick is a flight stick
oh, but the "dual action" is a gamepad, isn't it?
Okay I see 👍
But, is there a difference between perforemed/started and WasCompletedThisFrame() ?
This sounds much more like a flight stick, though
I wonder if the input system is incorrectly interpreting it as a joystick
Hmm... I did wonder why it maps it so oddly.
The "Hat" seems to correspond to the DPad. The right-stick is rz and z.
Most flight sticks have a little "hat" -- it's basically a digital joystick
it's definitely being interpreted as a joystick
the input system doesn't recognize this device
check out that unitypackage linked in the thread -- maybe that'll help you here
Oh, wow. It sounds like this is a fairly long-standing issue. Maybe why I got the gamepad for so cheap.
Ah, and reading further down, it's due to a lack of standards on gamepads. Fascinating. Well, I had fodder for a new article!
I'm not sure about that one, actually. I've not used WasCompletedThisFrame before.
It looks like it roughly lines up with the "canceled" state
I want to add this method of my PlayerMovement class ```c#
public void OnJump(InputAction.CallbackContext context)
{
Debug.Log("Jump");
}
when I push my button Jump. So, in my InputManager I add this line : ```Input.PlayerInput.JumpInput.performed += PlayerMovement.instance.OnJump;```
But, when I started my game, I have this error on this line on my InputManager : ```ArgumentException: Value does not fall within the expected range.```
Why ?
Can you show how you configured the action in the actions asset, and the full stack trace of the error?
Also where is this:
Input.PlayerInput.JumpInput.performed += PlayerMovement.instance.OnJump;```
And how do we know `PlayerMovement.instance` is ready to go at this time?
i dont see the jump event here (works with sendmessages using OnJump)
and i dont see move for that matter either when using invoke unity events
You need to expand the Player map
By pressing the little triangle
How do I make an action that execute a specific thing when tapping, and another thing when holding for enough time. I was searching on the unity docs but the page had a massive storm of information and I got lost and couldnt find what I'm looking for
Couldn't you just have two actions - one with a Tap interaction and one with a Hold interaction?
and listen for the performed
I think yes, but what I want to do could be simply done with only one. It's a dash system that when you hold for enough time it triggers a super dash instead, and I need to count the time the dash button was hold. But idk the keywords to detect that
It can't be done with a single action out of the box
you would need to write a special interaction/processor or just use the basic interaction and handle the logic yourself in code.
by basic interaction you mean IsPressed or smth?
i mean a regular action without any interactions defined. That gets you the default interaction
and then handling the logic either in Update or with events
so it would go like this?
if(input.IsPressed()){
timer += Time.deltaTime;
if(timer >= superDashTime){
superDashTrigger = true;
}
}
}
superDashTrigger = true;
Wouldn';t you just do the super dash there?
well the button should be released to do that
but no you need essentially a small state machine
when you first press - start the timer
- when the timer reaches super dash time - do the super dash
- if the button is released before super dash time - do a regular dash
ok then:
- when you first press - start the timer
- When the button is released - check if the timer is above or below the super dash threshold and do the appropriate dash
the IsPressed thing is the right way to detect if the player's still holding the button or not?
yes
ok, got it
but you will want to use WasPressedThisFrame and WasReleasedThisFrame to detect when it first starts being pressed (to reset the timer) and when it's released (to dash)
interesting, ty
you could also use events rather than Update, but I don't hate Update for this
Hey y'all. I'm trying to make this bus move by touching the back of it. I've got an invisible button set up as a child object, and I'm trying to make it add force to the rigidbody 2d when it registers a touch on the button. Can anyone help? What am I doing wrong?
start debugging; see if the touch is being registered, see if the force is being applied, etc.
oh wait you're assigning the velocity directly
make sure the bus rb is set as dynamic if you want it to process velocity
also make sure you don't have something like camera following the bus, if you did the camera would just move along with the bus so it would look like the bus wasn't moving
if you do want the camera to follow the bus, put something else in the scene as a point of reference
You can't put a button on a physics objects like that
Use the event trigger component
And make sure your camera has a physics Raycaster 2d
You'll also need an event system in the scene
I'd expect a Button to work as long as the camera has the appropriate raycaster
Possibly but it expects a Graphic for the transitions etc
It's just awkward
I just need to detect when a game object is touched, and I can't find a proper tutorial for how to do that. Does anyone know a tutorial for that?
Or is there someone I can pay to show mw how? Because I have no idea
Wdym by touched
With your finger?
I explained how up here
#🖱️┃input-system message
Yes
I know very little about coding. I don't know what to do with this info. I need a tutorial or for someone to show me
I was able to get the event system done based on this tutorial https://www.youtube.com/watch?v=mRkFj8J7y_I
But it's using mouse clicks, and I don't know how to code the script for touch
Welcome to a new video about detecting clicks in Unity 2D. This is a really simple way to detect clicks, and you can easily expand the code to allow for dragging and other actions.
Let me know if you need help with anything!
The script: https://github.com/chonkgames/Detect-Clicks-in-Unity-2D/blob/main/InputHandler.cs
► Subscribe: https://www....
Like I know I need to do input.gettouch and find the touch phase as begun, but I don't know the command for getting the x y of the touch or how to connect it to the collider
you don't need to do any of that
the tutorial's approach is not great either
what I explained above is all you need
Then you just set up a listener for the touch in the inspector for the Event Trigger
just like you would with a Button
none of it is code except writing the part where you move the object
So I've created an object with the event system and trigger, and in "First selected" I put the object I want to detect the presses from, and in the event trigger, I added the object I want moved, with the function "Begin drag" because I guess that sounds most like what I need
I also put this physics 2D raycaster on the camera
But I'm unsure what I need in the function box
Your object has no collider2D
You would attach a script of your choosing to the bus and select a public function from there
Oh so I should put this directly on the button I want pressed then
Like this?
I got a lot of errors in the console from doing that so probably not
first off no that's not valid C#
Second you need to make a function to call from your button
Third you need to configure your IDE
Because right now it's not set up to work with Unity
Like this then? I googled what it means to call a function
No
Make a public function and set it up as the listener in the inspector for the event trigger
Ypur code right now is, to be honest, complete nonsense
I expected as much. I have no idea what I am doing. I should probably pay somebody to show me how to write this code and learn from that, because I am getting nowhere, but I'm closer than I was before, so for that, I thank you
there are free learning materials everywhere. you don't need money, you just need time and effort.
maybe try checking out !learn and the pinned resources in #💻┃code-beginner
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
you over here nav
alr.
show inspector for the asset you selected
okay not sure why here you type PlayerControls, the class is called InputActions
ya.. and everything else is fine
this you probably don't need
yeah i just deleted that since i dont need to throw an exception now
since it found it fine
but another question then
so like... how am i supposed to have my position change then with WASD?
cause some tutorials show i need vector2 change
with OnMove()
but some dont
OnMove assumes you're using the SendMessages mode for example, or maybe linked action in inspector directly
You don't need that , not even the Player input component actually.
you already have everything linked from that Asset that has the mapping to your C# script auto generated InputActions
so its all subscribed I see here
This will auto call OnMove when you press Wasd
and exactly how i have that is fine?
except _playercontrols
i switched it to _playercontrols = new InputAction();
why
so its enabled the inputaction map within OnEnable i thought?
that should be InputActions
yeah my bad
it gets enabled, but you need an Instance of it first
hence the new()
thats what i meant
my bad
so wha ti have there (besides interact not being made yet)
that is fine 100%?
and i can attach my input action script to my player gameobject?
and its... good?
inputAction doesnt attach to anything
its not a component
its just a plain c# class, thats why it needs instantiation with new()
Monobehaviours (Components) instance get created when you put it on a gameobject.. thats another topic though
i guess im confused why its not a component if ive attached it... to my player
You haven't
That's PlayerInput
thats PlayerInput
is this not a component ?
you dont need that anymore
Totally unrelated
i can remove that?
yes
my god this is so all over the place
maybe its just me
but i cannot find a SINGLE up to date tutorial on the new input system
nah its just Unity made it like 3 different ways to use this thing
this is usually the most type-safe way
anything you add from now on goes in the Input Actions asset you shown earlier, the one with generate c# checkbox. Everytime you save a new change there, the class PlayerInputs gets automatically generated with the new items/actions
they're all up to date pretty much but everyone uses them differently so it seems more confusing than it is
okay, im trying this out and fixing all my compiler errors i was making when trying to figure this out
give me two seconds please
to like
make sure this works
Not much has changed in a while
But yeah there are many ways to use it, that's probably why you're confused
no joke ive been trying to be insanely self sufficient but ive been blocked on this controller input for like over a week
no worries took me literally 3-4 years to attempt the new Input System
the older one was a lot easier, but also yeah its pretty limited with newer inputs and rebind
yeah and im sorry - i just feel so weird downloading pre-built packages for everything
theres some things i feel like i need to understand, and i just feel like id need to understand the controller
I mean it would be insanity having to code your own inputs, this package is a good thing lol
wow it works
jesus
now i need to rotate char look position based on mouse and then do some sprint / jump / crouch
but thats another day
one block at a time
can you give me a very quick like.. what im probably going to look at doing
is it just within controller and just adjusting playerheight on keypressdown?
what kind of game exactly, don't think i caught that
so like 3d ?
ohh zomboid is dope
zomboid controls but duskwood art
zomboid has such incredible controls and depth and me being a programmer by nature makes me want to attempt something with depth like that
its inspired me
i walk around in debug mode and see all their variables they use on everything
its insanity how much they look at
but im trying to figure out their FOV, follow mouse, and the crouching stuff
yeah those games have a lot going on
im going through itch.io games too,
every game jam i want to add just a TINY bit more
Wanted to create a composite bind with CTRL + a number key, but it seems like some shortcuts used by the unity editor are blocking my bind. Is there some way to make it so that while playing, I can use whatever binds I want in game without the editor overriding them?
looking online for a solution right now, but it's just people complaining about the same thing
The game view has a toggle for keyboard shortcuts
That appears to block the cmd+X shortcuts for me (on macOS)
which the equivalent to ctrl+X on Windows
ah, I had the window set to half width on my screen so I didn't see that option there. Thanks! Surprised no posts I found mentioned it
they were all like 'why is there no way to do this' even from only a year ago
Im using the new input system on a project, and Im trying to set the spawn point of each player (local multiplayer). I have split screen enabled, so the prefab im instantiating have their own camera child. Im kind of getting it to work but because the origin of the prefab isnt exactly at 0 where the model of the prefab is (it's like in the middle of all the components), getting the transform to work is not only inconsistant but I have to set the Y value to like 5000 or else they fall through the terrain.
There's gotta be a better way
Make sure in teh scene view you set the tool handle position to Pivot instead of Center
Second time running it back to back (no changes made), they finally dropped into their spots but it took a minute
You can toggle it with the Z key
Yeah you have it set to center
that's why it looks like the average of all the child objects instead of where the actual pivot/object position is
is that editor change gonna affect the script ?
public void SetSpawnPoint(Vector3 spawnpoint)
{
transform.position = spawnpoint;
Debug.Log(transform.position);
}
this is being called from my gamemanager
It doesn't affect the script. It will simply show you where the actual transform.position is in the editor
The gizmo is at transform.position only when it's set to Pivot
right im setting the position of the prefab to the spawn point, but I think its a similar scenerio where its taking into account the camera as well and that center is being spawned outside the model
your problem is you have mispositioned objects because you haven't been able to see where the actual position of your objects are because of that setting
switch it to pivot then go through all your objects/prefabs and ensure the positions are as you expect
what object am i mispositioning ?
the prefabs get instantiated when the player input manager calls the player join event
they're not in the scene at start
public void SetSpawnPoint(Vector3 spawnpoint)
{
transform.position = spawnpoint;
Debug.Log(transform.position);
}
this is in my player script, which is tied to the prefab's empty GO parent
Empty GO > camera, CanvasUI, Model
does that function's transform.position set take into account the center of all the children ?
Again, no
the object doesn't care about its children
just its own pivot
your prefabs
your spawn points
I don't know for sure because I can't see your project
but you're spawning things under the ground
public void SetSpawnPoint(Vector3 spawnpoint)
{
startingPOS = transform.Find("HorseModel");
Debug.Log("Default start Pos: " + startingPOS.position);
startingPOS.position = spawnpoint;
Debug.Log("Set start Pos: " + startingPOS.position);
}
Alright I found a way to get the child and the debugs confirm the set position is set above the terrain
yeah but you need to look at your prefab
are the actual things that matter, such as the renderers, colliders, etc positioned properly in the prefab?
If the root of the prefab spawns above the ground but the renderers and colliders etc on the prefab are 100 units below the root, they will still spawn under the ground
look properly positioned to me
the collider
If it's above the ground then what's the problem?
the rendered object ?
also is this with Pivot or Center mode
thats when I dragged it to the scene. U keep mentioning the positioning of the prefab but theyre not in the scene at start
pivot mode
And which object is selected
Yeah I know that
I mean open the prefab itself
you can double click a prefab to open it in prefab mode
Then you can:
- make sure the prefab root is at 0,0,0
- Make sure the children of the root are not offset from the root
And when I say double click the prefab I mean the original in the project window
root wasnt at 0 !
ty
i still dont understand why if I was manually changing the transform.position at 10 for the y-axis in the script, it kept falling through tho but its fixed
the prefab y was originally -3.something but even the difference between 10 and -3 wouldve been 7, above the 0,0,0 terrain
private InputSystem input;
public string GetSelectedItem()
{
if(input.Player.ItemSelecting.IsPressed())
return input.Player.ItemSelecting.;
return "none";
}
Guys, how can i get id of pressed binding?
You can't not without writing some custom logic either around the activated control name or a custom interaction
I think you will find it's actually simpler in the long run to simply use 4 separate actions
This will also greatly simplify for example the rebinding process
ye, i know i can do it but if i need to make 9 instead of 4 it will be kinda painful so i thought maybe there's better solution
It doesn't take very long to make the actions
and it makes everything else much simpler
well if you say so i'll do tht
Does anyone know why my movement buttons work in the editor but not in the build version on android? Im using the on-screen button component
perhaps a misconfigured Input Module
and how do i check that
By... looking at it?
In the inspector
share it here if you don't know what you're looking at
so this thing or no
no
the Input Module
it's a component on your Event System in your scene
ok that looks fine
I would check your logs in android
(using the Android Logcat package)
make sure there's no errors in there
(needs to be a dev build)
this is also one of the buttons
ok i will try
its showing no errors
🔼
yes
Add some logging in your input handling and movement code then and check it in logcat
you can clealy see them turn grey when pressed
if it's responding to the touch then things should be working normally
could something be wrong here
if something was wrong there the button wouldn't react to your touch
the fact that the button is reacting to your touch leads me to believe it's a code issue.
Or maybe it's a control scheme issue
Are you using control schemes?
no?
Is that a question or a statement
but its not using any code it just the build in on touch button control using the movement that works well on keyboard
its not using any code
Of course it's using code
im pretty sure im not
How else is your player moving
ye but its working on keyboard
I know that it's working on keyboard
so should it work like that too
that depends on how you linked everything to the code and whether you're using control schemes for example
the gamepad device might not exist on android, for example
what happens if you bind the on screen buttons to the keyboard keys instead of gamepad?
im trying it rn
still nothing
"the up motion event handeled by client, just returned" is the thing that shows up on the logcat but no error
🔼
then it sounds like the input is being registered properly right?
So isn't it your movement code that's at fault?
put a log inside OnMove and see if it's reading the input properly
and how would i do that
how would you do what? Put a log in your code?
You type in Debug.Log(...)
you'll want to log the actual input value to make sure it's as you expect
this i did know atleast
Like I said, log the input you're receiving
like
Debug.Log($"Move input received, value is {moveInput}.");```
thank you
Move input received, value is (1.00, 0.00).
this is what i get in editor but i should probaly test it on android
"requestedHideFillUi(null anchor = null " is a new debug
but im not realy seeing anything else
new
@austere grotto
so the move input isn't making it to your code at all?
that could be
@austere grotto so any ideas im kinda lost?
does anyone have advice for how to set this up? i have a layout configured and stuff but there are no tutorials on how to actually check when an action is called that work for me
it just seems like a really unnecessarily complicated system
the tutorials for it all seem completely different
i'm so lost
how to set this up
set what up, exactly?
Hey there! I have a bit of a weird isue. I'm implementing my Input System for my game using the new input system, C# class generation and ECS.
My Unity project has been originally generated on Windows, but I'm also developing my game on Mac. Back on Windows, all inputs were working perfectly fine and my character could move around and look around.
But now, I'm on Mac and no input is detected AT ALL!
I'm instantiating my input system doing _playerInputSystem = new PlayerInputSystem(); (PlayerInputSystem being my generated class)
And then, in the OnUpdate I'm getting the moveInput doing:
var currentMoveInput = _playerInputSystem.Player.Move.ReadValue<Vector2>();
But it won't change from 0,0
Any idea why it would do that? Is there a difference between windows and mac for keyboard/mouse that I don't know about?
have you tried debugging the raw inputs?
go to your playerinput component and open the debugger at the bottom of the component
also make sure you've pushed all your changes (on windows) and pulled all your changes (on mac)
Hmm by the look of it, there are no device. But I do have a mouse/keyboard (and even though, it's a laptop, so they are hard wired to it lol)
uh, check if you have the inputsystem set in your project, i guess?
im really not sure where to go from there lmao
It looks all good to me lol
Maybe I should try and restart unity, who knows lol
Ahhh here they are! I had to restart the bloody thing lol
ah yes, the classic solution lmao
Yes it works now 😂
I'm literally watching the IT Crowd as we speak and I haven't even tried to turn it off and on again
Ironic
Thanks for the support :p
the input system, just in general
all the tutorials i can find all say completely different things and none of them tell you how to actually use it
i'm convinced it's broken
ok well without any specifics i have no idea what issues you're encountering
i've been trying stuff for the past 5 hours straight
Can you post a screenshot/bit of code with what you want to happen? Are you using the Input Master as posted above or just checking key strokes?
What's an Input Master?
-# We're working on the same problem together so I'm just tagging in for questions
We're just attempting to check key strokes, I don't think we have an "Input Master" setup
Something like the following?
if (Input.GetKeyDown(KeyCode.T)) { do something? }
My first step when I'm doing these is just to use Debug.Log("hello") to ensure my input is being read - so that's a good start.
We're trying to get an xBox 360 controller to work with the NEW Unity Input System
But we can't get anything to read and we can't even tell if it's detecting our controller
So I would say double check if your controller scheme includes the 360 controller. If it doesn't add that in. Then you'll want to check your Actions Bindings are picking up that new scheme.
https://www.youtube.com/watch?v=p-3S73MaDP8 - Brackeys also has a good vid on this with controllers specifically.
Let’s set up Gamepad controls using the new Unity Input System!
Jason no longer offers the course mentioned in the video.
❤️ Donate: https://www.paypal.com/donate/?hosted_button_id=VCMM2PLRRX8GU
····················································································
♥ Subscribe: http://bit.ly/1kMekJV
● Website: http://brackeys....
(looks like Unity is happy with any Xbox controller ^)
forcing my brain damaged companion to sit through the entire video,
give us a second and we'll let you know if we figure anything out. Thanks for the help
You got this, small steps and trial and error, just get a button responding and you're good!
does anyone know if its possible to make a 2d movement input without any limits on speed (im srry if its easy im really new)
sure what's stopping you?
nothing was i just needed to know if it was possible because im making a 2d movement shooter
anything is possible
Hii! For the life of me I have no idea how to get my console controller .vdf file working on my Unity game. I'm trying to implement SIAPI for it
I can detect the controller correctly and vibrate it, but the actions just aren't working
Can anyone point me to a resource that will help me implement SIAPI in Unity?
does anyone know if On___() functions called through Send Messages are executed before or after the Update() function?
i don't really know a good way to check
Here's how to check!
Debug.Log($"I was called at: {Time.frameCount}");
I really wish all log messages included a frame number
You can still see the order they appear in the console
I would expect all input to happen together, either before or after the entire Update step
it shouldn't get stuck in the middle
no prob (:
i am so confused by the new input system sometimes. i'm getting an error that isn't actually affecting anything
I did it like this, which is maybe slightly lowsy but it is sound logic
for some reason when i add a second action to the action mapping i then start getting the error i posted at the top
the gameplay still is absolutely fine, but i don't want this error to keep appearing, or cause a problem later down the line
even my setup for the input system is extremely simple
any ideas what causes this? nothing i google brings up my exact problem or a solution.
Errors as text:
InvalidOperationException while executing 'started' callbacks of 'Player/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]'
InvalidOperationException: Cannot read value of type 'Single' from composite 'UnityEngine.InputSystem.Composites.Vector2Composite' bound to action 'Player/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]' (composite is a 'Int32' with value type 'Vector2')
InvalidOperationException while executing 'performed' callbacks of 'Player/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]
I exhausted the only option I could actually find, being this website with the same error and a solution for it, but it doesn't actually work in my case: https://nekojara.city/unity-input-system-custom-interaction-sprint
Look at the full stack trace of the error
It will show you where the problem is
Full stack trace meaning the expanded log for each error message right?
yes
you can click on the error in console and look at the bottom of the console window to see it
Sorry, i'd never heard of it called that before!
the logs for each error is kind of the same, it's this:
UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Actions/InputActionState.cs:2808)
UnityEngine.InputSystem.InputActionState.ReadValueAsButton (System.Int32 bindingIndex, System.Int32 controlIndex) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Actions/InputActionState.cs:3122)
UnityEngine.InputSystem.InputAction+CallbackContext.ReadValueAsButton () (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Actions/InputAction.cs:1972)
GamepadSelection.OnSelect (UnityEngine.InputSystem.InputAction+CallbackContext selectCntext) (at Assets/Prototypes/GamepadSelection/GamepadSelection.cs:159)
UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/DelegateHelpers.cs:46)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)```
eugh the lack of wrapping on markup is awful, sorry
Looks like the issue is here:
Assets/Prototypes/GamepadSelection/GamepadSelection.cs:159```
line 159 of GamepadSelection.cs
weirdly, that line has nothing to do with the directional inputs that the Vector2 message at the top of the output is mentioning?
Yeah that line is you trying to read the value of the action as a float
which is invalid
since it's a Vector2 action
public void OnSelect(InputAction.CallbackContext selectCntext)
{
if(selectCntext.ReadValueAsButton() == true)
{
if (selectCntext.phase is InputActionPhase.Performed)
{
SelectCurrentTile(currentTileValue);
Debug.Log("pressed");
}
}
}
void SelectCurrentTile(int _currentTile)
{
tiles[_currentTile].GetComponent<GameboardTile>().ChangeTileState(2);
}
#endregion```
noting this is not the Move action that you have shown here
it's the Select one
My select action is a Button, not vec2
I think you accidentally bound OnSelect here to the Move action
somewhere
how did you hook this code up to the action? I think you made a mistake
Thanks!
you can remove it
Oh?
I was thinking I could have the same input for release for ui menu options
Just for better UX
if(selectCntext.ReadValueAsButton() == true)
{
if (selectCntext.phase is InputActionPhase.Performed)
{``` and instead of this you can just do:
```cs
if (selectCntext.performed)```
for release you can do:
if (selectCntext.canceled)```
or use a switch statement with selectCntxt.phase
Oh I see, because it's always performed as a binary input, the ReadValue isn't necessary?
yeah
cool, thank you ☺️
insane that they refer to the input as 'cancelled' rather than released
i'm surprised there's no standard on the terminology that reflects how we refer to input actions in games
but oh well
well it's complicated but it's a generic term for any interaction. Depending on the interaction that might not necessarily be when the button is released
it might be when, for example, a Tap interaction action is held for longer than the max tap duration
in which case it's still being held down
oh i see, and they just don't have a released phase too because they're fundamentally identical based on how the input system settings are setup by the devs on an individual basis? 😄
something like that
btw InputAction DOES have a WasReleasedThisFrame()
you would use that if you wanted to poll input in Update instead of using events
ooooh okay okay, thank you very much!
why in the new input system, a button action now is float and not bool? cant i do something so i can action.ReadValue<bool>?
you can use .wasPressedThisFrame or .isPressed
i need to use readvalue
why?
i want to make my input system and i cant make a case only for button
looks like you have to
ReadValueAsButton() Exists
Didnt know, thanks 😄
I want to disable hand tracking in my game on Quest. It's a controller-based game, but when I double tap my controls together, hand tracking turns on and my players can't play until it turns off again. I know Gorilla Tag has this turned off, so it should be possible.
I'm using the OpenXR plugin, and have hand interaction poses turned off.
Anyone know how I can turn it off?
Hello,
I have two action maps : Player and Dialogue that share a binding to the same key E.
In Player action map, E is bound to action Interact.
In Dialogue action map, E is bound to action Continue.
My player input component has its behavior set to "Send Messages".
Is it normal that even with only the Player action map enabled, when I press E, both methods OnInteract() and OnContinue() are triggered ?
Thank you for your help.
Got it.
My InputAction asset was both bound to my PlayerInput component and the project wide actions (in project settings).
So when I was disabling action maps other than Player, I was only doing it on the asset bound to PlayerInput component, and not for the one set project wide.
Why is this not changing canvases?
The first function is being called but the rest the Debug,Log is not working
here is my code
https://scriptbin.xyz/ocofiwadet.cs
Use Scriptbin to share your code with others quickly and easily.
I think you need to active the action map you want but im not sure how this works with using the input action references
Hopefully someone else can comment if activation is needed or not
thank you will check it out
still not working :/
inputActions.Player.Look.performed += ctx =>
{
mouseX += ctx.ReadValue<Vector2>().x * rotateSpeed * mouseSensitivity;
Debug.Log( Time.frameCount );
};``` How frequent does input system actually trigger? Why am I getting skipping values here?
it's skipping frames
Is there a way to bind a wii controller using the WiiMote API to the new input system. Similar to how the analog stick works on a game pad with a 360 degree type of input ? Or woul I just have to convert the axis' rotation in a script instead ?
might be niche but figured I could try to see if this approach was possible
Performed happens when the input actuation value changes
It's not meant to happen every frame
Thank you
We're having problems with the Input System. When adding a new device, being by code or because a real device was connected, sometimes it's assigned to a new "User", and this user "steals" the Actions from the other user. The result is that sometimes you can't move anymore on the other device. How do we solve this problem? Either by making actions "global", or assigning everything to the same user by default.
We sometimes use "fake" devices for cutscenes. And this whole user system is bugging our game out.
YOu'd have to explain your setup and how your game works
Is this a local multiplayer game?
no. it's a singleplayer game. we don't need multiple users
we use PlayerInput. that's where we put our actions
Sounds like you're spawning another PlayerInput at some point
PlayerInput is intended to be 1 to 1 with physical human beings
you should never have more than 1 if it's a single player game
New devices being connected won't spawn new PlayerInputs automatically unless you're using PlayerInputManager
The other thing you should not do if it's single player is use control schemes
we're not spawning another one to my knowledge. what we do is call AddDevice to add our fake cutscene device. and sometimes that's assigned to a new user that steals the actions
control schemes are there solely to differentiate users based on devices
double check if you have PlayerInputManager in your scene(s)
i'm checking. i can't find a component like that
we have two PlayerInputs
one for menu controls. another for everything else
is that bad?
yes that's bad
Remember what I said up here
oh..
right.. so it should be on a scene that runs forever
a unique one
thank you!
Why is there such a huge disconnect between how the input system behaves in editor and how it behaves in IL2CPP builds?
you have have to explain what you are talking about a bit more
I can't for the life of me get the input system to dispatch any events in an IL2CPP build from an object spawned with Instantiate, whilst in editor this works.
Binding via this pattern m_MoveToAction.performed += MoveToActionPerformed; works in editor regardless of what's going on, but in IL2CPP builds only works if a PlayerInput object exists in the scene
I've tried also calling WasPerformedThisFrame in the Update method, which works fine in the editor, but also doesn't necessarily work in IL2CPP builds
Maybe show more of your setup? It seems weird to me you would be mixing the PlayerInput component with this kind of manual event subscription.
you might just have some kind of execution order issue with how you set up your listeners or something
(have you checked the player log?)
moving up in the world
With compensation, if anyone would be willing to take an hour of their time to help me understand the new input system and how to implement them with pre-existing scripts in a discord call, please let me know.
I’m out for a couple hours, but I could take a shot, depending on your schedule. Not sure if you found anyone yet.
we don't do paid help here
just !ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
we don't really support private or vc help either; that defeats the purpose of a support server
actionRef.action.PerformInteractiveRebinding(actualBindingIndex)
.WithControlsExcluding("Mouse")
.WithCancelingThrough("<Keyboard>/escape")
.OnComplete(operation =>
{
newKeyPath = actionRef.action.bindings[actualBindingIndex].effectivePath;
string newKey = newKeyPath.Replace("<Keyboard>/", "").ToUpper();
// Check for conflicts
InputAction conflictingAction = FindActionUsingKey(newKeyPath);
if (conflictingAction != null && conflictingAction != actionRef.action)
{
// Store for later reassignment
actionToRebind = actionRef;
bindingIndexToRebind = actualBindingIndex;
// Show popup
conflictMessage.text = $"The key {newKey} is already assigned to '{conflictingAction.name}'. Replace it?";
conflictPopup.SetActive(true);
operation.Dispose();
return;
}
// No conflict, apply immediately
ApplyBinding(actionRef, actualBindingIndex, settingsField, newKey);
operation.Dispose();
})
.Start();
i want to check if the button is already taken by another action to display a warning popup with buttons cancel and proceed. I did it but now i realised its not working properly, apparently when the code reaches .OnComplete then its already too late, button is assigned. I can manually revert it back but is there a better way? An built-in method for some conditions before applying the change?
maybe use another callback, like OnPotentialMatch etc.
Anyone gotten this problem before? It's just stuck on this forever. Is there a way to close it?
Hi, I have a little problem, I want to mix keyboard and controller inputs for a split screen game mode I would like to have the classic configuration (joystick to turn L2/R2 to move forward and brake) but I can't find what to enter in the input manager.
Thanks
Hello guys. I have a split-screen game with two player controlled objects (both have a player input comopent). I would like the default controls for both players to be the keyboard. One player has the left side (WSAD - IKJL) and the other player the right side (arrow keys - numpad 8246). Creating two control schemes didnt work for me. Any tips on how to achieve that?
i need help getting the inputs from each dpad input
i wanna make it so the 4 directions on the dpad each correspond to a different item the player has
Make 4 input actions
assign one dpad button to each
i did but how do i then make it so if for example i press up on the dpad it will make the player use a healing item
that's a whole separate and potentially complex question
for example is this something the player can equip items to?
Or is up just always healing?
well i dont need help with the healing item itself, i just wanna know in code how to set it so when up is pressed something happens
it has nothing to tdo with the input system at that point htough
there's nothing special about the up button
it would work like any other button in the input system
set it up the same way
it's not the same
How do you mean? It is exactly the same
I have this right now
if (inputAction.Player.DPadUp.triggered) { Debug.Log("Up"); }
but when I press up nothing happens
`` public character player;
public PlayerInputActions inputAction;
private InputAction up, down, left, right;
private void Awake()
{
inputAction = new PlayerInputActions();
}
void Start()
{
}
void Update()
{
if (player.shopOn == true)
{
Bag();
}
}
private void OnEnable()
{
up = inputAction.Player.DPadUp;
down = inputAction.Player.DPadDown;
left = inputAction.Player.DPadLeft;
right = inputAction.Player.DPadRight;
}
private void OnDisable()
{
up.Disable();
down.Disable();
left.Disable();
right.Disable();
}
void Bag()
{
if (inputAction.Player.DPadUp.triggered)
{
Debug.Log("Up");
}
}``
You never enabled your input actions
inputAction.Enable(); is necessary
also !code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
hi, was wondering if there is an easy way to pass values through to a prefab instantiated by playerInputManager
there's an on player joined event
which gives you a reference to the newly instantiated object
you can do whatever you'd like with that reference.
oh! i see
what's the formatting for the reference out of curiousity
finding documentation for this has been tricky
formatting for what
to assign the instantiated object in the script
i'd assume its
void OnPlayerJoined(GameObject prefab)
{}
oh okay
void OnEnable() {
myPlayerInputManager.onPlayerJoined(PlayerJoinedHandler);
}
void PlayerJoinedHandler(PlayerInput newPlayerObject) {
Debug.Log($"A new player joined. Its name is {newPlayerObject.name}");
}```
which one of these lets me just read the value as a float?
so far everything returns 0 here
I guess if there's a way to directly get a bool, that would be better but it seemed like you just had to convert from the float from what I saw online
axis
you probably didn't enable it
where would I do that?
I've already gotten the movement vector2 to work if that helps
didn't fix it
this?
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
again you probably didn't
onenable or awake?
it has to be an event?
wdym
you have to enable the action before it's used
that's all
The code to enable it needs to run
then it will start working
is that only for buttons?
since my movement vector didn't need me to do anything else
It's really hard to help since you haven't shared any code
it's for all actions if you're using InputActionReferences
most of it's not super relevant but https://paste.ofcode.org/XgwCvjZ8sNNeKz95XUgbS4
I'm porting from the old system
alright
if it's working for the axis, something else has enabled it
or possibly if it's a Pass Through it might not need enabling
this is the only script with the new input package
so would have to be this ig
added this line to OnEnable() and it didn't change anything
move (axis) is also just a value, not a pass through
looks like theyre all enabled by default
since this is always true
I still haven't fixed the problem, btw
I don't even see a confirm action in your list
and hwy are you tryin to read it as a float?
shouldn't it be a regular button?
I also don't see you enabling it in the code you shared.
I added one line and told you where, I didn't feel the need to upload it again
yes triggered or WasPerformedThisFrame is generally the right idea - but you need to set the action up as a regular button not an axis
just - Action Type: Button
please stop cropping your screenshots so much
you're cutting out all kinds of useful context
the action configuration would be great
this?
look at your control scheme
only used for gamepad but bound to a keyboard key?
Is this a local multiplayer game?
that's proabably it
its literally the only keyboard input to have that
registers now but only for a frame
or wait
let me test something
trigged only happens for one frame yes
that's intentional
yeah
Does anyone know if it's possible to use the split screen in the input system stacked in vertical rather than horizontal?
Also if it's possible to make new players use the gamepad first and if there are no gamepad available then the keyboard
Edit: I managed to do this by setting the Default Scheme to Gamepad in the player input
right now it's the opposite
hi
i need the link to documentation where i can see all methods/functions for Input System
so far i have searched but it ended in disappointing theory
i just moved to unity from godot
i would like to study it myself
but i cant find the list of methods, i did try the pinned links
please help
you aren't really meant to use methods much with the input system
have you tried looking at tutorials on !learn?
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
sorry
no I haven't. you mean it isnt done in script? I'll look at some
moveInput is a Vector2 that holds an x and a y, where you can get x via moveInput.x
here you only have an x, which you can get via horizontalMovement
since you can't move vertically, you don't need inputY at all
also if you only care about horizontal control you could use a float instead of the Vector2
my character can face all 4 directions and i have 4 animations assigned, it just walks horizontally
ok, they can face 4 directions, but they aren't the same 4 directions the tutorial means, most likely
this would be for 4-directional movement
i think i just need to connect inputY with up and down arrows, i just dont know how to do it
so its 1 when Up arrow is pressed, and -1 when Down arrow is pressed. i thought i could do it in the same way the system reads if theyre pressed for movement, just without the movement
but you aren't doing the same way
you're taking the x of the input right away
you never get the y here
where can i get the y from
the input
what would pressing up/down even do though
that animation doesn't really make sense if you can only move left and right
you can face up and down and i have animations for that
i kinda figured, i just dont knowhow
do you understand the code in the tutorial
i belive i wouldnt have to ask for help if i did
tutorial command takes input from all 4 keys. what i use only takes input from 2
but you want to take input from 4... so take input from 4
i need to take input from the other two separately, so it doesnt move my character
thats what i believe could be a solution
or i jut have to make a bool for each key but i really wanted to avoid that
you don't
so how else can i solve this
many ways
- get the y direction by reading the input again and getting the y
- read the full vector locally, then assign just the x to horizontalMovement
- read the full vector like in the tutorial, then only use x to control the rigidbody
just for example
if you don't understand basic code yet, consider pausing that tutorial and
in #💻┃code-beginner
i have that in plan, for today i just want to get the controls done and never think of them again
oh, you'll have to
Good morning, everyone. I'm hoping that someone here might be able to help me. The gamepad and keyboard inputs seem to be fighting with each other, causing the player to grind to a complete halt during gameplay, if the keyboard/mouse are moved/pressed when using the gamepad. The inverse also happens (ie. touching the gamepad, while using keyboard/mouse).
I've set up a 'ControlsManager.cs' script to handle managing the input but I'm unsure of how to force Unity (via code) to distinguish between gamepad and/or keyboard/mouse input to enforce the use of one over the other, so it doesn't swap to using the other, if the first is in use. Any advice is appreciated.
public Vector2 getMove() { return move; }
public Vector2 getLook() { return look; }
private void moveCallback(InputAction.CallbackContext context) { move = context.ReadValue<Vector2>(); }
private void lookCallback(InputAction.CallbackContext context) { look = context.ReadValue<Vector2>(); }
I'm not sure I fully follow this. You're saying if you press the keyboard while using the gamepad, it makes your character stop?
That seems fully expected to me tbh 🤔
Basically when you release the keyboard key you're going to receive an event with a value of 0. If that was the latest event you received, that's what your input value is going to be set to.
Yes. Pressing forward on the gamepads left joystick makes the player go forward. If I wiggle the mouse while doing so, the player grinds to a halt, despite still pressing forward on the gamepads left joystick. And it's definitely not intended behavior. XD
I mean why would a player do that
For some reason, Unity is interpreting mouse movement as joystick movement and I need to find a way to reject how Unity is handling that.
mouse movement shouldn't be involved here at all
Not saying they would but lets say you bump your table while traveling at high speed and your mouse gets jostled. You then grind to a halt mid-gameplay and die.
that sounds like a separate issue from the conflicting controls issue
if the mouse input is feeding into your action here without any mouse binding something else is going wrong
How are you hooking these listener functions up to the actions?
I mean, they're all 'controls'. And by name, from the InputActions.
void OnEnable() {
playerInput = GetComponent<PlayerInput>();
addListenerByName("Player/Move", moveCallback);
addListenerByName("Player/Look", lookCallback);
}
So, I figured it out; it's a defect with the Unity InputSystem auto-switch feature, under the player InputActions component; the defect being that Unity detects mouse input as the gamepad/controller's left-joystick input, despite not being defined in the InputActions to be so.
If left in its default configuration, the PlayerInput component can be observed (via the debugger) rapidly toggling between gamepad & keyboard/mouse inputs, if the mouse is moved during gameplay (even just bumping the table enough to jostle the mouse triggers this).
If I set the default scene to gamepad and turn off Auto-switch, the intended behavior actually occurs and moving the mouse doesn't interfere with the players controls/momentum by causing them to grind to a halt. The over-all issue being that, when Unitys default auto-switching occurs, the input value from the mouse is deemed to be zero (or so significantly less than what the current left-joystick gamepad input is being clocked at from 0 to 1) and immediately overrides the previously calculated velocity values to be zero.
I'll need to implement custom logic on my end, in order to baby-sit Unitys auto-switch feature so it works correctly and it'll probably look something like this:
if ( /*Is Gamepad Connected?*/ ) {
if ( /*Is a menu Open?*/ ) {
// Set 'Default Scheme' to 'Any'.
// Set Unity 'Auto-Switch' to 'active/true'.
} else if ( /*Is gameplay level loaded, with no menu open?*/ ) {
// Set 'Default Scheme' to 'Gamepad'.
// Set Unity 'Auto-Switch' to 'disabled/false'
} else {
// Some other, currently unknown case...
}
} else {
// Set 'Default Scheme' to 'Any'.
// Set Unity 'Auto-Switch' to 'active/true'.
}
That said, thank you for being my rubber-duck here. TwT
Hello, does anyone know how to resolve an issue with the Input Actions system where keyboard modifier keys (Shift, Control, Alt) are not being read properly on key press & key release? All other keys and mouse button bindings are being read properly, even when mapped to the same Action as the Shift/Control/Alt binding.
eg)
1st full key press & key release of the "shift" key will log:
Started
Performed
2nd full key press & key release of the "shift" key will log:
Canceled
Cna you show how you configured the action and the bindings?
Yes!
This is how I configured the bindings in the Input Actions Editor. I only want the Dash Action to be bound the "Shift" key, but was testing it with "Ctrl" (another modifier) and with "Q" key (non modifier). The Dash Action is of Action Type - Button.
The code snippet is how I'm checking which context phase is being read on key press and key release, upon pressing any of the Dash Action bindings. The OnDash() method is in a PlayerInputReader class that inherits from both ScriptableObject and the C# class created by Input Actions Editor. I'm using this ScriptableObject to read player input and send appropriate events to the main player controller class.
can you show the poroperties of the action itself?
This is just the binding
Sorry, here's the action properties window
and how did you hook this action up to the code?
Is it via the SetCallbacks thing on the generated C# class?
Yes ^^ by using SetCallbacks
i don't see anything inherently wrong here
what happens if you remove all but one binding?
Having only "Shift" as the sole binding for the Dash Action results in this:
1st full key press & key release of the "shift" key will log:
Started
Performed
2nd full key press & key release of the "shift" key will log:
Canceled
Having "Ctrl" as the sole binding results in the same issue above. Having any other key such as "Q" as the sole binding for the Dash Action results in proper reading of all 3 context phases.
The issue occurs with Shift, Control, and Alt bindings, which leads me to believe it maybe be an issue with only the modifier keys
I just tested it
working fine for me
Both with Shift and Left Shift
Possibly it's a hardware or OS setting issue
Maybe you have Sticky Keys eturned on in WIndows?
Yeah If I turn on Sticky Keys then I get your behavior
Solution: turn off sticky keys
maybe an OS setting issue? I've tested it with several different keyboards and they all show similar results. I also have Sticky Keys turned off by default, and tested it with Sticky Keys on and they both have the same results surprisingly
maybe i'll test in a brand new unity project
Update:
I double checked sticky key settings and realized I was looking at the wrong page! I have all sticky key toggling shortcuts off, but my sticky keys were actually on. Unchecking it solves the issue.
Thank you Praetor for the assistance! 😄
no problem!
Also yeah while i was investigating that I too got confused by the sticky keys settings UI
when i build with webgl it wont detect keyboard input. does the new input system just not work well with webgl or something?
Hi, I'm quite new here, and I was wondering if I can assign the grip buttons on my Steam Deck as separate inputs in Input Actions? (Not mapping them to existing buttons like the D-pad or X/Y/A/B.)
what do you mean, "existing buttons"? If a device reports as a generic gamepad or a more specific device, it is a gamepad or that device, whatever you do with that (i.e. which input actions are triggered by that) is up to you.
You can implement a custom device that responds to the manufacturer signature of the steam deck and reinterpret all that but if the inputs are already recognized, what would be the point?
I just updated the Input System coming from a pretty old version. So far I used it with generated C# classes and Instantiating the actions when I needed them, like
input = new PlayerInputActions();
where PlayerInputActions is the generated C# class from my inputactions map.
Now there is the global actions and it seems kinda useful.
But can I use the global action map with a strong typing? Having type safety is so useful compared to handling around magic strings
Not really no. Come support me on my feature request here to get it added!!
hello there
quick question
when using gamepad rumble, am I supposed to call the function on every frame?
( _currentInputDevice as DualSenseGamepadPC )?.SetMotorSpeeds ( 0f, 1f );
cant really figure out how to use it properly
Hi, I have an empty parent object (Britain) which I have made a Territory object by assigning the Territory script. It contains an OnMouseDown method which moves Britain. I want the meshes of its game object children (UK & Ireland) to activate OnMouseDown method for Britain but I can't seem to find why its not doing it (after following instructions online.
Both the children have mesh colliders and work if the script is added to each individually, where they act as seperate objects. Can anyone help me?
If you add Rigidbody component to the parent, it will register collider triggers also from its children. Don't forget to turn off the gravity.
I'm using input system 1.13.1
Inside unity editor everything is working but when I'm trying the build, player controls aren't working, any ideas why is this happening?
Hey im trying to get the input system to work but noting else other then manuscript is there
You dragged the wrong thing into that slot
You need to drag a GameObject with the script attached to it into the slot, not the script itself
my buttons are not highlighting (and i think not working). at first i thought its event system issue because pressing arrows would do nothing, but in event system inspector they are selecting accordingly. theyre linked to dialogue manager script object, to MakeChoice method. theyre interactable, their navigation is set, their transition is set. i made a different set of buttons and they worked correctly. theres a separate set of keys binded just to make sure its not an input issue. (additionaly pressing choice1 button still triggers choice0 dialogue)
#📲┃ui-ux question, not input system
can you show the button inspector in #📲┃ui-ux
okay
is there a way to get the ReadValue(Vector2) as a float instead int. In the old system it was called GetAxis rn it is GetAxisRaw
Your question is really confusing because why are you mentioning Vector2
You can do ReadValue<float> but you need to set the action up as an axis.
already did that so i have that action map.
moveAction = myPlayerInput.actions["Player/Move"];
Debug.Log(moveAction.ReadValue<Vector2>()); gives me the raw int
i mean the single vector2 values
You're saying you want smoothing like GetAxis has?
yep
There's no built in smoothing
You can do it yourself with Vector2.MoveTowards in Update
allright, ty
they still are floats. they're just snapping directly to integers in your case
If I have three players (in multiplayer) and I'm using an InputManager and each player has its PlayerInput and its camera, I keep getting an issue where the inputs are going to the right players (Say P1, P2 and P3) but the players always see the camera from P1. OnNetworkSpawn I locally disable the PlayerInput to the other two players so in theory there's no reason why that should happen. Does anyone have any clue?
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
_playerInput.enabled = IsOwner;
Debug.Log($"Spawning {this.name} am I owner? {IsOwner}");
}
This is what I run in the MPPlayerScript
and if I also disable the camera:
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
_playerInput.enabled = IsOwner;
_playerInput.camera.gameObject.SetActive(IsOwner);
Debug.Log($"Spawning {this.name} am I owner? {IsOwner}");
}
I just don't get any camera renderer at all, although P1 camera is disabled locally but P2 camera is enabled locally
This didn't seem to work for me, do you know why?
I tested it, as long an object has Rigidbody, OnMouseDown registers all clicks for children recursively. I'm not sure what could bug your version. Perhaps something else is blocking your input.
Anyway, if you need an alternative solution, you can try sending a Raycast from your cursor's position, and then check if the parent of hit GameObject contains your script, then run its method if it does.
OnMouseDown doesn't work with the new input system
The correct approach is IPointerDownHandler
With a physics Raycaster in the scene and an event system
Stange, as I don't think anything is blocking the input, as the children register clicks on themself, just not the parent and unless the parent's rigidbody (its an empty object) is getting in the way, I can't think of what's causing the difference in our outcomes.
Should I add the Physics Raycaster to the camera object? As I had previously tried this but maybe I put it in the wrong palce or was missing something?
I didn't know about this new function, thanks for the info, tough, when I use this function, even the ones that did work with OnMouseDown don't work anymore. I'm using the newer version of unity so it should include the new input system but do I have to do anything in particular to allow that function to work?
I have an event system and am not sure what object should contain my phsyics raycatser for it to work
I just decided to make a new script and add it to the children, which calls the parent object's OnMouseDown function from the children's OnMouseDown functions but I appreciate all the help
The physics Raycaster goes on your camera
How do I use this new input system to read clicks that weren't on buttons? In my level, clicking anywhere on the screen except for a button is used to shoot, but UI buttons being clicked shouldn't result in a shot being fired.
public static PlayerInput inputActions;
private void Awake()
{
inputActions = GetComponent<PlayerInput>();
}
public void Pause(bool pState)
{
if (pauseMenu != null)
{
if (pState)
{
pauseMenu.SetActive(true);
gameIsPaused = true;
Cursor.lockState = CursorLockMode.None;
inputActions.Player.Disable();
Time.timeScale = 0f;
}
else
{
pauseMenu.SetActive(false);
gameIsPaused = false;
Cursor.lockState = CursorLockMode.Locked;
inputActions.Player.Enable();
Time.timeScale = 1f;
}
}
}
Why isn't my inputActions being disabled on pause?
In this video I'll show you how to enable the new input system to work with the Unity UI, along with another cool input system feature!
ᐅGet the full Source Code Bundle to my Unity Tutorials 🤓
https://sam-yam.itch.io/samyam-full-source-code-to-all-videos
😎 Cool Unity Assets 😎
ᐅPeek - Editor Toolkit: https://assetstore.unity.com/packages/tools/...
Hey, guys! Why would you recommend to use the new input system? I have heard about it and I saw some bad reviews in Unity Forums about it. Most of the devs are preferring to use the old one istead. Why?
Perks of the new Input System:
- easy toggling of action maps (e.g. when you open up pause menu, you can toggle off character controls and toggle on menu controls, then after leaving the pause menu you can do the opposite)
- registering callbacks to inputs (it feels better than checking their value every frame)
- input processing (you can modify global settings or modify particular inputs; input processing includes stuff like threshold, hold duration, and normalization; you can even modify those settings in runtime, for example, to let players invert camera controls)
- input references (imo better than hardcoding values)
- individual controller input support (for each action, you can individually set up generic inputs or use different ones depending on the controller, e.g. on Nintendo Switch
Acceptbutton is the East one) - tools for in-game control settings (you can override settings, write them, load them)
- debug tools (you can easily check what kind of inputs are being processed)
The old input system is great if it was already set up and coded 5 years ago and you don't have time to refactor it from scratch. If something is working, then there is no point in touching it. But for new projects, I would recommend newer, more flexible solutions.
There is zero reason to keep using the old system for new projects.
I am a beginner and I find the new Input System pretty difficult.
It definitely has a learning curve. Especially if you're still learning C#
I come from Python and there are definitely differences between the two languages..
its maybe a tad harder to get started but its considerably less hard to carry it through to a working system that has real world requirements
I sometimes use the old system for quick prototyping.
you can still use the new system in the same way as the old one, there is no speed gained using the old one.
Is it a glitch on my project or the Unity team forgot to test the new input system asset configuration window? Every action you modify, and then every path you want to change, everything you do starts reloading the whole editor
Every time I want to change my inputs it is the most disgusting experience I have in the whole Unity Engine
There used to be a "Save" button so this window doesn't auto-save and compile every time, why they removed it?
Nice.
It's due to the generated C# file changing
Are you using the generated C# file?
To avoid automated saving, you can turn off the auto-save function. If your file also generates C# class, saving will be even more time-consuming.
Unfortunately yeah
I don't have that on my input window for a long time, I think they removed at some point
Out of curiosity, I've updated my package to version 1.13.1. Auto-save is still visible. Are you sure you mean Input Actions Editor?
Just checked here, it seems they did not remove the buttons, but only if they're not used as "project-wide"
if you're using as the project-wide input actions, the buttons doesn't show
Unity version: 6.0
I have installed the Input System package and am trying to set up my own input actions in a custom input map. I was instructed to use the Listen button for setting up the physical keybindings, but hitting any of my keyboard, mouse or touchscreen inputs on my laptop after clicking on Listen doesn't actually binds any buttons nor does it have any visual feedback. Not even any errors pop up; just nothing at all happens. I have been googling this for a while and tried looking up solutions on YouTube, but I can't find any good resources on troubleshooting the Input System in general, let alone mouse inputs for games.
If anyone has good resources for troubleshooting the Input System please lmk 🙏
make sure you subscribe the input event and enable it beforehand, i suppse the best source would be the input doc in pin
Sure, but I can't even set the binding in the editor cause it doesn't recognize mouse inputs whenever I hit the 'Listen' button. Like, I know what to do AFTER I bind the lmb, but I can't get it to recognize it
For some people that listen feature is broken. You can however select all the bindings from the menu too.
Okay, so now I have a separate issue in that:
Press [TouchScreen]inputs for interacting with non-ui elements work fine.Press [Mouse]inputs do not.
I'm just looking for a basic press at this point, so I'm not sure what's broken. There are also NO good tutorials that explain this that aren't UI based
here is the script that captures that action:
using UnityEngine.InputSystem;
public class ProjectileInstanceHandler : MonoBehaviour
{
public GameObject ballPrefab;
public static GameObject Instance { get; private set; }
private Transform parent;
public InputActionReference pressAction;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnEnable()
{
if (pressAction != null)
{
pressAction.action.performed += OnPress;
pressAction.action.canceled += OnRelease;
}
}
void OnDisable()
{
if (pressAction != null)
{
pressAction.action.performed -= OnPress;
pressAction.action.canceled -= OnRelease;
}
}
private void OnPress(InputAction.CallbackContext context)
{
SpawnBall();
}
private void OnRelease(InputAction.CallbackContext context)
{
Instance = null;
}
/// <summary>
/// Attempts to spawn a new ball if one does not already exist in the slingshot.
/// </summary>
private bool SpawnBall()
{
if (Instance != null)
{
return false;
}
Instance = Instantiate(ballPrefab, transform);
return true;
}
}
so, I think an issue with this might be because this is an AR Foundation project.
I'll try that next time I get around to my desk
Hello, I have something that has an UP and a DOWN state, is it possible to create an input action that has both the UP binding and the DOWN binding, and also a TOGGLE binding to toggle between those two, all in the same input action?
no
Not worth it. Just make two or three actions
Will do. Thanks for the reply!
I'm confused. Are you supposed to use project-wide input actions if you only have one input action asset?
So the "player input" component is redundant in this case now?
The two concepts are orthogonal
It is an alternative to using PlayerInput yes
I really only recommend PlayerInput for local multiplayer games
Makes sense to me, ty
Is there a way to check for any gamepad input? There is a path that is any key [keyboard], but is there a similar thing for gamepad?
Hey it has been a quick minute, but where do you check for overrides in the debugger?
I swear they were somewhere
nvm, it was in Layouts > Specific Devices > [Device] > Applied Overrides
Is it possible to add a new matching device through a override (json) or do I need to do it this way?
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.14/manual/Devices.html#matching
I have a device that for some reason isn't getting matched by unity to the layout it has to use so I need to do it myself with the vendor and product ids
Actually what the json does is extending the layout, and layout != matching so..
Oh it seems that the device isn't getting matched because somewhere the manufacturer info gets lost, and its getting matched through SDL and not HID as I thought
Is this a normal thing on Linux? The controller used to match just fine to its appropriate device type on Windows (Actually no, because the controller and its gyroscope works perfectly fine in applications that use SDL so this makes no sense)
Oh actually I guess the reason for why its failing is because Unity uses SDL, not SDL2
Checking gamepad.cs and... yeah...
does anyone have any experience in creating their own custom device layout ? Or have a link to a tut (I cant for the life of me find one that I can understand). Basically ive been using the WiiMote API to get the gyroscope data from a Wii Remote but I recently found u can somehow create ur own input to read data, and this would make UI navigation and local multiplayer functionality (since its set up with the new Input system as opposed to manually doing each) much easier
Hey all, a question about a possible issue around my Input System.
Currently when I launch my Game from the Editor it's all working fine (UI, controls with mouse and keyboard) but the controls don't work when I load into it from my Main Menu. I can still interact with the game modes etc. by my custom Unity Editor tools, so the game is 'working/running' fine. It's just the input that doesn't want to register. Does know why this could be? Thanks in advance!
Oh, I just discovered that disabling and enabling the Input System UI Input Module restores UI interaction with the mouse and Player Input restores my controls. Is this a script execution order issue or is there something wrong with how I load/initialize the scene?
Could be a problem with just how your scenes are set up
Possibly having a duplicate event system or something
Trying to make an "Enter submit" script for a TMP InputField (Separate from the OnEndEdit callback), but it seems like when the box is focused this no longer reads any input? If I breakpoint this after the enter check, I hit the breakpoint when I press enter and the box isn't selected, but when it is, I get no breakpoint. It looks like the input field is "eating" the input somehow?
if (Keyboard.current.enterKey.wasReleasedThisFrame)
if (uiInput.isFocused)
OnSubmit.Invoke();
Is there a way around this? A way to call a function when specifically enter is pressed?
Couldn't you use ISubmitHandler or an EventTrigger?
I did not know that was a thing. I certainly could.
Actually, looks like Event Trigger's Submit doesn't seem to work
What if you make a script with ISubmitHandler
using EventTrigger might be weird because there's multiple handlers then
Ah, hang on, I think I found the issue and it's my own fault - I try to disable hotkeys so you don't accidentally do things while typing in a text box, and one of the devices I disable is the keyboard...
But... why does typing work if the keyboard is disabled? 🤔
I think typing in an input field uses the IMGUI event system which doesn't go through the input system
Okay, welp, I'm running into the corners of multiple half-assed solutions so now I gotta actually do it right 
I tried to find the issue, did a debug and got back that I only have one Event System... So I went for the 'dirty' solution and just turn the Input System and Player Input off and on lol. But thanks for the suggestion! 🙏
I've got my game spawning PlayerInput prefabs, but how do I differentiate which player is applying input?
Currently each device is affecting all characters.
Use PlayerInputManager to spawn them
It will assign each PlayerInput to different devices
Actually TBH PlayerInput should do that itself so I suspect you're doing something fishy
How did you link up your code to the PlayerInput?
Switching the PlayerInput from C# functions to Unity Events did the trick. I'm not sure why, but it worked.
Because it sounds like you weren't actually using the PlayerInput component before at all.
other than as a window to get to the InputActionsAsset
The "C# Events" mode on PlayerInput is the most misunderstood thing in all of the Input System lol
If you use the "C# Events" mode on PlayerInput the intended workflow is to subscribe to this event and handle everything from this one event handler:
Most people misinterpret this and do something like myPlayerInput.actions["SomeMap/SomeAction"].performed += MyHandler; which actually bypasses the component entirely basically.
Ah, I did indeed call SetCallbacks on the InputActions class rather than the PlayerInput component.
Thanks for the insight.
Ah yep - that's not even pretending to use the PlayerInput component. That's using the generated C# class.
Is this the proper and best way to get the current input device type (not the scheme)? InputDeviceType is my own enum
{
_playerInput.onControlsChanged += OnControlsChanged;
}
private void OnDisable()
{
_playerInput.onControlsChanged -= OnControlsChanged;
}
private void OnControlsChanged(PlayerInput input)
{
if (input.GetDevice<Keyboard>() != null)
_currentInputDeviceType = InputDeviceType.Keyboard;
else if (input.GetDevice<XInputController>() != null)
_currentInputDeviceType = InputDeviceType.Xbox;
else if (input.GetDevice<DualShockGamepad>() != null)
_currentInputDeviceType = InputDeviceType.PSX;
else
_currentInputDeviceType = InputDeviceType.Unknown;
}```
I tested it with my Keyboard, an Xbox Series X controller, a PS4 controller and a Logitech controller (Titan submersible tragedy model) and it works
But the Logitech controller registers as an Xbox controller instead of as Unknown. Not sure if its supposed to or not
well you're telling it to
XInput isn't specific to xbox, many controllers use it
the logitech controllers i used to use had a switch on the back to switch between xinput and directinput
Hey guys, what's up...?
I'm trying to make a system where the player can "dive-roll" when they press the left/right buttons in a double-tap
But I'm not sure if you can have multiple type of interactions or how they will work together...because when you hold the player will walk normally and when the player just double-taps quickly the player will dive-roll
I decided to make the dive a seperate action because for some reason there's no Multi-Tap interaction in Value or Pass Through
I have Pass Through set for my basic 2D movement, with Vector2 as the attribute, and I have the Dive as a Button (since that's the only way I can get MultiTap interaction to show)
you don't want "Hold" on the move action
that's not what you think it is
having two actions makes sense here
Oh so if I remove that interaction by default I can just hold the button for the player to move...?
assuming your code is set up correctly for that
And if I keep dive with the multi tap interaction with the same movement buttons will it still work...?
yes
Oh ok nice, nice, thank you, I'll try it out
Because all I wanted to do was replace my animations in Unity, and instead of using the Animation State Machine I decided to hard code everything in code, ever since then it's not working...I think it's the Input System
Also just to make sure, does the Player controller auto generated C# script need Monobehaviour...? Before it worked perfectly fine but now it's saying an error that it needs to drive Monobehaviour (I'm using Get Component, based on a tutorial)
no the autogenerated script is not a MonoBehaviour
and using it with GetComponent doesn't make any sense
it's not a component
Somehow it worked last time, I'm not sure how...
What's the right way to reference a script in Unity...?
you were using PlayerInput instead of the generated C# class before
or you were making a new instance manually
hard to say since we're talking about a mystical theoretical time which you don't have the code for
I was referencing the auto-generatted C# script through a reference like this
What's the right way to reference a script in Unity...?
This question feels kind of loaded in the current context
because I don't think you even know what you're asking
To "reference" anything in C# you make a reference variable
as for how to assign the variable that depends. If it's a Unity component you assign it in the inspector or by fetching it at runtime with e.g. GetComponent
playerControls is the reference to the type PlayerController, which is my C# generated script
yes here you're simply creating a new instance with new
because this is the generated class which is basically a POCO
it's not a Unity object/component
you're making a new instance here and storing a reference to it in your variable called playerControls
this is the normal C# way of creating objects
Oh so do I have to find that GameObject with GameObject.Find(playerControls), or can I just reference playerControls itself...?
It's not a GameObject
it's not a Unity object
Because when I was trying to search the internet that's one way I found of referencing a script
GameObject.Find is completely off the rails here
you're confusing Unity GameObjects with C# objects
GameObjects are the things that appear in the hierarchy window in your Unity Editor
those are the only things that GameObject.Find can find
Oh ok that makes sense...so like RigidBody or Tilemaps and stuff like that are GameObjects
no
those are all Components
Components are thje things that appear in the Inspector window in the Unity Editor
They are attached to GameObjects
So components are like attributes to Game Objects...?
they are modular pieces that give GameObjects behavior and functionality
When you make a MonoBehaviour script you are creating your own custom type of Component
Thank you for telling me about this, I didn't know, now I will keep this in mind when referencing stuff
You might benefit from reading this https://docs.unity3d.com/6000.0/Documentation/Manual/GameObjects.html
Ok then I'll have to find a proper way to reference the auto-generated C# script
you already have one
your screenshot above is the way
Because when I was watching a tutorial on making the Input System that's how they told me to refernce
Another thing to understand here is that the Input System is pretty complex and there are many different ways to use it and many different entry points to it in code.
So there is not just one way to do things
Yeah true, I just came across a YouTube video a while back saying that the "new" Input System is better to use in the long run than the typical Input.GetKey
If I can get all the complicated stuff working like multi tap and special button presses then I can have some relief
It is better. It has a learning curve though. You seem to be at the very beginning of your journey here. I don't want to discourage you from using it, just pointing out you are going to struggle a bit as it assumes you know the basics of C# and Unity already.
can i get information on the callbackcontext about the object i hit? i want to check if my left click hits a ui element or just the empty screen
Callback context is only input related it has nothing to do with anything in the scene
What you should do is implement IPointerClickHandler on the objects
oh okey, i thought i could get the screen position if i use a vector2 input for example. But the PointerClickHandler seems to be interesting, will take a look in that
Yes you could do it that way but it's better to use the event system
i think ill go with your method first and if that doesnt work ill try to get the positions from the input system
Can someone help me a create a custom device for the new input system? I basicaly want to create a dummy device that creates a bunch of dummy controls based on some collection of strings (HashMap, for example) that doesn't do anything and always return 0. The goal is for the list of strings to apear in the path options for bindings in the input action asset. They will only be used to identify groups of bindings that should be overrided together.
hello everyone it says he can't find the OnShoot method while i.m using it should i update the c# generate after each new action in my input system?
it says Onshoot method not found while it is added to my actions
nvmd i should name it " Shoot " not "OnShoot"
hello, i have a question, im pretty new to the "new" input system. my question is about whether i have to reference a InputAction in each script in which i need it, or can i make a one reference in scripts with static instance of it, and use that reference in all scripts where i need it?
for example i have a InputManager script where i calculate all the angle for rotating to face the mouse and stuff like that, which works cuz i can read the value and save it to a public vec2. but with a button value, where i either need to subscribe a function to it or use "triggered" value within it, im not sure, or rather it doesnt work, so is it possible or do i need to make a new reference to the Actions asset and all the input actions in it anew?
You can do it any way you want
It's often useful to have only one copy of the input actions asset which you manage from one place and share it around so that input rebinding etc works in one central place
I don't recommend reading the input in one place
Just managing a single instance of the asset in one place and letting other scripts access that is usually best.
well this is my code, but when i use anything other than vector value, it doesnt work, when i use the roll.triggered in other script, it says missing reference
well this is my code, but when i use anything other than vector value, it doesnt work, when i use the roll.triggered in other script, it says missing reference
that's really vague.
show the exact code you tried and the exact error you got
this is an order of execution problem
The stuff in PlayerRoll.Awake and OnEnable should actually go in Start
because if you have it in Awake it's possible for it to run before InputManager.Awake
ill try puitting it in start
The InputManager itself should be little more than this tbh:
public static InputManager instance { get; private set; }
public PlayerInputs playerInputs { get; private set; }
private void Awake()
{
instance = this;
playerInputs = new PlayerInputs();
}
void OnEnable() {
playerInputs.Enable();
}```
Also I'm a little confused by your use of the PlayerInput component here
because it seems like your code is using the generated C# class.
which means you don't need a PlayerInput component and probably shouldn't have one.
you mean here?
i referenced it so i could atleast work on it while i wait for someone to help me
wdym? im really new to this input system, so i have not a very good idea of how it works
I mean what I wrote. The input manager shouldn't really do anything other than manage the singular instance of PlayerInputs
all the actual input handling can happen in the other scripts
because the individual scripts are the ones that know/care about how individual actions should be processed/handled
oh, i thought you mean that there is something missing xd, "little more than"
I'm saying there's too much
i see, ill try to change it and ill see
Like doing realLookDir = aim.ReadValue<Vector2>(); this could be handled in a script dedicated to looking/aiming or whatever
ye, that one line was useless and i deleted it, but i get the idea, ill just make a new script for handeling tose looking and angle data
I pull my move action like this:
var moveAction = _inputMap.FindAction("Move");
when inspecting it with the debugger, there is a list of bindings, but no clear way how to pull the bindings bundled under secondary or primary.
What I'm trying to do is pull a specific binding, e.g Secondary/Left and then rebind it to another key. However I do not understand how to access it.
what do you want to do with it? Rebind it?
so i did it like this, but i get reference not set again. any idea? im lost..
Again I don't recommend a script like this INputValues script
it's a pointless middleman
Whichever script ultimately would read moveDir should just grab InputManager.playerInputs itself and read Move.ReadValue<Vector2>() itself
And as mentioned before
all the OnEnable stuff in InputValues that reads from Inputmanager isn't going to work
because Awake/OnEnable will potentially run in a random order
it's just running before InputManager's Awake/OnEnable runs
well i only wanna use it for the lookDir and moveDir. the other ones i dont care about rn. but the InputManager.instance.playerInputs doesnt work
ohh, didnt notice that, i found some run order image on google and it showed that awake is first, that makes sense than
it works fine
you just can't access it before it's initialized
(Also double check you actually have an InputManager instance in the scene)
thats what's confusing me
so where should i put the input actions and playerinputs references in the other scripts?
as needed
@austere grottoYes sir, rebinding is the goal. I want to bind secondary and primary controls.
for example in a movement script:
void Update() {
Vector2 moveInput = InputSystem.instance.playerInputs.Player.Move.ReadValue<Vector2>();
}```
though you can do some caching e.g.:
InputAction moveAction;
void Start() {
moveAction = InputSystem.instance.playerInputs.Player.Move;
}
void Update() {
Vector2 moveInput = moveAction.ReadValue<Vector2>();
}```
so mostly start, update and fixedupdate right?