#🖱️┃input-system
1 messages · Page 3 of 1
that's what everyone says, and yeah I 100% agree
I'm slowly learning it and it's slowly becoming easier and easier to understand for me
btw I like the game you're developing, I'll give it a wishlist
thank you ❤️
I won't be able to buy it because I'm just a teenager with no credit card
but I'll support you with a wishlist
no problem, thank you 🙂
So bit confused as to what is going on here, it will register the right trigger input for this action but not the left mouse click input. It is picking up the mouse position just fine though. Did I set something up wrong here?
Of note, I setup 2 control schemes one for gampad and one for Keyboard&Mouse
also Action Type is Button
apparently the problem is that my UI event system uses leftclick, I read I can bypass it with a lambda event, but I lose my "hold to continually fire" functionality
Found the issue, I needed to add mouse as a device to my controlscheme
Another quick question, I use inputs from the input manager which is great for controller but when using a keyboard it tends to have a quick ramp up and down when that isn't necessary (in other words, I don't stop walking when I let go of a key as the axis takes a half sec to ramp down). Is there any way to avoid this or disable it?
Please @ me.
Hi, for a long time, when connecting the controller, I get such an error, it prevents me from further work on the code to the controller, can anyone help me with this error?
Question: there's an Editor/Click action that's defined and works fine when you first load the game. When you then load in another scene on top, it doesn't work any more, and the action has disappeared from the list of actions in the Input Debugger. All other actions are still there. Anyone got any insight into that?
Use GetAxisRaw
Why would I use the Invoke C Sharp Events behaviour? for my input component?
Don't. It's not what you think it is.
Question: How do you receive different keys from the keyboard, into one script, with the Input System? I'm trying to set up a different action when the user presses one of key 1, 2, or 3 (I only need one key at a time). I think the process should work similarly to using WASD, where the one script accepts one of the keys, and then takes action. I've got it working pressing the 1 key, but I need it to activate the script for the other keys, and for the script to determine which key was pressed. Any help, or direction to a webpage with this would be greatly appreciated. Thank you!
Why not just set up one action for each key?
@vocal jay Thanks. If I understand you, it would mean a separate method for each key. It may be up to 10 keys. I don't want 10 methods. I'm very new to the new Input System.
Do all the keys do the same thing?
@vocal jay Each key will change several variables, to different numbers.
You can read the control from the callback parameter
Probably best for what you are attempting
I tried to read it, but I think it's not getting sent, because I don't have it set up right in the Action Map. Here's my Action Map:
The gravity speed change action?
Yes.
You're going to go around in circles for hours or days to avoid this and then finally just realize that you should've taken the 5 minutes to set up the 10 separate actions.
You should be able to define as many bindings as you want, and then check the actual control from the CallbackContext
Yes, I would definitely prefer separate actions
Mainly for rebinding purposes, but @royal stream already knows of that solution and doesn't seem to want to go that direction
Personally I find reading the path / name / whatever from the callback to be iffy
everyone's got to make their own mistakes though ¯_(ツ)_/¯
Can you show some code how you are reading the action?
Since it doesn't seem to work at all from what you mentioned
It's possible that I'm misunderstanding, because I'm so new on the Input System. To be clear, do I set up separate actions, like GravitySpeedChange1, with the 1 key, then a GravitySpeedChange2, with the 2 key, etc.
That's how I would do it, but I feel like having 10 controls for this is a bit much. Some other input method would seem more appropriate
The 2 key is not calling the script, which shows a Debug.Log.
But I depends on your project
yes something like that.
Depending on the way you actually listen to the input actions, it should be relatively easy to dedupe the code for actually handling the input
Hey man
nvm
public void GravitySpeedChange(InputAction.CallbackContext context)
{
Debug.Log("1 or 2 was pressed.");
string numberKey = Keyboard.current.ToString();
Debug.Log("Pressed: " + numberKey);
}
Having a seperate method of each key is a good thing.
Have you checked the input debugger if the action is correctly activated on the bindings you set?
e.g. not something like control schemes interfering
@vocal jay I haven't, thanks. I'm checking it now.
Good news. The 2 key, which I could have sworn wasn't doing anything, is activating this script, along with the 1 key. I think I just need to have the script figure out which key is pressing it now. So the code I posted, I think (he adds confidently), is the problem.
It's showing this in the Console:
Keyboard.current is the current keyboard device
It has nothing to do with the callback
Information pertaining to the triggered event is inside the CallbackContext parameter
Drag Touch Controls Are Clunky on Builds Using Touch Samples Code
Oops.
Ok, can you tell me which parameter I need. I can't find the right one. I'm assuming I need string numberKey = context. but then what? Thanks.
don't make that assumption
go to the docs and look at what CallbackContext contains
Thank you. I'm reading it now.
If you really want to only use a single action, a cleaner solution would be to use an input processor
That's what I'm trying to do. I just need to read the key pressed, and the rest is obvious after that.
Although I think I need a composite binding, like WASD, but I haven't figured out how to set that in the Action map.
I don't think Unity supplies a composite binding of the type you are looking for
That would be annoying. Although, unlike WASD, I don't need to read 2 keys pressed at the same time, so do I still need a composite binding?
The composite binding can read multiple keys and then decide what to do with them, outputting a final value
Whether or not you need to read multiple keys or not isn't really important for a composite binding
I think I just need to know what key was pressed. This was simple in the old system.
I'll write you an example, that should explain it better
Thank you. I'm having trouble finding an example on the Internet.
This obviously isn't super tested or anything, but the gist of it is something like this:
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
[Preserve]
public class TenWayCompositeBinding : InputBindingComposite<int>
{
#if UNITY_EDITOR
static TenWayCompositeBinding()
{
Initialize();
}
#endif
[InputControl] public int _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Initialize()
{
UnityEngine.InputSystem.InputSystem.RegisterBindingComposite<TenWayCompositeBinding>();
}
public override int ReadValue(ref InputBindingCompositeContext context)
{
if (context.ReadValueAsButton(_0)) return 0;
if (context.ReadValueAsButton(_1)) return 1;
if (context.ReadValueAsButton(_2)) return 2;
if (context.ReadValueAsButton(_3)) return 3;
if (context.ReadValueAsButton(_4)) return 4;
if (context.ReadValueAsButton(_5)) return 5;
if (context.ReadValueAsButton(_6)) return 6;
if (context.ReadValueAsButton(_7)) return 7;
if (context.ReadValueAsButton(_8)) return 8;
if (context.ReadValueAsButton(_9)) return 9;
return -1;
}
}
This lets you define a new input composite type
Thank you. I will test it right now.
You will have to adapt the ReadValue function to determine how pressing multiple keys at the same time is handled, but you would have to do that regardless
The reason why your initial implementation of reading the CallbackContext.path field inside the callback isn't the best is because the point of the input system is to decouple the control used from the code executed, or you may run into nasty issues, as Praetor mentioned earlier
Makes sense, but I wonder how people uncouple it for things like this. The number keys could be used for vehicle speed changes, or lots of things in games, so something is needed.
I mean it depends heavily on the context doesn't it?
You can do pretty much anything with a combination of composites, input processors and interactions
Makes sense.
The idea is that the input system supplies the final "input value" generated by the whatever input device is supposed to be the input for the gameplay code in question, which the gameplay code can then consume
Yes, I understand that this is the purpose of the new Input System, and it seems like a good idea, which is why I'm using it for this game.
Your code makes sense, and I think will be very useful, however I have a dumb question. Where do I put it, which script, or in a new script?
Inside a new script called TenWayCompositeBinding
Thank you.
Note that you will only see the composite binding for the generic type you registered it for, in this case int, so make sure the action type and control type are set correctly.
e.g.
Ok, it's looking better. It gave a few errors, which it suggested I add these:
using UnityEditor;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.Scripting;
Which I did, and it is happy for the moment.
Yes, I omitted the imports earlier
No problem. I mentioned them mainly so anyone else following this later, will have them handy.
I've got something screwed up here. It's not showing the Add Ten Way Composite Binding Composite, in menu with the Add Binding, like it shows in the image you sent. Here's what it's showing:
Hey for some reason, MenuDisplay works fine but the action map never gets disabled
What is your action type and control type for that action set to?
Action type is Button. There is no Control listed.
Makes sense, now. Control Type is set to Any. Still no Ten Way...
Control type needs to be Integer, since that's what the composite binding was registered as
InputBindingComposite<int>
Sorry, I forgot - you said that above.
No worries, it's not very intuitive at first
I've still got something screwed up.
Hit add a binding
Then right click the generated binding
The reason it works this way is that you might have a different input device that doesn't even require the composite
Similar to how the four way binding for WASD works, that's mainly since keyboards aren't very good at creating analog directional input for games
But a gamepad won't require the composite, you could just use a control stick (a single binding) to generate a Vector2
Makes sense. Unfortunately this is what I've got now:
My bad, you were actually correct in this picture, the binding should appear here
Let me check real quick
Thanks.
Do you have any compile errors?
No compile errors.
Odd, the InitializeOnLoad attribute is on the class?
It's exactly as you typed it, except for the 4 using statements.
Do I have to put this script in a particular folder?
Not as far as I know, but you should have 5 using statements
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.Scripting;
Yes, I have all 5. The first one was already in. I just added the 4. But not with the condition of UNITY_EDITOR. I'll put that in.
That's just to stop your build failing, it won't make the composite appear
The only other suggestion I have is to restart the editor, maybe something broke with the input system registration
The Ten Way is showing up now!
I'm off to bed, good luck on getting it working
If you have time for one more question. How do I read the value in my code now?
The same as you would any other input action. Set up the callback, and if you perform the action (pressing any of your composite keys), the callback will be called, letting you read the value returned by the composite using the CallbackContext.ReadValue<int>() method
Thank you. I'm still very new to Input System. I tried this:
int x = context.ReadValue<int>();
Debug.Log("Pressed: " + x);
@vocal jay If you've gone to bed, I hope you get this in the morning. I'll figure out the last part. THANK YOU! very much for all your help. I hope this discussion here helps others, too. Have a great day!
I didn't realize this was a question, is it not working?
The code above is not working to print x.
It's giving errors.
InvalidOperationException: Cannot read value of type 'int' from control '/Keyboard/1' bound to action 'Player/GravitySpeedChange[/Keyboard/1,/Keyboard/2]' (control is a 'KeyControl' with value type 'float')
UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at
It seems to think it's a float.
Are you sure you registered your function to the correct input action?
make a thread
InvalidOperationException: Cannot read value of type 'int' from control '/Keyboard/1' bound to action 'Player/GravitySpeedChange[/Keyboard/1,/Keyboard/2]' (control is a 'KeyControl' with value type 'float')
UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at
Did you save the asset?
Nope. 🙂
It still gives errors. Seems to think it's a float. I tried changing my code to float, and got no errors, but it still didn't work. ??
This is the code:
int x = context.ReadValue<int>();
Debug.Log("Pressed: " + x);
Is the GravitySpeedChange action correctly set up as Value and Integer?
Try defining bindings for all parts, not sure if that's an issue
Okay.
Actually, I think the issue is that you are reading GravitySpeedChangeOLD
I don't think so, however, I deleted the OLD one and am re-running it.
I think you are right.
Cannot find action 'Player/GravitySpeedChange[/Keyboard/1]' with ID '19dff998-6209-45e4-af6f-b2de8d037fea' in 'MyInputActions (UnityEngine.InputSystem.InputActionAsset)
UnityEngine.InputSystem.PlayerInput:OnEnable () (at
You'll need to update the action on the PlayerInput component in your scene
what is the right way to set set input button to false after it is pressed. Is that something that should be done in the StarterAssetsInputs? (I am extending the starter assets third person controller).
For example I have an item pickup, so I would have
if (starterAssetsInputs.pickup)
{
PickUp();
}
but it would end up detecting that it was true even after I let go, I guess maybe it was in a completed state or something?
so I cleared the input after the action to fix that.
private void Update()
{
if (starterAssetsInputs.pickup && inRange)
{
PickUp();
ClearInputs();
}
}
private void ClearInputs()
{
starterAssetsInputs.pickup = false;
starterAssetsInputs.drop = false;
}
but then the issue I ran into is, the input is only cleared if if pickup the item, which I only do if I am inRange. So I can press the button while out of range, then walk into range and it auto-picks up.
so I ended up just moving ClearInputs() at the end of my Update()
but I get the feeling that is more of a workaround and not actually the correct way to use the input system?
I'm guessing your use-case is a fire and forget action ("If I press the button, attempt to pickup the object")
correct
I would do that with a callback instead of polling the input
InputAction.performed
Subscribe your handler to that
@vocal jay I'm working on it.
So I would just do starterAssetsInputs.pickup.performed?
I'm not sure what type pickup is, but if it is an InputAction, then yes
This is the example from the docs:
// Create an Action that binds to the primary action control on all devices.
var action = new InputAction(binding: "*/{primaryAction}");
// Have it run your code when the Action is triggered.
action.performed += _ => Fire();
// Start listening for control changes.
action.Enable();
Fire would be your Pickup in this case
@vocal jay YES! YES! YES! It works!
@vocal jay The Input component wasn't updated, probably when I renamed the actions to point at my old method. Thank you very much! Have a great day!
You too, glad I could help
why might it be that even though I have if(context.performed) in my methods for input, I get double input?
depending on the device, control type, and interactions on the input action, performed may happen multiple times during whatever you're doing physically with your device
for example a joystick input will fire the performed event every time the actuation amount changes to a new non-zero value from any other value.
yes, I was curious if control type pass through on mouse click is a problem... is it? should I change it and to what in that case?
pass thrugh will always give you performed
whenever anything changes
you should use Control Type: Button
oh, I see! Not value though? 100%? I just want it to work with mobile touch too...
just tested, it works 10/10 perfectly, thank you very much!! 🙂 If it works on mobile too that's a total win
I chose touch*/press, is that ok?
so its either pointer or touch*/press + left mouse button click combo and it's a preference?
How do i get drag to work with the new input system on UI?
please i need some help getting this to work
iguess ill just stick to the janky bybrid system for now
im out of time to figure out how to get touch working for this
there doesnt seem to be much information on it and im concerned about affecting other systems
please I need some help to get started with this
is there a way to display an input binding path as a dropdown or context menu inside of my own class?
i.e. public InputBindingPath path;
I want to avoid having to manually type paths as strings inside of my custom class
hmm, long document and still elusive as heck about paths
var devices = InputSystem.devices; // Only gets currently connected devices.
var controls = devices[0].allControls; // Only gets controls for selected currently connected device.```
I could build a path based on values fetched from these in a custom inspector but this limits me to only the devices I currently have connected in the editor which could have issues on disconnection of a device you're working with or at runtime.
unity is able to pull off this context menu, I don't see why they can't open up the functionality :/
is there a way to find a list of all supported devices?
How I can fix this error? /* Doesn't work
doesn't seem like the Input system.. Looks like a cache / package conflict.. You could try deleting the Library folder and let unity rebuild the project
I tired man but its doesn't work
you may be using something like a shader incompatible with ur current render pipeline
u are on URP or built in-renderer
Built in
right so you may have something trying to access a Shader graph param which builtin has no clue about.. You could delete the offending asset/package and refresh cache or you could maybe switch it to URP and rebuild again, n see if that fix.. regardless backup your project before making changes
@stone oriole don't forget to backup the project before switching pipeline
I created a backup im going to do it now
Its works tnx!
managed to pull back my own enum lists from a completely outlandish way of doing it
but gets all layouts, then gets their controls, then allows you to filter based on input layout type, i.e. vector2/delta/button etc.
Can somebody help. I have a movement script and a variable doesn’t want to show up.
Editor: 2021.3.6f1
you don't have any fields that I would expect to show in the inspector
InputMaster is most likely your generated C# class from your input actions asset right?
That class is not serializable
Yes
probably just change that "_ => MVNTH()" into MVNTH to start
nah you can't
the callback needs a parameter
that's not relevant to their immediate problem either
do you ever assign controls to controller?
It’s from 2018
yes somewhat but not enough that it will matter
you didn't
you're missing a line of code
there should be somewhere they are assigning controls to a new instance
ah ok
yes it's just an outdated tutorial
you need controls = new InputMaster(); in Awake
didn't know performed was an event? more so just a bool
yes it's an event
Thx
yeah never being assigned would be the problem
so this isn't an implementation using CallbackContext ?
the problem is their callback function doesn't have a CallbackContext parameter
so it can't be subscribed to performed directly
is there a way to get touch input working with the new input system on UI elements?
I have the input system UI Input module attached to the event manager and in scene
the problem is that this only seems to work when im not simulating touch screens
but I need to be able to test the UI out with touch input to ensure it is all working correctly when the project is built and that whatever touch interactions im building work correctly
it does work when touch simulation is off
but turning touch simulation off breaks the parts of the project that rely on the new input system
so I need to get the touch system of the new input system to work with the ui
is there a way to get the new input system touch input to connect to events like on pointer down?
sorry i know im probably missing quite a bit here
Im still learning about the new input system and it does feel like the touch section of the new input system while powerful lacks some inportant information about how it should work
granted I probably have not read up on it fully, but i am having trouble locating a section on the touch input
is enhanced touch compatible with the new input system?
cause I think that simulated touch does not work with the new input sytem touch, but that enhanced touch works with that
that is atleast what I can see in the editor
I'm using the old unity input system on 2021.3.2f1, and my inputs work only in the editor. When I build the game it doesn't detect any controller input. I tried upgrading the input system, which didn't work either
Is this a common issue?
old input system you have to poll for in updates
new input system is generally done via a subscribing class that sits on some object in scene and listens to events
---- For my own question, anyone know how I can setup my own input binding etc. without creating an action map in the "Player Input Actions (Input Actions)" inspector window and auto generating a template class.
No idea whats causing this error
Only happens when I activate the button
yield return new WaitUntil(() => playerActionAsset.Player.Interact.triggered);```
Comes from this line
[SerializeField] private PlayerInputScript inputScript; im sure its the correct script.
Hi ive been making a game and i wanted to know why i cant see the edit aspect in the inspect
this is what its ment to look like
this is what it looks like
Edit Asset*
The stuff in the Inspector changes depending on what's selected in your project. In the tutorial you're following, the dude has the Input Actions Asset selected in their project files, that's why it's appearing in the Inspector.
so how do i do that?
I wonder why you need it to appear in the Inspector in the first place, but here goes
Go in your Assets and search where you put the "Playerimput" asset, and select it by clicking on it
Btw you really should make the names exactly as the tutorial does it, as names will be really important in the near future (you'll use them in code)
Anyone who notices that the callbacks for the new inputsystem takes a lot of cpu time on android? With my current game it can easily take 30-40ms when it process inputs and I use the supplied on-screen button/joystick scripts but I don't think that is the bottleneck
Connected my device to my computer with a cable and did av development build and ran the unity profiler. In the build window you have theee checkboxes. I think it is development build, start profiler and autoconnect profiler and then you are running 😉
is it better to select unity or c sharp events when deciding the input action behavior?
inputScript.playerInputActions.Player.Interact.triggered```
This seems to be triggering multiple times.
I don't know how to make it similar to GetKeyDown
im trying to do this
void Update(){
if(inputScript.playerInputActions.Player.Interact.triggered){ //seems to be triggering multiple times.
DisplayNextSentence();
}
}```
But it just skips to the end
Yeah, it seems like Im triggering it twice.
How do I get it to only trigger once?
Is my settings wrong for the player control map?
When I press the space bar it triggers and then I let go, it triggers again.
How do I stop this!
Is there something special I need to do to see the InputRecorder class?
No matter which version of the InputSystem I install, it doesn't exist, despite being in the docs
never mind! Figured out it's one of the samples, and I needed to bring that in
huh I haven't had issues with the input system being buggy and triggering multiple times
all issues related to that have been my own user error
Hello, is it possible to hit two different colliders at the same time with the new input system? I have a sphere and a cube, both with a script that will print something on pointer hover, with the IPointerEventHandler interface.
They work fine until I put the sphere into the cube (photo), is there anyway to trigger both colliders with the new input system?
you'd use a raycast RaycastAll / RaycastAllNonAlloc to get multiple. they're unsorted
though, your original question isnt related to Input manager / System at all
Nothing you mentioned in your question has anything to do with input system
It's supposed to work that way. The triggered function can take a CallbackContext argument, which you can use to check if the button was just pressed, released, or being held down.
public void SomeInputChanged(InputAction.CallbackContext context)
{
if (context.canceled)
{
// Button was just released
}
else if (context.performed)
{
// Button was just pressed
}
else
{
// Button is being held
}
}
But yeah this feels pretty bloaty for me too, I mostly stick to the old Input system. You can use both in your project btw.
I'm using the new input system and all of my of my vector2 composite inputs stopped working on one of my two action maps. I recently upgraded my project from 2021.3.2f1 to 2021.3.9f1 which might be the cause, except it has been a week and I don't know if the issue actually showed up at the same time. Can someone help me troubleshoot this? What settings should I review? My game's code seems to be fine, I haven't changed any of the input handling code since a while before I noticed the problem.
Oh, looks like this is a known issue in input system 1.4.1
How can I get this binding?
anyone know why I cant find the InputSystem.Flightsticks class anywhere in my project? I have a functional Joystick setup, but I want to implement Flightstick instead so I can have access to throttle etc
https://docs.unity3d.com/Packages/com.unity.inputsystem@0.2/api/UnityEngine.InputSystem.Flightsticks.html
this page suggests it would just be in the input system package, but no luck
Nvm I found out how.
You're looking at docs for version 0.2
Make sure you look at docs for the correct version
This annoying shit bugs me sooo much. How can I avoid it?
like what the fuck
nvm fixed
I'm using an on screen joystick for mobile input (that i added into a normal game that wasn't meant for mobile, just wanted to test it and it runs surprisingly well) but if i use it, i can't look around at the same time. IE if i start using the joystick first, the camera will move too. How do i handle that? How do i make a zone where the touchscreen doesn't work?
I dont know if this belongs here but i'm getting crazy trying to figure why my input field (TMP) clears the content when i press back button on mobile (i already uncheck the "Restore on ESC Key" in case that counts as "ESC" but it stills clears the content)
@austere grotto when browsing docs using the drop, I can only access 1.4, google points me to 2.0 and manually subbing 3.0 just doesnt give me any docs
1.4 is the latest release afaik. You were looking at 0.2
aaand im a massive drongo
my brain really caught onto that being 2.0
That helps a lot thank you. Looks like they removed 'flightstick' at somepoint, so i'm back to square one on finding a way to access my stick throttle, but looking in better areas now at least
Hey all, Im using the unity input system implementation from the 3rd person controller. Ive managed to get hold to work from sheer luck but tap isnt working.
Ive added a debug to the state but it always, not matter the interval i give, returns a false new state. Any idea how to fix this ?
public void DodgeInput(bool newDodgeState)
{
dodge = newDodgeState;
Debug.Log("Dodge :" + dodge);
}
the dodge action type is value and control type is any
Action type should be button.
How are you actually hooking that function up to the input action?
The input system they created is like magic to me, I have no idea how it takes in an input. The script that interfaces with the inputs sets each actions as such :
...
public bool dodge;
...
public void OnDodge(InputValue value)
{
DodgeInput(value.isPressed);
}
...
public void DodgeInput(bool newDodgeState)
{
dodge = newDodgeState;
Debug.Log("Dodge :" + dodge);
}
If I change it to button it is the same problem. It only ever sets the dodge to false, never true
What is interesting is that if I set dodge up the exact same way as sprint, it only sets to false never true
this looks like you're probably using the PlayerInput component in SendMessages/Broadcast Messages mode
that's the thing that will call your OnDodge method
you should remove the tap interaction
remove all interactions and processors and use action type button
Ive removed all processors and interactions from dodge action and set it to button, saved the asset, but the dodge once again only debugs false.
could it be that both the dodge and sprint use teh same binding ?
shouldn't matter
Once again I really appreciate the help you are providing
what happens if you do Debug.Log($"val is {value.Get<float>()}"); inside OnDodge?
(also do you have any interactions/processors on shift?)
Ah I do, in sprint, Sorry i thought you wanted me to just remove it from dodge as sprint hold was working.
Ill try both of your suggestions
i meant in dodge
although I wonder if that affects things 🤔
So i removed the hold interaction on shift within sprint.
I then added your code to on dodge, and the output was only ever :" val is -1"
I changed it to passthrough , any and it then gave -1 (on press), and 0 (on release)
what happens if you unplug your controller? (do you have a controller plugged in?)
Does that change anything?
-1 is strange - should be 1 usually for a keyboard press 🤔
Ngl im so imbarrased to say this, but there was an invert modifier. It was small so i didnt notice it, im so sorry.
So should I now try button with tap processor ?
So should I hard code for tap ?
As I want the player to roll on tap and sprint on hold, similar to warframe.
wdym hard code
the problem here is you're using SendMessages mode which only gives you an InputValue which is a vastly simplified data structure than you get using other methods
your best bet without changing that is to perform the roll directly inside OnDodge
rather than having it set a bool value which you check later
void OnDodge(InputValue v) {
if (v.IsPressed()) {
PerformDodge();
}
}```
So instead of using the tap and hold interactions, I have my own timers in my dodge script, and sprint script.
On dodge and On sprint will occur at the same time with this method, but id like tap = dodge and hold = sprint. In both cases using the shift key
A so the foundation is the problem. So maybe my soln is changing from send messages to unity events.
I see. Which method would you recommend?
unity events will be better
you'll get a CallbackContext which will have more information
Tyty thanks again for helping me and holding me hand through the experience, it is greatly appreciated
I want for the player to need to hold shit to sprint, what should I do ?
remove all interactions and processors from the binding
simple set a bool to true when the action is started and false when it is canceled
Is there an IPointerClickHandler equivalent for the new system?
wdym IPointerClickHandler has nothing to do with the input system. it deal with Event System
you just want mouse clicks you mean?
Yeah, I was under the impression it wasn't working with it. I have a UI item that uses it but its not picking up any clicks, so I was under the impression it just wasn't working because of the input system.
did you upgrade the Event System
Was unaware about any Event System upgrades, so I'ma go with a "no"
if u add new input package, you should see a prompt on the event system in the scene, to make u switch it to the new version
I'm guessing you're talking about the "Add Default Input Modules"?
..Nevermind, I got it. Thanks.
ohh ok good!
just going through the player movement guide in the pinned post, up to the part where i test it all and i have no player movement, i also have no errors. Is there a common mistake thats made? or things to check
only thing i couldnt do is set my projects api to .NET 4.x as it only shows .NET or .NET 2
which player movement ?
the pinned post
ive got it moving, sort of haha, ill finish the whole guide and see how it turns out
Every guide i find is all different to each other, so confusing xD
There are many valid ways to use the new input system, which makes it confusing for newcomers.
I need some help debugging; as with my earlier problem, I'm using IPointerClickHandler and my monobehaviour isn't receiving and function calls. I gave it a Debug.Log statement to show if it was called at all, and its not being called. Its attached to a game object with an image component that is enabled and has a sprite with a positive alpha. The event system has the updated input and has mapped player actions to a "Pass through - Button" for both the left and right clicks, as well as a "Pass through - Vector2" for the Point field.
Make sure your canvas has a graphic raycaster
Also generally the default input actions asset is sufficient for the action mappings in the input module unless you have special needs
While I didn't recognize its need, it is there.
Checked the documentation, and it asks for those settings.
Make sure Raycast target is enabled on your image as well and that it's not blocked by any other objects
Raycast target is ticked true.
The Image component also isn't covered up by any others; it is a child component of another UI element that has its own image component, but it serves as a background. Nothing is in front of these.
Hold on, that may be it. I have a textfield that only shows at the bottom portion of it, lemme see if thats the issue.
That was it, thanks @austere grotto !
How might I keep it from blocking the raycast though?
Sorry for late reply. Thanks, worked amazingly
Every video i watch on the input system, it is coded differently, is there a "best" way to do it or does it not matter which method is used? such as events or using the send messages way
my game will be including multiplayer if there is a way optimal for that
There are many different ways all with different advantages and disadvantages
"including multiplayer" is quite vague
I reall thought i had this whole "new input system" down and understood it. I used it for my whole project and everything worked fine. I've been using several Control Schemes, binding joysticks, gamepads, keyboard, mouse, virtual joystick. I recently decided to change something in the way my touch input worked. Instead of just reading the value in the Update loop, i decided to subscribe to started canceled and performed events so i could keep track of an offset (instead of moving under the mouse/finger you could touch somewhere on the screen and that would be the offset - your movement would be based off the "starting position".
private void OnEnable()
{
// TouchSimulation.Enable();
// EnhancedTouchSupport.Enable();
_camera = Camera.main;
_actions = new PlayerControls().PlayerPointer;
_actions.Position.started += TouchStarted;
_actions.Position.canceled += TouchCancled;
_actions.Position.performed += TouchPerformed;
_actions.Enable();
}
I played around with the Actions trying to get it to work but i can't seem to get any of those events to fire...
My action type is Value (i tried passthrough and button as well) and my Control Type is Vector2 (i tried any as well)
My binding is Position [Mouse] but i tried a lot of different types...
I sometimes get a single started - many performed but never a canceled - meaning the first touch will be the offset - if i lift the finger/mouse it won't fire a new started.
Right now, no events ever fire.
I can't help thinking i'm missing something important but i can't seem to grasp what that is?
hey i just started using unity a couple days ago and wanted to make an fps shooter so i followed this tut
https://www.youtube.com/watch?v=rJqP5EesxLk&ab_channel=NattyCreations
i followed it step by step but at 8:12 he does the code "playerinput = new PlayerInput();"
and when i wrote it it gave me error cs0029. anyone know how to get it fixed?
The first video in a series where we are creating a First Person game!
In this video we look at setting up our characters movement.
I've setup a Discord!!! and I would love to have you help me start up a friendly community where we can all help each other grow as game developers!
Discord invite link:
https://discord.gg/xgKpxhEyzZ
Can't wait t...
My guess is that there are two PlayerInput classes. The default one and one that you created
Show all the code above
If i press my finger on the phonescreen and then drag that finger around - how do i know when and where i started the movement and how do i know when i lifted my finger again? How can i also read it, if the process is repeated somewhere else on the screen. This sounds like a simple and common use case. I watched several videos about the subject but none showed me how to capture the first touch point and how to to know when the finger is lifted. Is it not possible in unity with the new input system?
Or do i need two actions? One to track the movement/position and one to track the finger press and lift?
Hi any idea where this performance issue can come from ?
I get this 30ms spike pretty often
Could anyone help me with a Inspector referencing issue with my array of a custom class? The second item I add in the inspector window seems to be referencing the first item in my array and when I go to edit the second item, it seems to be editing the first item as well.
Hey. What's way to get a character to rotate to mouse position in 3d with the new input system?
Is the new input system more fast and optimised than the classic GetAxis
performed I use for single fired actions, but when I'm doing mouse dragging, I'd only use started and canceled, while using a bool to check every frame for which I'm currently dragging. No clue how you'd go about doing multiple drags, perhaps you'd create multiple input actions for a number of drag inputs, and then make a queue which you check each time a drag is made.
I only get these errors when i connect to the game and a remote player is playing. If i join solo i dont get these errors. The input's are only active for the local player, as i destroy the components for remote players. does anyone know why this would be happening/
if (GetComponent<Player>() == null) //`Player.cs is local player
{
Destroy(GetComponent<FirstPersonController>());
Destroy(GetComponent<CharacterController>());
Destroy(GetComponent<UnityEngine.InputSystem.PlayerInput>());
Destroy(GetComponent<InputHandler>());
Destroy(GetComponent<GamePadInputEvents>());
}```
Destroy(GetComponent<UnityEngine.InputSystem.PlayerInput>()); this line is causing the three errors
perhaps i need to disable it first? idk
any time i destroy an object with the component on it, it just spams the console, Why is this a thing
It's logical, you are doing a GetComponent without checking the return so if the Component does not exist you pass null to Destroy
Null checked it, still gives the errors
which is the destroy line
That is really odd
So I'm having an issue with the Multiplayer Input System where the first player is not getting UI inputs but the second player is. I'm not understanding what is going wrong
My set up
I have the PlayerInput component on a Player GameObject and I have the Multiplayer Event System on a child object of the Player GameObject. What is weird is if I have 1 player this set up works. But when I add a second player only player 2 gets UI inputs.
Hopefully someone can help me out because I'm super confused as to why this doesn't work as described in the docs
After messing around with it a bit it seems that it is only letting me process input for the last player that was joined through the Player Input Manager 😕
After more testing it seems the Canvas Group that gets attached during player joining has its interactable state set to false when a new player joins 😕
Not understanding why that is
Anybody have a script for brackeys 2d movement converted to the new input system?
How can I get mouse movement?
By binding an input action to mouse delta
This makes very snappy rotation
this doesn't in and of itself rotate anything - it merely fetches the current mouse delta
This is where it actually rotates
multiplying deltaTime is incorrect
mouse input is already framerate independent
ah
Now the problem is that it snaps to angles vertically
it's not smooth rotation
Oh it was just high sensitivity fucking it up
it'll be as smooth as you move your mouse... and as fast as your sensitivity allows
using a mac and input system isnt recoginising the built in keyboard, input.devices length is zero
anyway around that?
no input is recognised on mac at all. no mouse no nothing
I'm not sure if my problem is with the input system or something else but after I changed from the old input system to the "new" one my movement has completely broken down. I can only move sideways and even after I look anywhere else the A and D keys move on the same axis as they did when I was facing forward. It almost seems like there's a wall behind and in front of the player. Has anybody else had this problem before or can anybody help.
I have made the scripts for movement and mouse and checked through them multiple times but can't figure out what's wrong
i am having some issues with my code that will not recognise my vector input for my second action map. i change to my new actionmap and the vector input stops working. buttons per se works though which is strange
i seem to be able to get vector debug output from the input context but it does not register into the variable i am trying to store it into
oh... just figured out that i was instancing the thing that i wanted to switch action map to use. this is a no no, because of it not being the same entity
i feel silly 🤔
Heyo, Im trying to subscribe to an action event. Do i have to do it through the generated c# class, or can I not do it through the input actions asset ?
PlayerInput component
you pass in events like you would like a button OnClick
you can use the generated class, or the player input component
example
Ty ty
You can do it either way you mentioned or the way Don mentioned. They all work
Could someone explain to me what's happening under the hood?
I understand that the InputActionReference calls the function Fire with context when the key bound to it gets pressed
But why the += syntax? What really is m_Fire.action and m_Fire.action.performed?
The += syntax is a delegate subscription to a method in your script called Fire. When performed is triggered, it will call your Fire method and execute what's in there, along with giving you a CallbackContext struct datatype, which contains some helpful information like what action got triggered.
m_fire is your action map, it contains a list of actions. You can have multiple action maps which help you sort your actions, and allows you to easily disable and enable a set of actions depending on the situation. Your actions are your buttons which you assign an input to.
Oh, and performed is the trigger method, and in this case is used in a trigger once scenario.
performed is an event.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/event
Yeah thanks
Hey guys i am trying to use the new Unity Input System and want to Check in which direction i am moving. currently i am checking like this:
{
playerMovement = value.Get<Vector2>();
}
public void ThrusterMovement(Vector2 playerMovement)
{
if (playerMovement == new Vector2(0,1))
{
transform.GetComponent<Rigidbody2D>().velocity += playerMovement * 5f * Time.deltaTime;
thrusterEmmision.enabled = true;
thrusterEmmisionIdle.enabled = true;
thrusterAudio.enabled = true;
if (thrusterTwo)
{
thrusterEmmision2.enabled = true;
thrusterEmmision2Idle.enabled = true;
}
else
{
transform.Rotate(new Vector3(0, 0, (rotationvelocity * 0.8f) * Time.deltaTime));
}
}
else
{
thrusterEmmision.enabled = false;
thrusterEmmision2.enabled = false;
thrusterEmmisionIdle.enabled = false;
thrusterEmmision2Idle.enabled = false;
thrusterAudio.enabled = false;
}
if (playerMovement == new Vector2(0, -1))
{
transform.GetComponent<Rigidbody2D>().velocity -= playerMovement * 1f * Time.deltaTime;
}
if (playerMovement == new Vector2(1, 0))
{
transform.Rotate(new Vector3(0, 0, -rotationvelocity * Time.deltaTime));
}
if (playerMovement == new Vector2(-1, 0))
{
transform.Rotate(new Vector3(0, 0, rotationvelocity * Time.deltaTime));
}
} ```
The Problem is that if i want to move to left or right while moving upwards the player doesnt do both.
I am currently checking with a "new Vector2(x,y)
But i would like to check it with the Input i am doing like "W" "S" "A" "D"
Read some docs for delegate and events and I think I now get it. Thanks
What is a clean way of disabling an action map through an input manager while using 'Player Input' components? I read that they all have their own inputActions script instance so simply calling inputAction.Enable() won't work, and yes, I've tried....
help i got an error with the new input system
idk what the hell is going on but i dont like it
im trying to make a cod like movement system, how do i do that?
thats outside the scope of this channel
?
movement system != input
we need more specific qurstions
okay fair
Why does InputActionTrace stop recording values once you call .Clear() on it? Am I being dumb and misunderstanding what Clear() is supposed to do? As far as I can tell it just completely breaks the InputActionTrace causing it to just sit around and record nothing. I also tried resubscribing to my InputAction after the Clear() but it just sits there and records nada. I thought that method is for resetting the internal buffer in order for the memory to not balloon forever. Or are you supposed to just, Dispose of it and new it again every 5 seconds or something to get rid of the memory?
Context:
I'm using the new InputSystem and currently have the need to lookup past inputs of buttons/sticks to disambiguate between "letting go of the stick" and "flicking past the deadzone".
Basically I'm trying to make an input buffer that lets me record and lookup the past X values for an InputAction to drive my input logic.
So when looking around I came across InputActionTrace which does the recording part and getting out the values is ez pz.... if you don't call Clear() on it.
Anyone have any pointers for clearing the memory of an InputActionTrace without breaking it or any other onboard construct to use?
Please someone tell my I'm a baka before I just start manually dumping the values into an array and wrap it with my own class or give in and new the InputActionTrace every n-th frame
https://stackoverflow.com/questions/73767326/raycast-not-capturing-all-vector-coordinates hi can someone help me on my problem
wdym by "not storing all the coordinates"?
yes as you can see I compared the mousePositions and linePositions count they're not the same. mousePosition count are always greater
well you're only adding to the line positions if your raycast hits
presumably sometimes the raycast is not hitting
The whole screen is occupied by gameobject
Debug.Log
see if there are times when the raycast doesn't hit
that's where I'd start
for some reason I cant figure out why the new input system doesn't seem to work (probably me just dumb) every time I run I get a compiler error saying
INPUTASSETNullReferenceException: Object reference not set to an instance of an object
PlayerMovement.Update () (at Assets/scripts/PlayerMovement.cs:59)
what I'm trying to do is to recreate the old input system's get key function here is my code
https://paste.myst.rs/p5xdr3pn (sorry if its bad kind of new to unity) i get the error on line 59
a powerful website for storing and sharing text and code snippets. completely free and open source.
I am trying to figure out the proper way of implementing the "new" input system in a multiple-scene game. In runtime have DontDestroyOnLoad where I keep project context stuff and scenes like Combat, Exploration, and so on. I want to keep PlayerInput in DDoL since I want just one instance of it for one player and subscribe/unsubscribe input callbacks in specific scenes (combat-related in combat, exploration in exploration, and so on). Because UI interaction is common for all of those scenes I wanted to subscribe UI input only once, in DDoL init.
Here are my questions:
- Since I want to keep PlayerInput in DDoL I shouldn't be using new InputActionAsset() ctor in every scene, right? That would bypass the concept of PlayerInput actually controlling the input, switching maps, and so on because every scene would have its own input action asset. From what I understand these runtime-created input assets are not connected to PlayerInput and are not controlled by it.
- If so, how to properly pass a reference to PlayerInput to different scenes? I am using DI in my project and injecting PI causes weird problems either with unsubscribing actions in OnDisable or when using FindAction(string) in OnStart().
The New Input System keeps referring to Events and Actions. Behind the scenes, are these C# and/or Unity Actions and Events?
Yep, the input system is built around C# events and subscribing to methods, reducing amount of input polling you'd do otherwise.
Heya,
So im currently trying to do some stuff with VR.
I was wondering if there was any documents/examples about connecting Input devices (e.x Joysticks, Gamepads, huggable pillows) with USB-A to USB-C converter or bluetooth.
Or if it was possible to use a different input system and having the game on a VR.
Also is it possible to get the amount of input buttons on an input device and the name of the button?
Anyone have any tips?
Thanks in advance!
How do I use InputAction.ApplyBindingOverride(0, ""); to bind a key to "None"?
Or I suppose, is there an InputAction path for "none"
Or another way to unbind an action?
Hi, i'm having trouble canceling an action (for example walking) with the same button press when the action is being performed
here's my Awake() code
private void Awake() {
_playerActionControls = new PlayerInputActionControls();
_playerActionControls.Player.Move.performed += ctx => _movementPressed = _movementInput.x != 0 || _movementInput.y != 0;
}
so what's the logic behind canceling an action that's being performed
How do I spawn an UI under the mouse with the new InputSystem? O.o'
a tooltip, in my case... I don't get how to convert the coords 😕
{
Vector3 tdPosition = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue());
Vector2 position = new Vector2(tdPosition.x, tdPosition.y);
float pivotX = position.x / Screen.width;
float pivotY = position.y / Screen.height;
rectTransform.pivot = new Vector2(pivotX, pivotY);
transform.position = position;
}```
The tooltip still get positioned on the bottom left 😕
Ok transform.position = Mouse.current.position.ReadValue();
Fixed the issue now I need to find a way to keep it always on screen 😅
Is this how the input system should be used?
absolutely not
you should not be subscribing to an event every frame
how should it be used then?
poll?
I am rn.
this code is not reading the value in update, it's subscribing to the event in update
isn't that the same as
reading the value would be like playerControls.Player.DropPickupLeft.WasPerformedThisFrame()
not even close to the same, no
if (Input.GetKeyDown(somekey))
{
PickUp(0);
}
?
reading the value each frame like my example is similar to that, yes
just replacing Input.GetKeyDown(somekey) with playerControls.Player.DropPickupLeft.WasPerformedThisFrame()
I thought it was more organized to create a function for only input.
it's up to you
what does .performed even do?
it's an event
I know.
that gets fired when the action is performed
it depends on how the particular input action is configured
getkey?
for a button action, it's very similar to GetKeyDown, yes
Pick one
how?
Can you think of any way to only run code one time at the beginning of your script's life?
awake or start.
although won't that mean that you must hold the button when the game is loading?
and then you can't trigger it anymore?
no
you're not understanding how events work
it would be subscribing to the event at the beginning
oh
that subscription lasts forever
like this?
sure
or this?
doesn't matter
Hi, i'm having trouble canceling an action (for example walking) with the same button press when the action is being performed
here's my Awake() code
private void Awake() {
_playerActionControls = new PlayerInputActionControls();
_playerActionControls.Player.Move.performed += ctx => _movementPressed = _movementInput.x != 0 || _movementInput.y != 0;
}
_movementPressed bool stays true when i'm moving so how do i cancel it with the same button press when i'm moving to stop
Not sure I understand exactly what you're trying to do here? Can you explain what the actual gameplay goal here is?
when my character is moving (_movementpressed bool is true) i want to make it stop with the same button press like many games do (when you are running and press run button again the character stops
so is this for sprinting?
yes but if it works in sprinting it works in other toggle stuff too
?
let me share the sprint code
I'm confused about what the Move action actually is
is this a sprint button? Or joystick input?
both lol its the new input system
I know it's the new input system...
How can joystick input be both a sprint button and move input
which is it
yeah
so this code is confusing to me because I don't understand what it's actually supposed to be doing? At no point are you actually reading in the direction input from ctx
there are several ways of reading input in the new input system this is the one that worked for me so i used it
it works great but the problem i don't know how to cancel the action with the same button press that activated it
_playerActionControls.Player.Run.performed += ctx => _runPressed = ctx.ReadValueAsButton();
bool isSprinting;
void OnEnable() {
_playerActionControls.Player.Run.performed += ctx => isSprinting = !isSprinting;
}```
here's the run
something like this
i forgot to share it my bad
this is on the OnEnable() function so should i move my code to this function ?
it doesn't really matter
because it gets activated only once right ?
that's not an important detail here
Awake only runs once
OnEnable runs every time the script is enabled
_playerActionControls.Player.Run.performed += ctx => _sprinting != _sprinting;
maybe try copying what I wrote accurately 😛
it worked bro now when i'm running and click the run button again the run gets cancelled thanks a lot i've been having this problem since ages XD
Hey could someone explain to me what purposes are "scheme" and "map" supposed to serve?
action maps are just named collections of input actions
From my understanding, it's to put the actions under a two-layer categorical structure
But why do we need these two layers?
Say, why can't I just use one scheme and many maps for everything?
And schemes are named collections of maps? Is that so?
schemes are sort of like "filters" for bindings so that only bindings associated with a certain control scheme are active at once
a scheme is like "mouse and keyboard" or "gamepad"
they are completely parallel to the concept of action maps and actions
Here's why I'm confused. I saw tutorials where said the schemes are for different device types, but nothing stops me from doing this?
this is exactly the point of schemes
why would you be stopped from doing it
I made them so. The question is why would it be a bad thing?
It's up to you to define which devices/device types are part of a given scheme
Why should I consider using the scheme feature to separate them?
Several reasons:
- it gives a way for unity to automatically split up players by devices in local multiplayer games
- It makes it a lot easier to show contextual on screen prompts like "Press X to climb" vs "Press Space to climb"
Cool, valid points those are

How do I use a joystick push as a button?
I can read the Vector2 value of a joystick, I get it. But what I'm trying to implement is to set a deadzone, and once the joystick gets pushed beyond the deadzone, it's registered as a one-time event, like a button press
Anyone ever heard/experienced keys getting 'stuck' when shift is held? For me the Input System specifically no longer registers any keyboard input changes when the shift key is held.
I'm on Linux and submitted a bug report about 13 days ago but haven't heard anything
Fair few threads on google about it, none with either a solution or a dev response
or am i doing it completely wrong and should be using unity events?
you dragged the wrong thing into the slot
you dragged the script in
you need to drag in a GameObject that has the script attached to it.
really
Would appreciate it if someone could help with this ❤️
new input system or old?
new
deadzone can be configured on the action itself or the binding with a press interaction.
as for reading it like a button, just make it Action Type: Button
The binding is unsearchable when action type set to button
I guess I can still manually put the path in there but is that gonna work?
setting it to value/vector2 should work too, just put a press interaction on it
How do I define the press behaviour?
Oh nvm I think i can find it in the docs
Thanks
Thanks. Exactly what I wanted
Can someone tell me what "Press Point" means for Tap interactions?https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Interactions.html
Nvm, found out via the tooltip that's it the min time the button is to be held.
Anyone know why I cannot put a Hold interaction on a WASD/move Vector 2 action? The only little info I've been able to find is that Hold is invalid on Vector 2 types
This my workaround, not pretty but I can get what I need from it:
Eh actually since it's a WASD/directional binding that won't work if I have other keys held down. I might resort to doing it manually
For now I'm going with not using a composite binding and creating actions for each of the 4 keys. I get way more flexibility here and the keys are more independent. For UI I have a separate action map that uses the usual composite/vector2 binding instead
Hey I'm trying to get UI support working for a VR mod. I made a custom BaseInputModule and it's pretty much working for canvas stuff, but I'm having trouble with colliders in the scene that are listening to OnMouseEnter etc. The game uses a separate camera to render the UI which isn't necessarily in the same place as the game camera. But I'm wondering if OnMouseEnter etc aren't even triggered by the EventSystem - are they completely separate?
I'm starting down the path of just calling OnMouseXXX directly based on raycast results from the VR laser pointer, but if those things are supposed to work from the EventSystem then I'd probably rather use that.
Hey! I am working on a local multiplayer game and I got everything working BUT one thing. In a specific section of the UI, I want to disable the functioning of the second gamepad, however, I can't seem to find anything which can help me with that.
The old Input System had the option to to set the Joy Num. Any help = ❤️. Stuck on this for a while
you are trying to make each player have their own separate UI or what
Yeah, I have a part in the game where players have to select cards (individually). It's all there, except that Player 1 can interact with the UI while Player 2 is choosing the cards and vice versa - which is annoying as you might get haha
The new system has a special event system that is per-player
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.4/api/UnityEngine.InputSystem.UI.MultiplayerEventSystem.html
Cheers, I'll make sure to look into that 😄
Using InputAction.CallbackContext is it possible to get the processors applied to input? I want to check to see if my mouseDelta is being scaled down.
How do i grab the second action in this in code?
and can i add / remove pre-processors on it at whim
huh dont they both use Aim
yes, but i need to do something with the controller assignment
private bool toggleADS = false;
public bool ToggleADS
{
get => toggleADS;
set
{
toggleADS = value;
int isOn = value ? 1 : 0;
aimAction.controller.Processor = value ? press : null;
PlayerPrefs.SetInt(PREFS_TOGGLE_ADS, isOn);
}
}``` as an example, second to last line is entire psuedo code
ah ok that makes more sense
yea, i just want to add and set Press if value, else remove it
is it not InputBinding?
I dont know, thats why im asking
on the processor doc, doesnt look like i can add and remove them
oh, i should be looking at interaction docs
can someone help me?
these are different bindings not actions
Yea, I ended up making two actions and disabling /enabling the appropiate one
Does anyone know how to setup keybinds to a float? So for example when W is pressed I want the float to be 1, when S is pressed I want the float to be -1, and untouched is 0.
I ended up using a press/touch to register started and cancled and then i used the position (another input) to track the position only when the the touch was after press but before cancled...
This is just a standard axis
In fact that axis is built in by default
How can I do something like this? I want it to debug "Q", because that's what DropPickUpLeft is binded to.
Nvm, this did it: ```cs
Debug.Log(rebind.Player.DropPickUpLeft.GetBindingDisplayString(InputBinding.MaskByGroup("Keyboard, mouse & gamepad")));
why the inputs of the new input system are delayed and sometimes they don't work?
Doubt it's something with the new input system or no one would use it lol
after i change to the old one, it doesn't lag or delay the inputs
then your implementation of the new inputs is incorrectly setup
i followed a tutorial...
and? most tutorials are shite
the one from Dapper Dino
then you did something wrong in between. Pretty sure that one is one of the rare solid YTbers
Hey, is there any way for me to get the controls object to respect the current control scheme on the player input object? I need to check input every frame, so using the events on the player input object won't work for me, but when I just read from the controls object, it doesn't disable input from inactive control schemes. By the way, "controls" is the name of my input actions.
How do i add looking with a Console Controller
the same action you have bound to your mouse
Not sure why that happened
do you have a Look action ?
yes
just add the gamepad joysticks as input
well you said How do i add looking with a Console Controller
how can that be from only adding gamepad to look
ye i dont know, but i'll figure it out
Hi there, I need some help on the new input system 🤔
I've got a simple button action for Sprint. While the sprint button is down the player sprints, and when the sprint button is released the player stop sprinting.
Things work well, I can use WasReleasedThisFrame or canceled to detect when the sprint action is canceled = when the sprint button is released.
BUT, when the sprint button is down, if I move the mouse the sprint action is automatically canceled (even is the sprint button is still down).
Does someone know if it is normal than mouse movement auto-cancel button actions?
Thanks !
Whenever i try to bind any gamepad key to the Movement action, it's always the right thumbstick who calls the Movement action even if i dont have the right thumbstick binded to anything. Anyone had a similar issue like this? I dont have any idea if this is just a bug or i messed up with something. And every other gamepad button just does not respond, it's always the right thumbstick. Using PS4 Controller connected via bluetooth
Two guesses. You've got another controller scheme you're initializing and reading from that. Or, your logic isn't set up with events and you're reading from the current controller directly each update.
That's the script. It works with different keys on keyboards but for controller only the right thumbstick triggers the event always
You'd have to show how you actually hooked this function up to the input
Also why would it work for keyboard at all?
You don't have keyboard bindings there. I think you've confused yourself with multiple input action assets or something
I added keyboard bindings for testing and it works fine there. But when i use the gamepad the right thumbstick always calls every action
Again show how you set it up
Hey, I just enabled automatic navigation for my UI. It's 4 buttons aligned vertically. It works so far, if I press the arrow down key, it goes down, if I press the arrow up key, it goes up, and when I press return, it "activates" whatever the button does. But I need it so it goes down on the right arrow key, and up on the left arrow key. How can I change this?
In your input module
An/or by using manual navigation
Thanks, that helped. Works now.
I get this error when trying to access the PlayerInputActionControls from another script
Looks like whatever field you're trying to access is not public
looks like i don't need to reference the existing action controls i just made a new one that takes from the existing one so problem fixed
Hello, I was wondering if anyone knew how you are able to reference specific gamepads as a variable so it is tagged and able to be used in a turn based game? I am trying to make a 4 player input system for a lobby where each gamepad is able to ready up a slot and need to figure out how to detect when a controller has already been pressed down thank you!
PlayerInputManager is there to handle this stuff automatically
If a PS4 controller is connected to my pc unity doesn't receive inputs from my keyboard and mouse anymore. Auto-switching is toggled on on all my Player Input components. Is there a general fix for this? The only way I can get my kb/mouse working again is to unplug the device or to remove if from the device list manually when using wireless
Sounds like you set up some exclusive control schemes?
I left the default schemes and just added a bunch of new controls to the keyboard scheme while leaving the controller one as default
Supported devices is set to gamepad, keyboard, mouse
Yeah sounds like you don't want separate schemes
Why not? What’s the difference?
Do i have to view each scheme as it being a separate player?
Not separate player, no
Just independent sets of devices that won't be used together
so if one is used the other simply cannot be used?
then what's the point of auto-switching control schemes?
Yeah I have already tried a little bit with the playerinputmanager but there arent many good sources out there at all im just trying to have 4 seperate inputs that can select up to 4 characters
yep that's what PlayerInputManager is for
alright thank you
So games where you can choose to use a specific controller or a steering wheel are the ones that use multiple control schemes?
That's the setup. Basically folowed the unity documentation and something i learned from a few tutorials. The keyoard and mouse scheme works fine, but as said the gamepad does work incorrect
Hi all, I'm trying to implement multiple input devices support.
I have 1 InputActionAsset in which I defined 1 custom ActionMap for my player actions, and 1 Action map for the UI (copied over from the package asset).
The issue I'm facing right now is that whenever I press a movement action on my keyboard, it performs a navigate action instead (from the UI map).
The current action map is set to my custom action map and never changes at runtime. Anyone know why this is happening? Using PlayerInput component with UnityEvents.
solved the issue above but now the mouse can't interact with ui buttons
you have a graphic raycaster on your canvas?
i do, yes
actually...
damn. I had a child canvas without a raycaster
thanks @austere grotto
Hi there. Currently attempting to use the PlayerInput component set to SendMessages instead of getting a reference to C# script. In testing, I'm attempting to have a character run a 'block' animation when a button is pressed, and stop running the 'block' animation when the button is not pressed. Unfortunately, the only message that's being sent is OnBlock, so my 'Block' bool remains set to 'true'. Is there a standardised method for creating an 'on released' event?
SendMessages is quite annoying to work with since all you get is an InputValue
if you use UnityEvents mode, you can get a callback context which will let you check whether the context is performed, started, or canceled
This is what I get for using the Unity Third Person Animation template as a testing ground. =D I'll switch it over... or try, anyhow.
@austere grotto Thank you, that worked perfectly.
Hello. Can anyone have a guess as to why my menu isn't navigable via mouse / keyboard, but it works fine with my two controllers? I have a keyboard set up in the input system.
how is your input module set up?
input module is what links the input system and the UI/Event System
I have this InputHandler script added
https://pastebin.com/dsZwrSBx
Not what I asked
You input module. It's a component that is most likely on the EventSystem object
Oh yeah thats on the first screenshot
I haven't added any custom scripts to it
Is this what you mean
yes
you'd have to look at all those actions you have set there
and see what bindings you have for them
As far as I'm aware they're completely fine
not sure where to ask this but
i got a script where holding down alt + WASD changes walking speed
but i cant actually see if it works
since alt + wasd or other keys opens up random stuff in unity
how to disable unity hotkeys in play mode?
nvm figured osmething out
player character movementpressed variable doesn't get activated unless i press vertical and horizontal input together
_playerActionControls.Player.Move.performed += ctx => _movementPressed = _movementInput.x != 0 || _movementInput.y != 0;
is this a question or?
there's an issue so its a question XD
the code clearly says that if one of them isn't = 0 then movement pressed should be on
but its not working as intended
both of them need to be pressed for it to activate
well where and how are those values set?
seems like that's coming from some separate code
_movementInput = _playerActionControls.Player.Move.ReadValue<Vector2>();
why is it not just:
_playerActionControls.Player.Move.performed += ctx => _movementPressed = ctx.ReadValue<Vector2>().magnitude > 0;```
why rely on some other code and reading the same input action data nonetheless 🤔
yep it works like a charm thanks a lot brother
🙏
Hello World
I am just using the new unity input, and I made a player which moves when clicked (w or d key) or (left or right arrow), there is this behavior
-1 while left key pressed
+1 while right key pressed
0 while none is pressed
the only issue I am facing is, if i press the left key and then release it my player continues to move in left direction it does not stop
private float _movementX;
private void Awake()
{
_myBody = GetComponent<Rigidbody2D>();
_playerControls = new PlayerControls();
_playerControls.Enable();
_playerControls.PlayerControl.Move.performed += context => { _movementX = context.ReadValue<float>(); };
}
private void Update()
{
MovePlayer(_movementX);
}
any help is appreciated
for this kind of control you're better off polling it in Update than using events
to fix this with events you'll need to also subscribe to the canceled event
e.g. cs _playerControls.PlayerControl.Move.canceled += context => { _movementX = context.ReadValue<float>(); };
To do it with polling you can remove all the event subscription stuff and just do this:
void Update() {
_movementX = _playerControls.PlayerControl.Move.ReadValue<Vector2>();
}```
this worked perfectly
while trying this, first error was cant use vector on float, so I fixed it by ReadValue<Vector2>().x but now I am getting some weird error
InvalidOperationException: Cannot read value of type 'Vector2' from composite 'UnityEngine.InputSystem.Composites.AxisComposite' bound to action 'PlayerControl/Move[/Keyboard/leftArrow,/Keyboard/rightArrow,/Keyboard/a,/Keyboard/d]' (composite is a 'Int32' with value type 'float')
sorry yeah it's supposed to be ReadValue<float>
I got confused because usually people use Vector2 for a Move action
(you should consider doing that if you have separate x and y variables...)
worked how I wanted it to, thanks a ton
I only have x values as of now
also, would you tell me why to use this instead of the other method
because it's a lot simpler
What do you mean by polling
polling means "checking periodically"
in this case, checking the input value every frame
alright, thanks a ton for helping me out
how would I pull a certain binding from an action? I have a dash function that isn't based on a vector2 value and i want it to dash in all 4 directions and have each direction being a double tap, and those directions are all under a dash action
How can I shorten this? ```cs
playerControls.Player.Jump.started += ctx => Jump(ctx);
playerControls.Player.Jump.performed += ctx => Jump(ctx);
playerControls.Player.Jump.canceled += ctx => Jump(ctx);
Also, what's the equivalent of GetKey in context.{...}?
why do you need all three?
exactly
doesn't make sense?
that's why I'm wondering if I can shorten it.
you only need performed, no?
Why would you need all three for an action like jumping
also you can just do playerControls.Player.Jump.performed += Jump;
you don't need the lambda
like context.started
no because the parameter is a callbackcontext.
So?
what should I put there?
ok
Write this:
playerControls.Player.Jump.performed += Jump;
that's all
don't change Jump
keep the parameter in the function
it will work
how in the world is it supposed to know what the context is then?
the event passes it to the function when it is invoked
invoked?
I have an inquiry that the replied message replies to.
Common sense imo.
I don't understand what that inquiry means at this point of the conversation
we're well past that
what
If you have a question just ask it
There isn't a direct equivalent
what we're doing with these events etc is the equivalent
it returns a bool telling you if the action is currently in the performed phase
bruh
literally not what I meant.
I don't know what you meant I guess. I answered the question you asked though
What does the performed input state do in the new input system that was released about 4 years ago in Unity?
performed in relation to an input action is an event that gets fired when the action "happens"
after started?
performed in relation to a Callback Context e.g. ctx (which you asked about the first time) is a bool property saying "is performed happening right now?"
sometimes
depends on the interaction set for the action
the system is somewhat complicated
so what exactly should I use for GetKey?
what should I use instead of getkey?
gameplay wise
I'm trying to detect if a specific key is currently being pressed.
void Update() {
bool isCurrentlyPressed = myInputAction.IsPressed();
}```
yeah I know about that.
that's more or less the GetKey equivalent
Although I'm asking about the InputActionAsset equivalent.
the point of using the events etc is to not check in Update
InputActionAsset is ultimately just a collection of InputActions
with which you would do as I showed above
I mean this.
that's the input action asset inspector, yes
what about it?
public InputActionAsset myInputActionAsset;
void Update() {
InputAction myInputAction = myInputActionAsset["SomeActionMap/SomeAction"];
bool isCurrentlyPressed = myInputAction.IsPressed();
}```
InputActionAssets do not contain a definition for IsPressed().
is that what you want?
of course not, like I said they are containers for many input actions
already checked it out.
so what are you asking that hasn't been answered at this point
what the equivalent of getkey is for inputactionassets.
this
playerinput isn't an actual name.
yes it is
look at the title there
yes
that's the name of the component
that I set.
just like a Rigidbody is called a Rigidbody
oh
you did not set PlayerInput
I thought I named it.
You set "PlayerControls"
that's a different thing. That's the Input Action Asset
which we discussed already
yeah
so isn't this for PlayerInputs?
do you see anything there that says PlayerInput?
so are we just doing free word association?
PlayerInput makes me think of joysticks which reminds me of arcade games like Street Fighter
since when was playerControls an array?
"myInputActionAsset["SomeActionMap/SomeAction"];"
yes this is the magic of C#
lol
you can give indexers to types
See look InputActionsAsset has an indexer that takes an action name
brackets dont always mean arrays
to find an InputAction
CS0021: Cannot apply indexing with [] to an expression of type 'PlayerControls'
Why are you doing it with a PlayerControls
what should I do it with?
my example uses InputActionsAsset
isn't that what it is?
No
okay I wanna use playerControls for it.
PlayerControls is the generated C# class you created FROM your InputActionsAsset
if you want to use PlayerControls you'd do something like:
PlayerControls myPlayerControls = new PlayerControls();
void Start() {
myPlayerControls.Enable();
}
void Update() {
InputAction jumpAction = myPlayerControls.Player.Jump;
bool isPressed = jumpAction.IsPressed();
}```
😵💫
I agree
Doesn't playerControls.Player.Jump.IsPressed(); also work?
yes
I separated it it to highlight the fact that playerControls.Player.Jump is just an InputAction
and that all of this discussion was a circuitous way of just saying the same thing I said back here
ok
no, that doesn't do anything.
the player doesn't jump.
what does the code in the Jump function look like?
although it does jump, but it doesn't crouch.
So it does jump...
So shouldn't you be asking about Crouching?
yes
public void Crouching(InputAction.CallbackContext context)
{
// Start crouching
if (context.started)
{
crouching = true;
transform.localScale = crouchScale;
transform.position = new Vector3(transform.position.x, transform.position.y - 0.5f, transform.position.z);
if (rb.velocity.magnitude > 0.5f)
{
if (grounded)
{
rb.AddForce(orientation.transform.forward * slideForce);
}
}
}
// Stop crouching
if (context.canceled || (crouching && !playerControls.Player.Crouch.IsPressed()))
{
crouching = false;
transform.localScale = playerScale;
transform.position = new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z);
}
}