#🖱️┃input-system
1 messages · Page 58 of 1
Yes
Still doesnt explain why the player that actually uses the joystick refuses to move
well that'd be related to your other code
public void PlayerThrottleJoy(float inputJoy)
{
//Multiplies ThrottleSpeed and ReverseSpeed with input, all are independent float variables
//Sets the independent variables to the front/back axis and creates some new independent vector variables
float throttleForceJoy = (inputJoy) * throttleSpeed;
float reverseForceJoy = (inputJoy) * reverseSpeed;
//If there is a positive input, lerp from the current velocity to what the max speed is (throttle force) with an interpolation of the acceleration force
//Joystick
if (inputJoy > 0)
{
currentVelJoy = Vector3.Lerp(currentVel, new Vector3(0, 0, throttleForceJoy), throttleAccelerationForce * Time.deltaTime);
}
//If there is a negative input, lerp from the current velocity to what the max speed is (reverse force) with an interpolation of the acceleration force
//Joystick
else if (inputJoy < 0)
{
currentVelJoy = Vector3.Lerp(currentVel, new Vector3(0, 0, reverseForceJoy), brakeStrength * Time.deltaTime);
}
//if there is no input, lerp from your current speed to zero
else if (inputJoy == 0 && currentVel.z != 0)
{
currentVelJoy = Vector3.Lerp(currentVel, Vector3.zero, throttleDecelrationForce * Time.deltaTime);
}
}```
well none of that actually moves anything
oh yeah mb
private void FixedUpdate()
{
Vector3 direction = transform.TransformDirection(currentVel + currentNitroVel);
rb.AddForce(direction - rb.velocity);
float speedovalue = rb.velocity.z;
speedovalue = Mathf.Abs(speedovalue);
speedovalue = Mathf.RoundToInt(speedovalue);
}```
the thing is that it works for kb but not for my joystick
none of that reads currentVelJoy

so I can't see how the above code would affect it
forgot to add it there
it does work, just hella slow though
atleast thats one issue solved
Is this the right place if I have a question regarding input and I'm using Rewired?
I have a specific case that I can't find a solution too and would love some new ideas to try.
Yeah this would be the best channel probably
But Rewired I believe does have its own forums and/or discord
I didn't find a discord or forum, only a help section with FAQs. But I do remember in the past seeing a forum... If anyone have the link please let me know.
what's the input for nintendo switch joy cons
Here's the challenge I'm facing :
I am using Rewired, my game supports controllers, keyboard and keyboard mouse.
In my UI I have selectable buttons with transitions handled by an animator (press, highlighted...)
When I use the mouse and over on a button, the highlighted state is on (expected).
If at that moment I move my controller joystick to another selectable button (switching input mode) , the previous selected button stays highlighted (since the mouse cursor is still on it).
I can't find a working way to force that previous button to stop being highlighted.
UPDATE
Finally found a solution that works. I'm still surprise that this is not handled more gracefully by Rewired / Unity.
I made an adaptation of this solution : https://answers.unity.com/questions/1130654/clearing-mouse-hover-effect-when-cursor-is-hidden.html
UPDATE 2
Here's a simpler way that works too.
// Put this code in a Controller changed callback if (controller.type != ControllerType.Mouse) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } else if (controller.type == ControllerType.Mouse) { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; }
Anyone possibly know how it's possible that I'm getting an error where
InputAction.CallbackContext MoveInputCtx;
MoveInputCtx <====== is not null
MoveInputCtx.action <====== is null
Well what's the error?
hey i'm new to unity, will this https://assetstore.unity.com/packages/tools/input-management/joystick-pack-107631#reviews working on webgl for mobile? i just read that unity doesn't officially support webgl mobile yet
if i have all my inputs in 1 script and generate a single instance of the PlayerInput script my inputs work fine, but when I split the keyboard and gamepad inputs into their own scripts each generating their own instance I get Null Reference Exceptions when i press my inputs, anyone know why?
nevermind, twas me being silly
I'm looking for some input (pun intended) in regards to the different ways to implement the "new input system." Specifically, a comparison of the PlayerInput component vs using the class and interface generated from the InputActionAsset. Any good links/blogs comparing the two methods? Or maybe someone's personal experience?
I'll just chime in to make your life harder and say that there are even more options than that:
- InputActionReference
- InputActions and InputActionMaps defined directly on a MonoBehaviour
- direct InputActionAsset references
Yep, aware of those as well. Didn't seem like good options unless you have reason to believe so...
I like the generated class and interface. Just wondering about shortcomings and any caveats/gotchas that will rear their ugly heads later on.
PlayerInput on a singleton that you use to dispatch events can also work pretty nicely
Reduces the amount of manual work involved overall
The generated class "works" but it's pretty janky
I discussed the word janky with my protocol droid and it did not compute. Can you be a little more specific? 🙂
Awkward to work with and the code it generates is a bit of a mess
It also unfortunately doesn't implement the interfaces it provides on the generated types, which I remember being a pain point
What type of messaging are you using on your Player Input singleton?
The singleton has a PlayerInput component and then another component that receives the input events from that via SendMessage, which then call C# events
Got it.
It can be handy when you want to use PlayerInput but don't want it to be on the actual player object itself
i.e. in a multiplayer game
Since that would result in multiple PlayerInput components active at one time, when you only one want to represent the local player
So your not capturing the InputAction.CallbackContext? That's not possible with SendMessage, correct?
The SendMessage approach receives a type that wraps the callback context
Specifically, it gets an InputValue, which gets recycled between messages to avoid allocations
Didn't know that. Haven't seen examples.
The InputValue contains the callback context, but you can't retrieve the context directly from it: https://github.com/Unity-Technologies/InputSystem/blob/develop/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs
The first example here in the docs uses it: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.3/api/UnityEngine.InputSystem.PlayerInput.html
So for example, I might have something like:
public event Action<Vector2> Move;
private void OnMove(InputValue value)
{
Move?.Invoke(value.Get<Vector2>());
}
On my "listener" component
Yea, I see it now. Guess that's what I get for watching outdated youtube videos.
There's a surprising number of those for the input system lol
Worked like a charm. I kept wondering why the Unity Event and C# Event message would have a context and the SendMessage not. Thanks.
SendMessages is unfortunately pretty limiting
Yeah, I don't quite get why they don't expose the CallbackContext inside the InputValue
you can't distinguish between started, canceled and performed
If it weren't for that, it'd be perfect
You can always put your PLayerInput in C# events mode and use the playerInput.onActionTriggered event
if you want to do it all in code
Yeah, but at that point you lose most of the benefits of using PlayerInput (aside from like, automatic gamepad/keyboard switching)
That's what I'm looking for. Going the C# route, for me, is so much cleaner. I want to make sure it doesn't cause hardship down the road.
Luckily though, so far SendMessage + callbacks has been good enough for me, whenever I need more granularity like started, performed, etc I can add a manual subscription via input.actions["Move"]
I recommend avoiding PlayerInput entirely unless you're doing local multiplayer tbh
that's what it's made for
Ok.
PlayerInput itself is useful because it handles switching automatically
PlayerInputManager though yeah, that one you don't need unless you're doing MP
What kind of switching are we talking about
It recognizes when you press something on a gamepad and switches the control scheme
Ok so like gamepad / kb + mouse switching
Yeah
Switching between gamepad and kb/m based on your inputs
You can of course implement it yourself, but why bother when PlayerInput has a working implementation
It also exposes events for when the switch happens so you can update your UI and stuff accordingly
From the docs:
If control schemes are present in actions, then if a device is used (not merely plugged in but rather receives input on a non-noisy, non-synthetic control) which is compatible with a control scheme other than the currently used one, PlayerInput will attempt to switch to that control scheme. Success depends on whether all device requirements for that scheme are met from the set of available devices. If a control scheme happens, InputUser signals ControlSchemeChanged on onChange.
Control schemes are still an area of the new input system that I don't fully understand
What is best way to save rebinded inputs?
There are so many ways to do it that I don't think there's really a "best" way, but one option is to have an array of input binding overrides that you serialize to json or something
You'd basically iterate over all of your actions, collect the binding overrides active on them, and save them out
Thanks!
@untold gulch How are you delineating between phases when using InputValue?
You unfortunately cannot because they don't expose the callback context for some reason
Ok. That's what I read and wondered if I'm missing something.
There's a hack you can do to get the value but ideally Unity would just expose it properly
using System.Runtime.InteropServices;
using UnityEngine.InputSystem;
public static class InputValueExtensions
{
public static ref InputAction.CallbackContext GetContext(this InputValue value)
{
return ref new InputValueUnion { InputValue = value }.RawInputValue.Context;
}
[StructLayout(LayoutKind.Explicit)]
struct InputValueUnion
{
[FieldOffset(0)]
public InputValue InputValue;
[FieldOffset(0)]
public RawInputValue RawInputValue;
}
class RawInputValue
{
public InputAction.CallbackContext Context;
}
}
Haha damn this really is a hack

@austere grotto Are you willing to share how you use the InputActionReference?
[SerializeField]
InputActionReference jumpRef;
void OnEnable() {
jumpRef.action.performed += Jump;
}
void OnDisable() {
jumpRef.action.performed -= Jump;
}
void Jump(InputAction.CallbackContext ctx) {
// whatever
}```
Got that part. The part I'm missing is what you put in the serialized field.
Or:
[SerializeField]
InputActionReference moveRef;
void Update() {
transform.Translate(moveRef.action.ReadValue<Vector2>() * Time.deltaTime);
}```
Whichever action you want from your asset
you can usually just press the circle thing on the right and choose from all of them
Hmmm....pulled one in and it successfully "set" it. Didn't work, though.
I'm usually not dragging/dropping, just selecting from the circle menu
they usually all show up there for me
Yea, they are there and can be selected. Checking other stuff.
What's not working exactly?
YOu may have to enable your asset from somewhere
The InputActionAsset, correct?
So your creating an instance of it somewhere in your code?
no
just referencing the real one
I generally have a single script that manages enabling/disabling action maps
Probably I enable the asset from there
Don't remember off the top of my head
Disregard. It works. Unity was not detecting mouse clicks. Moving it to the keyboard worked. Have to solve the mouse issue now.
@austere grotto I think you are tired of talking about it, but I have one other question. Using the generated C# wrapper class for the InputActionAsset is strongly typed, provides a convenient interface to implement and eliminates the need for serialized fields. Are there any pros/cons to doing it your way vs the C# wrapper? Simply personal preference?
I like my way because I don't have to manage my own instance of the actions asset. Also last time I checked the generated code didn't contain quite the entire interface of InputActionMap and such, but that might have changed since last I used it. I also like the directness of being able to reference the input action in the inspector like any other ScriptableObject or what have you. I can reassign it without changing the code. It feels very "Unity" to me.
It is of course my preference
Ok. Cool.
Hey guys, does anybody know how to get middle mouse button hold state and at the same time mouse position? Trying to make camera rotation script when middle button is pressed
can i identify a device with any data from PlayerInput.devices[]? I need to pass the player devices to another scene but the deviceID returns another device with InputSystem.devices[deviceID] . I can use a foreach loop to check which devices match but if there is a better way i would be happy to know
NVM found how
I have set up several input devices (PS4, XBox, etc.) and a general gamepad profile, but when I connect the PS4 gamepad, etc. it uses the general gamepad profile rather than the PS4 one. Is that a Unity bug or intended behaviour?
I think there are major issues with Unity's new input system right now regarding gamepad controllers.
I'm having issues where my controllers are just randomly disconnecting, when I can play games fine while Unity thinks they are disconnected.
Someone else is having this issue too https://forum.unity.com/threads/xbox-controller-stopped-working-in-unity-but-still-work-outside.1246507/ and i've submitted a bug report.
But I would like to know if anyone else is experiencing this too?
hello, i'm trying to get ahold of the new input system, and i'm having this issue where despite (to the best of my knowledge) i set up the input as a 1axis float, it isn't read as a float. how can i convert from teh input value read to a float?
Never experienced that myself to be honest. Might sound stupid but have you checked your cables / gamepads?
You use the ReadValue method
yes. also happening on multiple PCs
it doesn't seem to like this response
some of those old comments are just old code i'm keeping around for reference, so don't worry too much about those
you're not calling the method
Method invocation requires () in C#
okay, but if i try that, then enter float, it returns as invalid
same with input, axis, int, bool, vector2, and vector3, under this context;
nor does it work if i do something akin to;
throttleAmnt = ReadValue(verious destinations)
i converted teh control type to a double, and tried to search for a double instead of a float, or other variables, and it's still unhappy
given the documentation, it implys i should use one of the two i've already used, but this doesn't seem to work basically at all
ReadValue<float>()
it's just a simple C# syntax issue on your side
Hi. I'm working on learning the input system to move/rotate a box using either WASD and arrows or an XBox 360 controller. I set the sticks to 2D Vector and analogue, yet the thumbsticks act like 8-way switches. In other words, it's like I'm stuck with the digital-normalized mode, when I want the analogue mode. All three options 2D composite modes seem to behave the same. Any idea where to start?
Should just be Value/Vector2
Just tried it for the 12th time, and it works. I could've sworn I tried those settings before. Thank you!
The only change I can think of was rebooting the project.
after a lot of digging, i got it ty
anyone have any idea why this script to rotate my empty wont work? debug.log reads an input, but when i try to turn it it jsut sorta freaks out in place like it wants to turn but cant
(turn force is set to 100f just to try see any result)
🌈 .rotation is a Quaternion
yes, i'm aware, but i need to use quaternion.eular(variable) to convert the roll, yaw, and pitch into a quaternion
if i remove it, it errors out
specifically with this
because when i try to create a quaternion, i cannot seem to specify a w, so i need to use a vector, then convert that vector to said quaternion
so as much as i appreciate a meme, i do feel like your comment fails to understand what i'm getting at, and i'm sorry if i didn't explain it well enough.
Your problem is not the Quaternion.Euler call it's where you got the x y z from in the first place. Go look
i have, and i've erased basically every reference
What may help is to understand that you can compose Quaternions by multiplying them together. I.e. transform.rotation * Quaternion.Euler(0,1,0) will give you a new rotation that is the object's current rotation rotated by 1 degree in the y axis
Maybe you can extrapolate from that
You haven't fixed what I described above
for aditional context, this the entirety of where the variable is being called except for where it's established
You're still trying to read x y and z from a quaternion
and i will try that in a second, i'm simply just trying to show why my confusion might be so
Your confusion is that you think x y and z in the quaternion represent rotations around the x y and z axis but they do not
x is roll, y is yaw, z is pitch
to be blunt, i've done game development in unreal engine before, i understand the fundimentals.
i understand rotating is like if you stuck a rod into it, and rotated it around that
Nope. Not in a quaternion
They are not angles. Not around anything.
What you're describing are Euler angles
Trying to stick quaternion components into Euler angles is like sticking a round peg into a square hole. It doesn't fit
Try printing out transform.rotation. See what it prints
okay, well, then i guess that is my issue, and the tutorial i found is nulll
and okay
by the way, in unity: x is pitch, y is yaw, z is roll.
(but that's not your issue)
yes, my bad, and after teh debug, the x, y, z, and w
after using transform.rotation, i have the issue where unity is asking for the w input
so unless i need to do like in unreal, and plug 3 vectors and a float into this, i don't understand the issue
Don't use or set individual values of a quaternion
.eulerAngles/.localEulerAngles are the Vector3 euler angle values
also that's not how you create a vector
The problem I was initially talking about was this
not how you used Quaternion.Euler, which was fine
then what is the issue with it? i see no reason this might be wrong
you are creating a Vector3 out of values from a quaternion
it makes no sense
Quaternions are 4 dimensional normalised values. They are not degrees like euler angles
i'm literallty just trying to rotate an empty
.eulerAngles/.localEulerAngles are the Vector3 euler angle values
seeing as you have a rigidbody, you can get the euler angle rotations from the quaternion using rotation.eulerAngles
An easier way to do it might look like rb.rotation = Quaternion.AxisAngle(Vector3.up, 5) * rb.rotation;
i appreciate the attempt at helping, but i tfeels like the time is being wasted, i awknowlege i was using quaternions wrong, and i'm understand that adn will do my best not to do it again, however, the issue is, i feel liek i've been told a whole lot of what not to do, but not how to do it.
i'm sorry, but simply saying i should use x without context of where is very confusing, and i'm having to google practically everythign you're saying after to try understand where to properly impliment it
trying to follow what you've been saying has led me here
I gave you a suggestion above
You ignored it
Again, how you used Quaternion.Euler was fine. You can use that original code you had. The problem was with #🖱️┃input-system message
if you mean this, it's not that i ignored it, i tried to impliment it, but i have 0 idea where you mean to impliment it
do you mean i use that to get the vector "newRot"
do you mean i use that to adjust the output
yes, i understand that
but my point still stands
transform.rotation can be assigned to a quaternion
okay, again, where
where in my code
there is 3 things happening at once, and just telling me to do so, is not helping as i am both a novis and inexperianced with c#, coming from unreal with c++
okay, will try
I don't want to completely spoon feed you here, I want you to understand a bit.
Just try this for a second:
transform.rotation = transform.rotation * Quaternion.Euler(0, 1, 0);```
see what this does
I recommend not trying to understand what the x, y, z, w are. Don't even think about them. Just think of the rotation as a whole.
what you fail to understand, is if i'm clearly not understanding this, having the expectation of me just getting it is not helping.
i'm fine with you wanting me to try something, however i think it would save us both time and energy if you did just treat me like an idiot lol
and okay, i can do that
and it appear to be doing nothing after replacing the last line of my code
this line of code replaces all of the code inside your if statement
yep
doing this does perceivably nothing
is your joystick deadzone over the threshold?
i'm not saying it is, i just cannot see anything at a glance that is different
Or wait - did you run it?
i pulled a 404, i forgot i actually needed to press the joystick lol
yes, it is spinning in a cw fashion
Is it spinning the way you want? (don't worry about the speed for the moment)
but the nature of the rotation
i need it to spin both ways.
turnAmnt is my left joystick y, so to explain my thought process, i'm imagining i need to multiply that 1 by my turnAmnt variable
Seems reasonable to me
you should be able to replace that 1 with whatever you want now
Don't forget your turningForce and deltaTime as well
very true
I'm also not sure as to the context of the code but you may want to Mathf.Abs the turningAmt in your if statement if you expect it to be negative, that way negative values pass that check
To try to explain what actually is happening here:
Unity represents rotations with Quaternions. A quaternion represents some rotation away from the "default" rotation. You can "compose" quaternions using the * operator. So all we're doing here is taking your object's existing rotation (transform.rotation) and composing a new rotation of some degrees around the y axis with it, and then setting that composed result back to the object.
hopefully that makes sense 🤔
And what was wrong before was that you were composing a euler angle rotation using values you got from a quaternion
this is no longer working
uh check where your brackets are
brackets are still wrong
the braces are not wrapping around the content of the if statement
if statements without braces only affect one statement (the log)
although if tbh it should still be rotating just fine anyhow, just not respecting the deadzone
lol, i was looking at a different bracket
regardless, you probably just need to scale your turningAmt by a larger value now it's being tempered by deltaTime
i think you call them parenthesis or something
() are parentheses
{} are brackets or curly braces
the finale working statement
key word working
and ty for the help
and for a dash of context, i'm in SW canada, and i've basically only ever heard of () as brackets
not saying you're wrong, just a mental roadblock lol
grey vs gray as far as i'm concerned
sorry about the confusion, yeah maybe parentheses is an American term? idk
for context, i learned pedmas as bedmas lol
and it's fine, just felt like with this i should be as clear as possible, not trying to come across as rude, and i really appreciate the help
but if something wasn't working, i feel like i should call it out
and yeh, at the end it felt like ti was working much better so woop
Hey, If im pressing or releasing 2 buttons at the same time, unity doesn't register one of them, any work around to that issue?
Are you sure it's Unity and not your code?
Im pretty sure yeah, i found this issue: https://forum.unity.com/threads/bug-with-two-keyboard-keys-pressed-or-released-simultaneously.706955/
which talks about it
I'm having an issue with the Input System that I hope someone could help me out with. I am trying to implement basic left/right movement in a 2D game, and it works great for KBM. But I'd like to also have gamepad support, so I added another 1D axis binding under my movement action and assigned the positive/negative bindings to the appropriate direction on the gamepad. However, when I plug in my controller to test it, while the player character is moving, it is doing so at a much slower rate. I wrote a quick Debug.Log() line and discovered that while the keyboard is giving out perfect readings of either 1, -1, or 0, the controller is reading very inconsistently between about .5 and .8 (or the inverse if holding the other direction). This is happening even when I push the stick as far as it goes. How can I make the inputs consistently read max value when held fully in one direction?
Just tried with the controller's dpad and that works as it should (reading 1, -1, or 0)
Hello! How can i save specific button from up/down/left/right composite after rebinding?
I can't just action.ApplyBindingOverride(path); it does nothing
how do you disable a action map during runtime?
ive tried doing ```csharp
private PlayerInput InputSystem;
InputSystem.actions.FindActionMap("Player").Disable();
InputSystem.actions.FindActionMap("Menu").Enable();
and ive also tried like 3 other ways with no success
so whats the proper way to disable and enable action maps, or am I doing something in the setup wrong thats not allowing this stuff to work
hi all, i have a little problem with buttons in gameover screen.. on click they dont do anything.. any ideas please ?
Still need help
So... I made a small app for android (its only a cube object and touching the screen, moves the cube to that area... but I'm noticing a input lag when I do that (about half a second)...
also, when I update the engine with the new input system (1.3.0), my phone no longer recognise any input
Is your input module set up appropriately?
okay... found a tutorial that explained how to use the new input system
can anyone help me with the swipe inputs. Left and right swipe works fine but up and down swipe works only 6 or 7 out of 10 times.
what do you mean ?
Your input module. Is it set up properly or not? It's necessary for UI interactions to work.
Just asking this here as it's an input question. I'm getting the mouse position in the manner below...
public Vector2 MousePosition => controls.BipedMovement.MousePosition.ReadValue<Vector2>();
I'm using this to rotate a rigidbody on the Y axis based on the movement of the mouse on its X axis. The problem is that the speed of rotation is affected by the overall size of the screen or viewport - and given I'm hoping to put this program onto browsers and a variety of platforms, I'd like to find a way to make my code screensize agnostic. Any clues? =)
yRotDesired = (iC.TurnInputRaw.normalized.x + iC.MouseDelta.normalized.x) * (speedTurn * speedCur) * Time.fixedDeltaTime;
moveRotDesired = rbBody.rotation * Quaternion.Euler(0.0f, yRotDesired, 0.0f);
- You shouldn't multiply by fixeddeltatime for mouse input
- It will not only be affected by screen resolution but also by the user's mouse DPI and OS settings. It's impossible to account for all this and the best practice is find some reasonable default and allow the user the option to configure the mouse sensitivity.
Mouse Delta is in absolute terms
It's the number of pixels the mouse moved since the last reading
By definition this is already framerate adjusted
Right.
Also, I'm an idiot for not even posting the relevant input code for the mouse. Thanks @austere grotto , you're bang on the money.
Although if this is FixedUpdate, you may have an issue of double reading or missing mouse input unless you set the input cadence to be FixedUpdate in the input system
The input is captured outside FixedUpdate, then applied within FixedUpdate.
That's a little dangerous. FixedUpdate may run 0 times in a frame or multiple times in a frame. If you do that you need to consume the input in FixedUpdate
So it won't be read twice
And accumulate it in the other place
Hmm. Okay, this is sorta new to me.
By 'dangerous', are we talking about 'potential harm to hardware/os' or 'harm to the running of the Unity program' or 'may cause the player behavior to be wonky'?
I've been basically using this methodology for years on multiple projects and haven't encountered a problem, so I'm very interested to hear details, if you can spare the time (or point me in the right direction). Always looking for better practices.
All good, appreciate it.
I'm currently storing, for example, rotation data in the class variable moveRotDesired.
If you haven't noticed any issues I guess don't worry about it
It's possible I don't fully understand your setup
Honestly, I'm interested in learning about 'consuming'. Are we basically talking about calling a function from fixed update with the data fed to parameters?
I'm guessing 'no'. =)
Don't want to waste your time, though.
sorry i am beginner in unity, you mean this ?
Disregard that, I'm an idiot, apologies, carry on.
Btw, @austere grotto , now I have the scalar in for the Mouse Delta, I'm definitely seeing the wonky behavior you described.
God, apologies in advance if I'm being dense. Let me just get the current relevant code...
public Vector2 MouseDelta => controls.BipedMovement.MouseDelta.ReadValue<Vector2>();
This ^ is from my inputController script, talking to the new InputSystem.
yRotDesired = iC.TurnInputRaw.normalized.x + (iC.MouseDelta.normalized.x * iC.MouseSensitivity) * (speedTurn * speedCur) * Time.deltaTime;
moveRotDesired = rbBody.rotation * Quaternion.Euler(0.0f, yRotDesired, 0.0f);
This ^ is from my PlayerTraversal script, called from Update().
private void FixedUpdate()
{
if(sendToRigidbody)
{
// moveDirDesired.y = 0.0f;
Vector3 position = rb.position + moveDirDesired * Time.deltaTime * speedCur;
rb.MovePosition(position);
rbBody.MovePosition(position);
rbBody.MoveRotation(moveRotDesired);
}
}
That ^ is my FixedUpdate() event.
So, to fix this, I'd be... List<quaternion> ListOfMoveRotations.add the desired rotations as they're processed in the Update() event. This would accumulate the input every frame.
Then, in FixedUpdate, I'm basically doing,
rbBody.MoveRotation(ListOfMoveRotations.pop);
After the .pop operation, I'd basically do,
ListOfMoveRotations = new List<quaternion>;
...making it ready to be filled by the code in Update.
Does this make sense? Apologies @austere grotto , the whole consume thing is sorta new to me.
bump
Using the new input system, I created an action that takes mouse delta
How can i apply this vector 2 to my camera?
I don't know how to get the vector2 value in code
do you know how to access the action in code?
Hi! There is any way to have multiple ways of calling a button? For example, in a inventory, equip with the north button/shift click, throw with the east/supr etc
You can use bindings with modifiers, but there is no way currently to make modifiers disable other actions that are a subset of the binding. You have to do it manually
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.3/manual/KnownLimitations.html the limitation is the first one listed
Yeah but I dont want to prevent another action. I want to call a ui button with another input button
are you asking about secondary keys do the same thing ?
like multiple keys can trigger same action ?
I don't get what you're asking. You can do what you want with the action, you can have multiple action maps if you want to switch between UI and another state that has different usages of the same controls
I have an inventory which is a grid of buttons. Now, I want to do two things with that buttons. If I press key1 when I have the button selected I want to do thing1, if I press key2 with the button selected, I want to do thing2
So do different things in those callbacks, you can check which button you've selected and do whatever you want
Yeah, probably Im overcomplicating this
does anyone know how I can do this?
hover mouse over it and show your error
I cant compare inputaction classes to strings
Input System doesn't work in Console Build?
Hey, when i try to make a new axis with ctrl and shift it deletes my words for some reason. any clue? cheers
You'd have to have a reference to the action you want to compare it with of course
How can i access the values of this action?
I have this code, but the Log outputs 0.0, 0.0
public void Move()
{
Vector2 input = new Vector2(0, 0);
input = actions.aMove.ReadValue<Vector2>();
Debug.Log(input);
}
Did you enable actions?
Yes
Show the code
private PlayerActions playerActions;
private PlayerActions.DefaultActions actions;
#region Defaults
private void Awake()
{
// Initialize input components.
playerActions = new PlayerActions();
actions = playerActions.Default;
}
private void OnEnable()
{
actions.Enable();
}
I got the other action to work
aLook
I was following a tutorial but the guy had an option that i didnt
Which one are you talking abvout?
Oh found it
Up down left right composite
Yeah
THank you
See if that helps
Still need help
are there pre-existing input system actions configured for mobile gestures?
for example pinch to zoom with touch -> a float / delta y value?
Not that I’m aware of, last time I checked I had to do my own one.
Maybe there’s some templates hiding somewhere
it just seems so... obvious
it must be somewhere
Yeah ik… it’s not too hard to do but it’s a pain to manage concurrency between zoom,pan,rotate,finger release double click :p
Hello, what I am trying to do should be very simple but I cannot understand the documentation so I need help. I am trying to get my horizontal_movement action to invoke a move function. However, I have 2 issues, first issue is that the function does not show up as selectable, and 2nd issue is that I do not know what parameters are being passed when it invokes the function. Any advice is welcomed.
It sends a CallbackContext
Do you know why it gives me this error?
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.3/manual/QuickStartGuide.html
Look at the code example at the bottom of the page
Nothing happens when I press A or D, not even a debug log, any ideas why?
Show how you configured the Horizontal_Movement action (your current screenshot only shows the binding)
(Also your binding is a 1D float and your code is asking for a Vector2)
is it not?
it should be
Action Type: Value
Control Type: Vector2
And then you can do a 2D vector composite or 4 button composite (up left down right) or whatever it's called with WASD as the binding
I'm just trying to do horizontal movement with this action, I'm leaving up and down separate
Then it should be
Action Type: Value
Control Type: Axis
And your code should be doing ReadValue<float>() not Vector2
It still isn't showing the debug log when I press the buttons even after changing the types to what you said
It isn't invoking the events at all for some reason
How did you set up your control scheme>?
Looks like you have a control scheme named "Keyboard"?
(i recommend not messing with control schemes until you have the basic stuff working btw)
yep, that was it...
this list was empty
thank you for the help I would've never remembered to check that
Hello! I get this error when trying to rebind button. I dispose it on complete, but still error appear
Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions)
UnityEngine.InputSystem.Utilities.ArrayHelpers:GrowBy(NativeArray`1&, Int32, Allocator) (at Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Utilities\ArrayHelpers.cs:433)
UnityEngine.InputSystem.Utilities.ArrayHelpers:AppendWithCapacity(NativeArray`1&, Int32&, UInt64, Int32, Allocator) (at Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Utilities\ArrayHelpers.cs:360)
UnityEngine.InputSystem.InputControlList`1:Add(InputControl) (at Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Controls\InputControlList.cs:216)
UnityEngine.InputSystem.RebindingOperation:OnEvent(InputEventPtr, InputDevice) (at Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputActionRebindingExtensions.cs:2401)
UnityEngine.InputSystem.Utilities.DelegateHelpers:InvokeCallbacksSafe(CallbackArray`1&, InputEventPtr, InputDevice, String, Object) (at Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Utilities\DelegateHelpers.cs:71)
UnityEngine.InputSystem.InputManager:OnUpdate(InputUpdateType, InputEventBuffer&) (at Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\InputManager.cs:3244)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*) (at Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\NativeInputRuntime.cs:65)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
why is Right Stick [Gamepad] and Delta [Mouse] greyed out for me in my bindings? I can't select it
what's the nature of the input action you're trying to bind it to?
Does it have Control Type: Vector2?
I have a reference to an InputDevice from an event, and I want to know whether it is a Gamepad, Keyboard, or Mouse and I'm not sure if there's an easier way than doing something like Gamepad.all.Contains or something along those lines
I think the best way might be:
if (theDevice is Keyboard k)
else if (theDevice is Gamepad g)
``` etc
Oh, it's that easy. the Input system chooses the weirdest stuff to make simple or complex
for my 3D game, using built in engine, I am using the "Player Input" script for my game and inside, I have a custom "Actions" (Input Action Asset). UI Input Module (None). etc... This controls my player and its working fine currently. I then have a 2D Canvas for the UI and inside that I have "Input System UI Module" which has Default - for the Input Action Asset (the stock one unity creates).
I try to use my custom input action asset from the player, and it just doesn't work with the mouse or click or anything, but using the built in stock one it works great.
Can I 'mix and match' 2 different input schemes? 1 on PlayerInput.cs and 1 on InputSystemUIInputModule.cs ? Its working right now with the 2 different input action assets but didn't know if I should be using 1 and if i am... why using 1 (the first one thats custom) doesn't work but the default does, i've even opened the default and copied the UI over 1:1 so still not sure on that.
I leave the InputSystemUIInputModule alone since I think it just interfaces with the EventSystem
Then for like button UI input I just use the built in Button class and either drag in a script for the onclick event or subscribe one in script
I use a single input action with touch and mouse click location setup
this works well since they're both a Vector2
is there a way to disable the editor default input devices in play mode
or is there a way to get the editor devices to be assigned to a user right away?
Can anyone help with making a composite binding? I'm trying to make a single InputAction where the player can press one key from a row to return an int. E.g. for a FPS selector where you press keys 0-9 to select one of 10 weapons from an array, or a MOBA style selector with Q, W, E and R. But I've been fiddling around trying to make my own composite binding and it's not getting anywhere
Hi. I'm looking at the new input system, and I decided I need a custom composite for my logic (switching gears). The idea is to have space enable the clutch, and shift-ctrl change the gears up and down respectively. The problem is that my composite is stateful, as in it will have to depend on its previous state. Is it stored somewhere, you do I have to just store it in a private field? Also, is InputBindingComposite.ReadValue going to be called every time the input is provided, or every time the input is queried, or just a single time when it's queried and then cached?
Here's a sketch to give you a bit more context
public class GearComposite : InputBindingComposite<GearInteractionType>
{
[InputControl(layout = "Button")]
public int clutchPart;
[InputControl(layout = "Button")]
public int gearUpPart;
[InputControl(layout = "Button")]
public int gearDownPart;
public float timeBeforeCanChangeGearsAfterClutchGetsEnabled;
private GearInteractionType _previousEvaluatedType;
public override GearInteractionType ReadValue(ref InputBindingCompositeContext context)
{
// TODO: take into account the parameter.
bool clutch = context.ReadValueAsButton(clutchPart);
if (!clutch)
{
_previousEvaluatedType = GearInteractionType.None;
return GearInteractionType.None;
}
float up = context.ReadValue<float>(gearUpPart);
float down = context.ReadValue<float>(gearDownPart);
float sum = up - down;
if (Mathf.Approximately(sum, 0))
{
_previousEvaluatedType = GearInteractionType.Clutch;
return GearInteractionType.Clutch;
}
if (_previousEvaluatedType != GearInteractionType.Clutch)
return GearInteractionType.Clutch;
if (sum > 0)
{
_previousEvaluatedType = GearInteractionType.Up;
return GearInteractionType.Up;
}
_previousEvaluatedType = GearInteractionType.Down;
return GearInteractionType.Down;
}
}
I realize that this is trash, because if I have multiple such bindings, they will all refer to separate states of the previous input
If I am using Unity's old input system, how would I go about fully disabling any input from the mouse? I am trying to make the game only have keyboard inputs but if the mouse is clicked on screen, all of my buttons deselect
Project Settings -> Input Manager -> Submit axis -> remove all the mouse stuff from here
er wait not submit
🤔
Unfortunately I think you might have to do this http://answers.unity.com/answers/1247828/view.html
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
replace your standalone input module with a custom one
it's a lot easier in the new input system as there's a simple checkbox to disable deselect on click
I am half wondering if it just makes more sense to just upgrade but I also have no idea how much I need to rebuild to implement that
oh you could also probably just remove your GraphicRaycaster from your Canvas
that'd probably do it 🤔 maybe
er wait maybe not
because it's a deselect
idk
I tried that and it still has the issue
The thing that annoys me is I know I found a fix for another project but cannot remember what it is at all
brand new to new input system can someone help me out? I want to control in code which controller scheme is in use but dont know how. The goal is to switch between gamepad and keyboard, disabling the one not in use based on a setting in the game
thx
Hey guys, was wondering if i could get some help with my implementation of the input system for a touch mobile device. I have a couple problems with my current implementation.
What i wish to achieve: Have 2 joysticks in left and right bottom half of screen that are floating and can create a new anchor point wherever the player taps. And to have the top half of the screen be a "swipe region" that can detect swipes.
Current problems: 1. The joysticks aren't floating. They're fixed in place. Im using the input system On-screen stick component script, which is uneditable so im not sure how to go about it. I actually tried just importing the script from the floating joystick in that free asset on the asset store (called joystick pack), and its very promising but the handle jitters back to the center of the background every couple seconds. I think this is because the on-screen stick and floating joystick scripts are in conflict, but i would need the on-screen stick component still in order to read the input as movement.
- secondly, my swipe region works but not if im currently using the joysticks because im currently touching the screen so it just exits the script basically. Not sure how to fix this while staying in the input system, because id like for users to easily switch to a bluetooth controller if they want.
Thanks, sorry i know thats a mouthful. Just really stuck on this core issue of the game and its hard to test my builds until this is all working smoothly
hi i created a project using the fps core template, how do i go about adding more controls? I can add to the action map, but im not sure how to create them in the existing files for use in other scripts
what is the recommended way to use new input system
unity events or c# generated class?
i watched a tutorial that says use unity events but i dont want my methods to be public
it doesnt feel right to make them public
Depends, if you want to do it manually, you can do so
InputSystem.onEvent
.ForDevice<Keyboard>()
.Call(ctrl =>
{
foreach (var button in ctrl.GetAllButtonPresses())
Debug.Log($"{button} was pressed");
});
Judging by how you worded your question, I don't think you want this method. So yeah just stick with what Unity told you or most tutorials you can find out there
if you for some reason want to go with the snippet above, just make sure to dispose it (onscenechange/disable etc) with IDisposable
I'd say either is fine if you're starting out. Personally I prefer the generated class, but it can be annoying if you add & remove controls a lot.
The events is more of a designer way of assigning controls to things
the good thing with new inputSystem, if you chose to ditch out the generated class and prefer to handcraft it yourself, you can do so and make your own reusable template in form of c# classes, sorta like a compact library which you can use for other projects.
I personally don't like the generated-class thingy it's not that straight forward and too many steps just for an inputsystem
Hello there, newcome here, having a spot of trouble getting the settings working right.
I'm on the new InputSystem v1.3.0 - I'm getting the left stick (Gamepad) and Mouse delta to work fine for movement and camera change respectively, however for some reason the keyboard is not doing anything. A debug logger is showing that it's simply not activating the sendMessage OnMove() or OnLook() method through these systems.
Any ideas what I may have done wrong. I copied the composite vector layout of the InputSystem default structure but even the default fails to provide any inputs.
private void OnMove(InputValue movementValue) {
movementVector = movementValue.Get<Vector2>();
Debug.Log("Movement Vector: " + movementVector);
}
void Update()
{
...
// Surface Movement
Vector3 move = transform.right * movementVector.x + transform.forward * movementVector.y;
controller.Move(move * moveSpeed * Time.deltaTime);
...
}
So the above works with Gamepad left stick, but the keyboard is not recognized. Then the mouse works fine to look around, but the right stick does nothing!
I set the Input System component on both the Player and the Camera objects and I have mapped all the necessary controls using the same Actions (Move and Look) creating a Composite Vector2 for the keyboard.
edit: auto-switch is enabled for both player and cam, not that it matters given that the joystick has one stick working and the other not.
My working theories atm are that using the same Input System on two separate objects might be bad for whatever reason, or there's some quirk with the InputSystem that's escaping me.
Appreciate any help
And I setup the numpad on keyboard for view and both mouse delta and numpad gives me a valid vector2 to look around. Right stick still not doing anything tho. Left stick lets me move but neither WASD nor Arrow Keys do anything. The method is simply not triggering for them. I'm very confused.
Does anybody know how to extend the OnScreenStick component from the input system to make my joystick a floating joystick?
define "floating joystick"?
A floating joystick is where the center point spawns in where your finger touches and then locks in place until u lift up ur finger. Then it returns the transform back to starting vector
Should be fairly simple code but i don't know how to either edit the onscreenstick script, or make an extension of it in some way
Sorry just saw the message
Hey I'm a super noob so I was just wondering if there was a way for me to add both k&m and controller input to my game and if there is would someone be able to link me to a way to do that TYIA
Yes, you can create an input action asset with both m/k and controller inputs and handle them in the .performed events. Check out the samyam videos on youtube
How to use the new input system in Unity! I go over installing the package, the different ways to use the input system, and the recommended way!
📥 Get the Source Code 📥
https://www.patreon.com/posts/55295489
►🤝 Support Me 🤝
Patreon: https://www.patreon.com/samyg
Donate: https://ko-fi.com/samyam
🔗 Relevant Video Links 🔗
ᐅALL of my Input System...
does anyone know where is the 2D Composite Axis? Is it removed or my editor is bugged?
hi i created a project using the fps core template, how do i go about adding more controls? I can add to the action map, but im not sure how to create them in the existing files for use in other scripts
i've added the control in the templates action map but im struggling to see how on earth to use it in a script
I'm confused 2 here
Do u have an answer yet
All i know is, it was there till i updated to the lts for 2020 ik in the 2019 lts it is fine tho
From the above problem that I had, I ended up redoing everything step by step and successfully got both keyboard (WASD) and Mouse (Delta) as well as Joystick (LStick and RStick) to control movement and camera respectively. What I don't understand is why the moment that I introduce Control Schemes, everything goes wonky. Is there some known bugs related to Control Schemes? It's making little sense to me how half the controls stop working and then other things start working.
still not yet found anything about it, also asked on the forum. I ended up using the 1D axis.
Did you try setting the Action from button to Value?
oh? Sorry I am kinda following a yt tutorial so i don't really know much about it. I am still learning and yt seems to be the best way to go imo.
. this dude knows somethin xD
Action "Move" should be Value type, not Button
Not sure why they call it that, It seems to span a range of inputs.
so how do i make it a value type
Go on the action, up top above the binding
And change Type to Value
It will accept a 2D vector as is shown in that screenshot where I setup WASD to be mapped as a composite 2D Vector
Currently everything breaks for me when using Control Schemes, so maybe best avoid those too unless you know what you're doing. I'm not in that regards.
nvm
i'm just stupid there
Not sure how those are your options when it's set as Value, try the Save Asset option?
Action type needs to be Value
Control type needs to be Vector2
ah, so that's where it goes, and it's now named 'Up/Down/Left/Right/ Composite'
thx guys! 
clicking the button unity gives when you have old input system enabled with the input system package will not save the new changes if you didnt save?
Greetings,
I hope this is the correct channel, as it could fit in some others too.
We are currently developing a webgl racing game.
Currently we are having troubles with the mobile controlls (When you play the game in an mobile browser)
Problem is, that we have multiple buttons for the controlls (see image)
and each of those is using the Event Triggers PointerUp Down and Exit.
The called Method(s) just toggle different bools depending on which button is pressed.
public void OnPressGas() { Debug.Log("OnPressGas"); isGasBtnDown = true; }
While this works so far, there are issues with pressing and releasing multiple buttons in different orders.
For example if you press the "gas" button you drive forward. Now while stil pressing the gas button and then pressing the left button for example
the car drives forward and left. But now if you release the gas button while stil pressing on the left button, the car stil drives forward left.
I added some console logs and the PointerUp and PointerExit buttons only trigger for the last pressed button.
I hope I explained it right. I searched for a few days now how to fix this and couldn't find an working answer.
I tried removing not needed Raycasts from hud elements and also the solutions discussed in this forum topic: https://forum.unity.com/threads/onpointerup-occasionally-doesnt-fire.435230/
I hope someone here can help. Thanks in advance 🙂
also it says it will disable old input system and my game is using it so will it cause any errors when switching (the errors from the restarting unity says when you saved with errors in script i know the old input stuff wont work)
what button are you talking about
Just FYI:
https://docs.unity3d.com/Manual/webgl-browsercompatibility.html
Note that Unity WebGL content is not currently supported on mobile devices.
but it may still be an issue with your code too
nvm , it was about the popup when you download the input system package while having the old one on
So I'm trying to make your standard "right-stick-controls-camera" type thing, and with what I have; input just appears to not be working at all lol
this is what I have in my code:
actions.Gameplay.Camera.performed += ctx => targetOffset = ctx.ReadValue<Vector3>();
and TargetOffset doesn't change at all
Remove the Position[Mouse] binding
that's going to report the current mouse position constantly
and probably screw with the stick input
When you want to get to mouse input, mouse delta makes a lot more sense there than mouse position
oh gotcha
ok so I dropped the for now I'll work on the mouse later
however it still doesn't appear to work
lemme show my entire code
oh nevermind just realized I can't read Vector3 from the right stick
this would be helpful if you're interested in diagnosing this issue
nah I know what I need to do (just use Vector2 instead lol, I don't need the player to be incontrol of all 3 axises for the cam lol)
oh actually I was wrong lol
so the basics of this are working
however its very... drastic
I'll upload a gif in a sec but here's the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class CameraFollow : MonoBehaviour
{
public Transform Target;
public Vector3 targetOffset = new Vector3(0, 5, -10);
// Start is called before the first frame
//
public PlayerActions actions;
Vector2 inputOffset;
private void Awake()
{
actions = new PlayerActions();
actions.Gameplay.Camera.performed += ctx => inputOffset = ctx.ReadValue<Vector2>();
actions.Gameplay.Camera.canceled += ctx => inputOffset = new Vector2(0, 0);
}
// Update is called once per frame
void Update()
{
FollowTarget();
}
public void FollowTarget()
{
if(inputOffset.x != 0)
{
targetOffset.x = inputOffset.x * 20;
targetOffset.z = inputOffset.y * 20;
}
Vector3 targetPosition = Target.TransformPoint(targetOffset);
//targetPosition.y += 5;
//targetPosition.z -= 10;
//transform.position = targetPosition;
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime);
transform.LookAt(Target);
}
private void OnEnable()
{
actions.Gameplay.Enable();
}
private void OnDisable()
{
actions.Gameplay.Disable();
}
}
I'm also trying to impliment it so when I lay off the input it stops moving
doesn't really work
Still haven't found the answer: How do you read swipe detection with the new input system when you're already touching the screen? Users will be using a joystick with one hand and can use the other thumb to swipe. My implementation works right now but only if im not touching the joystick already because im only accepting swipes on the top half of the screen and accepting joystick movement on the bottom half. The swipe detection script returns because its reading my touch on the lower half already
Kinda depends on what you want the swipe to do, but typically first you'd differentiate a swipe from a touch by checking for a drastic change in position of the finger while held down. Then just keep track of the change in distance between the original touch position and the position when the finger is lifted
Well that is what im doing. My swipe detection works just like that
So once your touch[0] is using the joystick swipes dont work
so you could listen for swipes on other finger touches
not sure how to post code in here its getting auto deleted
just pastebin it
hi how can get input of keyboard while i am in editor mode
for what
are you just trying to make a hotkey to do something?
if (Input.GetKeyDown(KeyCode.W))
{
direction = Vector3.forward;
}
if (Input.GetKeyDown(KeyCode.S))
{
direction = -Vector3.forward;
}
if (Input.GetKeyDown(KeyCode.A))
{
direction = Vector3.left;
}
if (Input.GetKeyDown(KeyCode.d))
{
direction = Vector3.right;
}
``` i want to perform this in editor scripting
what are you doing with direction?
direction of movement
movement of what?
capsule
You know Update doesn't run in edit mode
onSceneGui
why are you trying to make gameplay work in edit mode 🤔
going to play mode for everystep is time consuming
If you want to read input in OnSceneGui you use this https://docs.unity3d.com/ScriptReference/Event-current.html
then you can check if it's a key event:
https://docs.unity3d.com/ScriptReference/Event-isKey.html
and check which key with:
https://docs.unity3d.com/ScriptReference/Event-keyCode.html
i don't see how this is generally useful though - it'd be completely different code than your actual gameplay movement code
i just trying to learn
As someone much more experienced in Unity - I think this is counterproductive. Stick to writing actual game code and entering play mode to test it
only write editor code if you're making tools for the editor
ok
thanks
how do i replace the old input node with the new input system one?
yea thats hwy i said i was stupid but ty ;D
how can i check number of input key is pressed , like i pressed W and D , then it should show 2 event
if I'm using sendmessages and I have a button event called PlatformJump I should just be able to have a function somewhere in my movement script called OnPlatformJump(InputAction.CallbackContext context) right?
because for whatever reason it's not outputting anything at all, and more confusingly it's logging errors that then aren't showing up in the console
I finally got debugging up and running on my android and its not even recognizing my swipe as an input if another finger is touching. Is it something to do with the setup of my actionmap?
how do i generate a c# class with the new input system i'm using lts for 2020
When a new player instance is created via the input system duplicating a prefab (in the case of local multiplayer) is there any way to fetch that new instance? I need to write data into it and I have no idea how to get it consistantly
Try setting the parameter as InputValue instead of CallbackContext instead. I'm not too clear myself on the SendMessages approach tbh, might be misadvising you just a fair warning
I'm planning to shift to the Unity Event
PlayerInputManager.JoinPlayer returns the spawned instance
Why does the player input component show up as an icon and how can I stop it from doing that?
it's a gizmo
disable it in the gizmos menu
thanks, that had been bugging me for a while
someone ping me ?
so it appears that the Input System has a bug with ButtonWithTwoModifiers, I'm getting this exact issue: https://forum.unity.com/threads/buttonwithtwomodifiers-cannot-find-public-field-modifier-1.1238371/
anyone encounter this and know of a workaround, or if it's fixed in later versions? I'm on 2020 lts
Can someone please help me understand how to read a swipe action on a touch screen with multiple fingers on the screen?
Does anyone know how to fix this problem I'm having at the moment
I'm trying to create input rebinding that works from a scriptable object everything seems to go good until i actually do the rebinding operation where I get this error:
InvalidOperationException: Cannot rebind action 'Gameplay/Jump[/Keyboard/c]' while it is enabled (There is more but it doesn't seem important to this issue)
so the problem I having is I want to be able to disable my current input map but I dont want to have a reference to PlayerInput as then it defeats the purpose of having this be a scriptable object
https://paste.ofcode.org/c5XXcWHWmpGZzXLDzK4sZ this is the code
PlayerInput is commented out as that is what im trying to remove but works with it their
I'm working with the generated c# class in unity 2021. you get there by clicking on your Input Actions asset, then, in the Inspector window, you should see the option to generate the c# class.
Is anyone working with their notification behavior to Invoke C# Events? I'm trying that approach and it interesting but i am unsure if i am going about it correctly. I am able to use the generated c# class from my Input Actions asset and just get rid of the PlayerInput Component. Then I just work with the Input events directly in code using the interface provided by the generated c# class. ill post an example
I don't seem to get it in my inspector menu well at least i didn't last night ill try today thank you ! 😄
hmmm weird. here is my InputActions asset when i open it and where it shows the option in my inspector if it helps
none of those pictures show you clicking on the asset
oh im dumb
sorry thanks for making me realise xD
I figured showing the asset open next to the inspector would be a more clear to show what I was talking about
At least someone got there question answered
I thought u had to click the action itself not the thing in the folder xD
the thing in the folder? wonder what that folder is called lol. Could it be... the 'assets' folder
I was meaning the PlayerInput.inputactions thing xD
sorry its a bit weird as i am still quite new but ah well xD
All good
Well technically it could be anywhere. It depends on where you created the input actions asset
How could it be anywhere other than assets folder or a sub of it
idk lol
either way im that good i fucked up following a tutorial xD
Idk it gives you the option to choose where it is created when you make a new input actions asset. I'm not an expert just trying to help
lol mind helpin me out figure out tf i did wrong to the point i can't move but it registers inputs?
https://pastebin.com/H16t8q7h - PlayerMotor script
https://pastebin.com/4z5E4m7x - InputManager script
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Just won't move not sure why
sorry if its a basic thing i've screwed up, i was following a tutorial idk tho
Sorry im having trouble doing something basic right now too with input system. spent like a week trying different things and asking on forums but always ignored
I feel it, I've been trying to figure out the best way to go about using this system for awhile and want to use the generated c # script and invoke c# events. It seems like most people just use invoke unity events though
I was able to accomplish using the generated script following a tutorial and everything worked right. Its actually frustrating how many ways there is to use the input system because then if i want a tutorial on something else to do with it, there's like 3 other ways they might show instead which isnt how im implementing it
Yeah the documentation from unity doesn't dive very deep on it either. Just curious but were you able to use the interface that the generated script makes? It's how unity recommends using it but I haven't found any tutorials that actually use it. But I was able to get it working and using the interface seems to make the rest a lot more simple (as in getting access to all the actions and their callbacks)
I didnt know there was an interface. Are you talking about the components?'
sounds about right lol
No, you can create a script that inherits from the generated c# script and gives you access to what's in the interface. It's really nice I think
If you open the generated c# script then go all the way towards the bottom you should see an interface for each action map
It simplifies setting up callbacks
But I haven't found any tutorial or anything that uses it. It's crazy
I'm so fed up with this i thought its such a simple problem but i cant find anything about it online. How to set up multiple touches so swiping can be detected on the second finger to touch the screen. Im about to give up
Hmm yeah I wish I could help you there
I just had an idea and its probably dumb and might not work but im gonna try this in a last ditch effort
What if instead of reading swiping, I make a 3rd joystick that has no image but takes up the whole part of the screen i want to detect swiping. This should work but im not sure if having a 3rd joystick is doable, at least for me to do lol
Ayyy if it works it works lol
Im not sure why it's not working. Maybe try caching the input before passing it in to the method in your input manager script?
huh?
nani?
My code brain is stupidly small xD
You have
motor.ProcessMove(onGround.Movement.ReadValue<Vector2>())
Maybe try
Vector 2 moveDirection = onGround.Movement.ReadValue<Vector2>();
motor.ProcessMove(moveDirection);
Something like that
Sometimes caching the value before using helps me
alrighty
Why did no one tell me
that you can use your right click as a second touch point. This makes testing so much easier
How would I code a 2d roll animation for a player?
I think you need to use the animator. I learned that from this part of a unity course: https://youtu.be/b8YUfee_pzc?list=FL4PXCnzqwGEscOwR6aE3Gbg&t=15212
This is a full release of an Top Down RPG course made in Unity 2017
0:00:00 - Intro
0:01:31 - Setting up
0:16:03 - Moving and Manual Collision Detection
1:03:06 - Tilemap and Designing Dungeon
1:40:31 - Interactive Objects and Inheritance
2:15:37 - Saving Game's State
2:41:31 - Floating Text System
3:11:11 - Top Down Combat System
4:13:32 - Ani...
Do you guys have an answer for my question? I've spent about 6 hours in the past 3 days and I can't figure it out.
I'm trying to stop the character (Polygon Collider 2D) from moving through a wall (Tilemap Collider 2D).
1 var hitResults = new RaycastHit2D[10];
2 var hitX = collider.Cast(new Vector2(desiredX, 0), bodyFilter, hitResults);
3 //var test = new Collider2D[10];
4 //hitX = collider.OverlapCollider(bodyFilter, test);
5 if (hitX == 0)
6 {
7 transform.Translate(desiredX, 0, 0);
8 }
Why does the character not stop moving horizontally when I run the code like this? I proved the character can collide with the wall because it does stop moving horizontally when I uncomment the two lines (3&4).
because you are using transform.Translate() which is ignoring physics
so... I have a tenny tiny problem...
in the player events, only the monoscript is showing up
nvm... I figured out
how do I fix this?
stop trying to read a Vector2 from the action
Hey there, I have a bit of a problem. For some reason Unity Input System doesn't detect me pressing any keys on my keyboard.
Any advice on this?
The new input system handle input actions differently (I'm still learning it, so I can't be of much help)
I'm making a game with a Health bar and a Stamina bar but when i want to assign the stamina bar to the playing it will only let me select the health bar, can anyone help me?
the second one needs to be stamina bar but when i put it there nothing happens
How do you use a gamepad to navigate to different elements in the UI? My controller can navigate to through the pause menu because i set up the resume button to be the starting button. But what if the pause menu is inactive and i want to navigate from a second panel?
Doesn't look input system related
Anyone familiar with working with the generated c# script in the new input system?
And using invoke c# events notification behavior
Invoke C# Events is for PlayerInput
Which would be a different approach from using the generated script
Oh hmmm I've been a bit confused with it. I actually was able to just get rid of the PlayerInput component and just write an input script that inherits from the generated c# script, so I have access to an interface that lets me easily access the callbacks for each of my actions. But I haven't found anything that goes about using it the way I have.
Anyone I've seen use the generated script manually registers the action maps and everything but not use the interface that it provides to do it.
I thought that using the generated script was considered invoking c# everts since it was all dealt with in code
You're confusing lots of different interrelated things
A little bit yeah, what I'm focused on is using the interface from the generated c# script. That's all I really want to get figured. How come nobody uses the interface?
Some people use it
You have to use the SetCallbacks(myListener) method on an instance of the generated class
Oh yeah I've got it working for the most part. I'm just unsure of how to properly work with the callbacks I guess. Here is a chunk of my code to show how I've got it set up.
The interface will force you to implement some functions
Those are the functions that will be called
Yes, the functions are all the actions that were created in the actions asset. Like, my "Player" action map has an action called "Move" so it has a corresponding "OnMove" function from the interface.
My confusion is how to properly write code inside the functions using the callbacks
Wdym? What's confusing you?
I've just been figuring it all out through trial and error. I can't find any documentation or tutorials on the way im doing things with the generated script. Weird stuff happens when I refactor like I move a lot slower for no reason. Also, figuring out how all the callbacks get called when you trigger a function and how to correctly work with them
It works the same way as the others
You get a call to your function when the actuation of the input changes
(it's also dependent on which interactions if any you've used on the action)
Ok I guess I'll go through how the other ways work and figure out the callbacks. Do you have any recommendations for a tutorial that demonstrates working with the callbacks and possibly linking the input to other scripts. (i.e. input script working with a weapon script or something? ) or maybe getting like a charge up action to work? (Like charging a gun to shoot a stronger bullet)
I bought some courses and books to try and learn this but they seem to like these old input system and use it instead but I'm determined to just use the new system
trying to revert to Old input system in my game, and it seems like Unity just "HATES" my xbox controller and has a hard time in windows / unity as making it the primary controller. is there a way to check or see on OLD?
like in windows i have 2 or 3 controllers showing becuse i have a keypad gamepad that it thinks is a joystick as well, so i remember back in the day when i started old input system was a PITA to get it to be primary
i dunno if i had to run sTEAM and make my xbox controller the stock or what i had to do, but its not fun. any thoughts?
i can't expect people playing my game to pull keypads and joysticks out and plug in wireless or a certain port
its showing up as "Xinput Gamepad 2"
Hello! has anyone used the input system for counting steps (pedometer) yet?
solved partially my issue by going into device manager, and removing all gamepads and drivers and rebooting, somehow i had a xbox 360 gamepad driver in there (from razer) which is even more odd, not sure if that was from razer or from xbox 360 years ago, etc. but now my gamepad is player 1 so were good for now
is it possible to get which key pressed from CallbackContext?
ex: ctx.aKey.WasPressed
How do i switch back to the old input system? I set the player setting to old, uninstalled the new, but when i try to do anything my Event SYstem is telling me that I am using the new input system and the old system is disabled
Hi, I've been having an input rebind problem for several hours now. Basically I want to be able to change the bind of the New Input System, so I use the scripts provided by Unity in their "Rebinding UI" sample but unfortunately when I press a key nothing changes, after investigation it seems to be the action.PerformInteractiveRebinding function that doesn't work properly. Has anyone encountered a similar problem?
project settings -> PLayer -> Active input handling
go make sure you've switched back to the Standalone Input Module as well on your Event System
i think it was because I had an addon that was using new input as a dependancy
so when i removed all the addons that need new, now it works, or at least the error is gone
thanks
Hey, quick question: is Input System 1.3 verified for Unity 2020.3? In the Documentation it says it is, but in the package manager the last verified version appears to be 1.0.2
Did you update your editor to the latest patch version?
Hum, not really. I'm on 2020.3.16, but when they said it's verified for 2020.3 I imagined it includes all versions of 2020.3
Like, do I NEED to update to the latest patch for it to be verified? Or is this just a aesthetic thing (the "verified" tag not showing up in the package manager)?
ok so im still having some issues with the fact that my kb and controllers are vector2 but my joystick is an axis (float). should i just add them together like
float inputval = controllerAction.ReadValue<Vector2>().y + joystickAction.ReadValue<float>();
or is there a fancier way in doing this?
because having overload functions look nasty
or should i go with overload functions either way? i cant decide
its not verified if the tag doesn't show up. You definitely should update to the latest patch if your project allows it. Its kinda the whole point of using an LTS version.
Is it only a single axis joystick? Why not make that a vector2 control too?
do you need to use the input system window or can you just do everything through c# alone?
nope still stumped. I personally don't want to use the input system and define all the buttons in the input manager, I'd instead like to use the raw code versions of the input code and just check those instead. however, I can't find a clear answer as to how you use the raw code versions of the inputs. is there any documentation on how to get the raw values?
Because then it wont show up for some reason
Idk my joystick is really weird since i’m using a specific variant which most of the times doesn’t even show up on the list
And according to the input debugger, it spits out a float value and not a vector2 value afaik
I'm using the old InputSystem and Unity 2019.4 . Currently trying to get multi-display input working. From what I have heard and read, the second display is expected to be in fullscreen all the time. I have hacked my way out of this using windows specific commands (user32 stuff). The problem is, this completely messes up the mouse coordinates (I seem to get them relative to the main display). I think I could fix this, but I would have to be able to manipulate the mouse coordinates before they are sent to the UI/Canvas. Or send my own mouse-events. Is there any way to achieve this?
simple question: is there a tutorial on how the controller axis are managed? i don't know how to access the right joystick.
Not trying to be impolite, but googling this will be much faster to find your answer
none of the tutorials found helped, all were off, so i stumbled into a solution.
guessing blindly how stuff works is faster than good tutorials.
First documentation, then tutorials
@austere grotto this is what is displayed when value is set to vector2 (first image with only 2 options) vs then value is set to axis (second image with a whole lotta more options) slider is the one i need (third image with it highlighted)
I see you can run new and old input modules at the same time. Would a valid use case for this to be running a character controller in the old input (like rewired or built in) and then running the UI in the new input system?
I think the only really valid case for running old and new at the same time is to do so during a short term transitionary period as you migrate from old to new in an existing project.
Or when you have a third party asset/plugin that uses the old system that you cannot modify
that said you can do whatever you want
I was using 100% new, but i was having some issues with the xbox triggers as buttons and etc etc, so as a temporary fix the old input works on it no problems, so i switched to that, but my UI uses a 3rd party library that only runs on new, so i needed both.. took a bit of fiddling to get them to work but they do now after a bit of trial and error. I can check back on the new input in the future when i have some time to get a workaround etc
one quick question, is there a github or a bug tracker / changelog / etc for new input that i can go see outstanding issues and things planned ?
how do i replace the old input node with the new input system one? there's no in-flow on the new node
Hey I am having an issue that Im not quite sure even how to debug....
When I restart my game, in game via script by loading a temporary scene, then unloading all scenes, then loading into my title screen.... my PlayerInput module, which is supposed to be sending out C# events, no longer does so. its functioning fine otherwise, nothing looks wrong in the Input Debug window... but scripts that have subscribed to the events its supposed to send out just aren't doing anything... I'm not sure if the PlayerInput component has stopped sending out the events, or if the problem is on the subscribers end... I've been trying solutions to this for hours and I'm stumped
I made a test that that just subscribes and debug logs, on the same GameObject as the PlayerInput component, and even that stops working after the reset
public class PlayerInputEventTest : MonoBehaviour
{
[SerializeField] PlayerInput testInput;
private void Awake()
{
testInput.onControlsChanged += TestInput_onControlsChanged;
}
private void TestInput_onControlsChanged(PlayerInput obj)
{
Debug.Log("Test Input event log");
}
private void OnDisable()
{
Debug.Log("test input Obj disabled");
testInput.onControlsChanged -= TestInput_onControlsChanged;
}
}```
the new input system uses events, they are not directly integrated in the control flow. no idea about visual scripting, but try just hooking the output up to your input logic
Gotcha thanks
Any idea how I’d use the event flow to control a bool for an if switch?
Like “if pressed/active” then do thing
should literally be just like that. if input then do..... you just don't need the if anymore
Actually let me try using the button node instead, I assumed they were for button events only
Oh true
what would be the code way to handle inputs? no input manager, just using UnityEngine.InputSystem & the classes inside of it.
ik there'd be a bit of set up involved but I'm personally trying to use just code for now since that's the environment I'm most comfortable in
question what is
ArgumentOutOfRangeException during event processing of Dynamic update; resetting event buffer
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
what does it mean
seems like an internal error
create the asset, generate the c# class, get an instance and subscribe to the events
yes I am getting it when using a button on the game pad... when i use the button of the same control binding of the keyboard it works...
i think I explained poorly. I want to not create the Input asset and instead just call the booleans & values and assign them to variables. I know you can call the code, i just don't know how to call it.
you always need an input action. either that being an asset or a self constructed one from json
There's no code in Unity's InputSystem namespace that I can use to directly refer to a keyboard key?
no. that's exactly the point of the new system
also that would be the worst thing to use the new input system for. if you want that behaviour, use the legacy input manager
got it, will they eventually phase out the old one entirely or will you always have direct access to the devices?
can anyone give me a clue as to why when i use a keybinding on keyboard it works but if i use the same binding of the gamepad it wont?
the input manager does not provide direct access to the devices. anyway, hopefully they'll face it out eventually, but unity's been incredible slow on such matters and / or very hesitant. so if they'll face it out, it'll probably be in like 10 years or smth.... XD
still seems like an internal error. i don't think it necessarily has to do anything with anything you could change. maybe restart unity
I will try that
didn't work these are the 3 errors i am getting
is the picture showing?
can anyone help me with this?
Hello! Is there a way to cancel binding from method?
Is there a way to press button through script?
look in youtube for one wheel studio
you'll see what you're looking for
also people... I found the cause to my problem, i need someone to help me if they have an idea :
the cause of the problem is that i made my button turn off its parent game object... so when I press it I get those errors... any idea on how I deny that from happening... or am I obliged to change the hierarchy so the button wont turn off its parent
type[] keyboard = new type[2];
//Readonly Keyboard Array
void KeyboardReadonly()
{
keyboard[0] = true;
keyboard[1] = "Keyboard";
if (keyboard[0])
{
Debug.Log(keyboard[1]);
}
}
void Update()
{
KeyboardReadonly();
}
is there an array type that would work for the following?
You could generate your own class that holds a bool and or string in inheritance
Not sure why you want a bool in the string array
object is the base type for everything
i want a bunch of stuff in the array, not just a bool or a string
I think you just want a struct buddy
public struct MyStruct {
public bool someBool;
public string someString;
public int someInt;
}
MyStruct myData;
void InitData() {
myData.someBool = true;
myData.someString = "Keyboard";
if (myData.someBool) {
Debug.log(myData.someString);
}
}```
gotchu ty
Then you could checkout interfaces
Does anyone have a solution for emulating a second controller?
I wanna make a 2 controller game, but only have one
@rare summit you can use the On-Screen Button / On-Screen Stick components, assign them gamepad inputs
not all of them work right, but some do, 2 that worked ok for me were PlayStation Controller and WebGL Gamepad
Heyy! Im not sure if this is the correct channel to ask this, but where exactly can i find the "capabilities" section for android in player settings? I need to make a prototype with microphone input and i need to enable it but i cant find it.
the input system is very confused. it made 3 players
i tried to make a multiplayer game, with a player on controller, one on keyboard and mouse, but it seems keyboard and mouse both generate a new player, is there a way to stop that?
did i set this up wrong?
@rare summit yeah, just dont use one of those 2 fake controllers you just created with On-Screen buttons
no, this is me trying with keyboard and my controller.
the first screenshot is my player.(3 of them)
now im having troubles with unity not running lines of code, im so confused.
check you Control Schemes in the Input Action Asset, add both mouse and keyboard into a single scheme if you want them to be treated as one
should this all be considered one controller
so the way this runs is..
it detects a click: spawns a player
it detects a keyboard input: it spawns another player
it detects any button (not joystick) from a controller: it spawns another player
that's your actions, top left you have a drop down for control schemes, check what you have there
Character with Player Input is set to DontDestroyOnLoad
But when another scene is loaded, the input is disabled
What to do?
NVM, I just had to remove the preexisting player character in the other scene
I found some videos on this topic from one wheel, but I didn't find the right one. Is it possible to link or name the video in which the answer is present?
Hey guys for some reason when I use if(inputaction.triggered) it doesn't work if i press the button too quickly or too slow
show your code
well that's your problem
you shouldn't be reading input in FixedUpdate
Thank you
OK, now I'm getting an issue where the player character doesn't receive input if it's instantiated rather than in the scene from the start
how are you assigning input
I have setup the new input system to use the main camera to raycast where the player has touched on the screen, are there better ways of doing this without needing the camera?
1: Why does my package manager only see Input System version 1.0.2 despite the documentation stating that the latest version is 1.3.0?
2: Why is "Background Behavior" missing from my Input System Package settings?
I am using Unity 2021.1.25f1
Later versions of packages often use newer unity APIs that are limited to newer editor versions
You might need to be on 2022 to use the latest version of input system
I have my doubts that is true due to this: https://i.imgur.com/04SjzXA.png
If I change versions it also shows 1.3.0 as being supported by 2019.4+
seems convincing, not sure why then
You can add package by name manually, it would probably work, I did this for 2021 to get version 1.3
backup 1st!
the doc a bit outdated, but still similar
im using the rebinding tool made by unity with the new input system... Does anyone know what this field does?
I have a question regarding the new input system in general and what's the "ideal approach" to using this. For example inputting a Jump action by varying height based on how long it's held.
- Should we be using the
Invoke Unity Eventsoption or is there nothing worse with the defaultSend Messages? - Is there something internal to the Input System that allows to track a "held" action as opposed to constantly checking frame by frame that it's still pressed?
- Any examples that demonstrate a recent implementation of this behavior for the new system? The example I found doesn't appear to handle a logical hold.
Are you talking about the new input system?
Yes, edited it to clarify, thanks.
You can hook into all of those Disabled The Action is disabled and can't receive input. Waiting The Action is enabled and is actively waiting for input. Started The Input System has received input that started an Interaction with the Action. Performed An Interaction with the Action has been completed. Canceled An Interaction with the Action has been canceled.
Am I right in thinking this video by Samyam is up to date: https://www.youtube.com/watch?v=m5WsmlEOFiA ?
How to use the new input system in Unity! I go over installing the package, the different ways to use the input system, and the recommended way!
📥 Get the Source Code 📥
https://www.patreon.com/posts/55295489
►🤝 Support Me 🤝
Patreon: https://www.patreon.com/samyg
Donate: https://ko-fi.com/samyam
🔗 Relevant Video Links 🔗
ᐅALL of my Input System...
On Input System v1.3.0
It demonstrates v1.0.2, not sure how far off it is
Neither do I, sorry. But basic stuff should work properly I guess
Thanks, I understand
Hello there 👋
I'm trying to achive a pretty complex input system (with the New Input)
the player controller is a TP and with AWSD I can control the character as usual, what I would like to achive is to play "dodge" animation on double-tap on AWSD too
dodge/roll ... you know what I mean.
add an interaction
I guess I could count how many ms pass from the first tap to the second, to know if the user wand to move or dodge
no, you can just add an interaction modifier to your input
umm ... ok but then what?
when I double press the S the character turn to the camera direction
and then roll
check which interaction was activated
I need to avoid that
is the Input Order relevant in the editor?
I could place the double-tap for first
i think it's relevant
Hello. I written a code for simple character moving. My character is for some reason going backwards even i am not holding "s". I think it is something with input cause i tryed following tutorial from brackeys too and everything was good but chaacter was automaticly going backwards. Can someone help please?
it could depends on what event you've subscribed .Start and .Performed are different, also you could you .Cancel to stop it. in any case.
Anyway, debug is always the best solution to figure out what is going on.
Hmmmm
Like you mean functions like Start Upade LateUpdate or what i dont understand
As we are in scripting, throw your code in here at first
If its loads of code, use hastebin #854851968446365696
Did you debug.log your inputaxis if it ever gets -1 and 1?
I advise you to get into unity learn platform and put some time in there to learn what is doing what. Will make you rlife easier 🙂
bro i tryed script trough tutorial and it is still moving backwards please help @chrome walrus
literally it is fifth script
like i even tryed to download free movement asset from asset store and it is not working
My point stands, I can't handguide you through that tutorial or any other basic stuff. You should learn super simple stuff first before going into youtube and do a tutorial about a fullgame. Learn how to debug to see, what your code is doing.
D :
you have some events on you input!
each one respond based on the input event.
xD
{
return phase == UnityEngine.InputSystem.InputActionPhase.Started;
}```
for example, here you the InputActionPhase is used when the user Start Pushing the button
but you have also .Performed which means during, and so if you use it, it will works like a toggle, so once you push a button it will trigger your event without canceling.
where do i change this?
and then there is .Canceled which means you move out your finger from the button
I should do it in the movement script?
did you write your own code? 🤔
yea
You should know where it is xD
i dont use it
keys.Player.Movement.performed += i => moveDirection = i.ReadValue<Vector2>();
this is a typical Input System subscripton
in that case it read a value, but it could be also like...
but i dont have this in my script
keys.Player.Lock.started += i => lockInput = true;
To toggle a bool
ok I surrender ¯_(ツ)_/¯
Sorry
ok
CodeMokey does a pretty nice tutorial about the New Input System, also Brackeys didn't make any tutorial so his stuff is pretty old rightnow
okay ill try that
How would you go about detecting a "Smash", that is, moving a joystick very quickly in a direction very hard? Is there a processor or anything you could do to determine a stick smash, or some sort of code you could do? I need a way to detect a smash separately from normal joystick so I'd need something that wouldn't read when:
- moving the joystick slowly to maximum over several frames
- Moving the joystick quickly but only halfway
- Starting from a halfway position, then moving quickly to the edges
How might I go about programming something like this?
I think a custom interaction would be a good fit
Question:
I made this method for eventsystem of the tmp pro in unity. But, When I tried to add this method on the inspector on the image, it doesn't exist
What are you dragging there, a prefab from project view or from the hierarchy window?
A prefab from hierachy
but, nevermind, I found the cause
it can't use more the two parameters
and I used two parameters for my method
oh okay, ye makes sense
private void OnJump(InputAction.CallbackContext value) { } Can I have a CallbackContext when I'm using SendMessages option?
Having a hard time navigating the Documentation to get a good understand of how it works
I didn't know that was a thing that could be done. It seems like that's what I want, but there is not much in terms of actual documentation for that feature, just a single blurb at the bottom of the Interactions page of the input system documentation. It mentions something about how custom interactions can store state, which I think I'd need to do for this, but it doesn't really mention when it gets reset ("he system might invoke the Reset() method to ask Interactions to reset to the local state at certain points." doesn't really give much information on that...)
Still, what would be a good way to go about this? Maybe starting a timer once the Vector2 is outside some deadzone, and if it reaches a value greater than some threshold within a frame, do the action? I'm not sure how I'd access time during this interval, I don't think Input Actions occur during the update loop...
yeah, maybe try how far you can get with that approach
hi, i wanna ask. how can i check my device type without build? i want to check the platform for different input system
Im trying to do "Right click + Drag" to orbit my camera, but im getting a boatload of errors in the console
how should this be set up to enable rightclick+drag?
Use two actions
first off the modifier would be the right click here, and second mosue position is not a "button"
"Button with one modifier" is not appropriate
Why is right click not the button and the position not the modifier? I know mouse position isnt a button
a modifier is a button
like shift or ctrl
the actual input information you're interested in is the mouse position
so that would be the "button"
but it's not even a button really
it's more like an axis
so overall "button with one modifier" is just not appropriate for this
I see
Right click as a button, mouse movement as a pass-through delta?
Since delta will be the difference from the previous frame, I can track how much it moved and rotate accordingly, if I understand delta correctly, rather than its screen position
I switched to two inputs like you said but MouseMovement isnt an event because its not a button press
which is why I had it as button+mod before
When I googled how to do this, the net said to make it pass through.
¯_(ツ)_/¯
Either way, neither value nor pass through show up as events
did you save the asset
Ah Autosave got unchecked, I didnt save it
This video goes over the difference action types in the new input system for unity, specifically the value, button, and passthrough types. I explain each in depth and go over event callbacks and interactions.
There are three action types with the current input system, Value, Button, and Passthrough.
🔗 Relevant Video Links 🔗
ᐅInput System Gith...
watching this now to understand the difference between value and passthrough
For some reason, the FIRST time and only the FIRST time that I press a direction key, the player moves 4x faster than it should
then on all subsequent key presses, it moves exactly the speed it should
and I cant seem to debug why
ive logged all the values, nothing is wrong, yet it still moves too fast
cameraOrbit.transform.position += movementDir;
thats the move function
why would the move vbelocity be so much higher ONLY on the first time the key is pressed?
Hi… I’m using the new input system, wondering how to handle key releases with it?
I’m using functions like
OnMove(InputValue val)
Wondering how I would handle something like… OnMoveRelease?
Does such thing exist? Or something similar
I just want to track when a Move action has ended
onpointerUp and other similar ones depending one what you're using
Assigning press only/release only etc. doesn't work
Input gets called on all events regardless of specification
Anyone has a fix?
InputAction has a bool called IsPressed, I tried using that but it just brings up errors
context.performed, .started etc look into those
According to the documentation for custom input interactions:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Interactions.html#writing-custom-interactions
Now, you need to tell the Input System about your Interaction. Call this method in your initialization code:
InputSystem.RegisterInteraction<MyWiggleInteraction>();
...what Initialization Code? Does this mean when I'm subscribing to events? It's supposed to be available in the asset editor I believe, so where would I put this code?
I made an Editor script with [InitializeOnLoad] and now it seems to be working. I guess this is what it was supposed to be?
If i want to setup a split keyboard input system are control schemes the right thing to use ?
Restart Unity?
can you expand it?
i did already
wdym
Okay, I have a custom interaction that mostly works for detecting a stick smash:
http://pastie.org/p/2Wv2l5tsWW9L9uyInbRoVi
I have two issues with it:
- Once a Smash starts, it keeps going until you let go of the stick and it gets canceled. I want this to behave like a button, where the performed action happens once and then not until you do the interaction again. How would I make an interaction like this? Do I just need to cancel it right after I perform it?
- I am using my own sort of timer system for detecting how fast you move the joystick because no matter what I try, the timeout functions don't seem to do what I expect. If anyone knows how I could convert that into the
SetTimeoutproperly I'd like to know.
How to make a dialogue tree trigger via a button press when you are close enough in radius to a certain npc.
Also maybe have a button prompt appear over their head and have it ps2 style where horizontal black bars appear on the screen and it switches a camera angle
seems like a problem for https://docs.unity3d.com/ScriptReference/Collider2D.html (with isTrigger set to true)
or https://docs.unity3d.com/ScriptReference/Collider.html if you're working in 3D
you should make your own input- buffer imho.. then check the difference based on Time.frameCount rather than the actual time
You can do this asynchronously if you want
If you want to go this route, I suggest to ditch out the generated-class and implement it your own via InputSystem.onEvent
I will probably be having a frame-based input buffer separately from the interactions, to be used for both buffering and recording, I just want this event to fire when you smash the joystick very quickly to max, rather than slowly moving it forward
I made a typing-game library for Unity so the detecting must be super fast for each button presses and noticed that there's too much overhead with the generated-class, but Inputystem.onEvent provides me with almost raw input performance
that said, detecting the difference is much better with Time.frameCount instead due to the overhead..
just saying, must be a bit overkill for your use case
Just an extra, if your game is an online multiplayer that implements a rollback mechanic, input-buffer is a must... which I rarely seen this used in indie games made with Unity
I'm trying to do mouse-look or gamepad look based on input device in a kinda twinstick shooter setting.
I have a solution that works, but i'm not really happy with the string comparison.
private void Look_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
var value = obj.ReadValue<Vector2>();
if (obj.control.device.name == "Mouse")
{
var worldPoint = Camera.main.ScreenToWorldPoint(value);
var dir = worldPoint - transform.position;
dir.Normalize();
lookInput = dir;
}
else
{
lookInput = value;
}
}
The input binding is set up to either read the right stick or the mouse position.
Anyone know of a better solution to this that doesn't add unreasonable amounts of complexity?
I can use simulated touch, but the unity remote 5 does not work. I'm debugging through prints. Input device: Touchscreen
Try:
if (obj.control.device is Mouse) {
// ...
}```
The new input system explicitly does not support Unity Remote as documented here: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.3/manual/KnownLimitations.html#features-supported-by-old-input-manager
That works, thank you!
Trying to think theoretically at how to reduce input lag to the minimum. The use case is a bit unique (fighting game, game tick locked to 60fps, no frame interpolation). The best I've been able to come up with is:
- maxQueuedFrames should be 1
- Snag the inputs right before you need them.
- Make sure everything runs fast, prioritizing latency over graphics and removing post-processing.
Things I'm not sure how to do on Unity on Windows:
- Delay the Update()+rendering to complete closer to the vsync so the frames being swapped to the front are fresher.
Hello! Is there a way to cancel binding from method or is there a way to press button through script?
...is there a way to press button through script? why you want this tho
you can just call the function that supposed to be triggered by the button press
You can Invoke the onClick method of a button, if you want to.
So, apparently this is a class that exists. It says it has an inspector so I assume it's a component you can add, but I can't find it in the add component menu. I'm on InputSystem 1.1.1 and no updates are available. How can I add an InputRecorder component? I tried to add it in script but it seems like it can't be found in the InputSystem namespace either. Do I need to install something else to get this class?
It doesn't inherit from component, so no, it's just a normal class. No idea why you can't find it though
But it extends mono behaviour, it should be a component, right?
Bizarre, it does... and yet there's this wonderfully useless inheritance hierarchy
@blissful comet it appears to be in the samples
That'd make sense, I didn't install the samples. I'll go get those and see if I can move it somewhere more sensible
Not a fan of the input systems documentation compared to the main unity API, to be honest
Yeah but it's not what i need
I can't press "Escape" to cancel rebinding onclick and can't cancel rebinding from another method
Hi Im currently trying to write a script that will export my inputs to a JSON file and Import them from the same JSON file if one exists (I plan to write a small program that will let you edit the keybindings from outside the game)
This is the script I currently have
using System.IO;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputToJSON : MonoBehaviour
{
public InputActionAsset inputAction;
void Awake()
{
if (!File.Exists(Application.dataPath + "/Test/Rebinds.txt"))
{
inputAction.RemoveAllBindingOverrides();
var rebinds = inputAction.ToJson();
File.WriteAllText(Application.dataPath + "/Test/Rebinds.txt", rebinds);
Debug.Log("Binds Reset");
} else
{
inputAction.Disable();
string rebinds = File.ReadAllText(Application.dataPath + "/Test/Rebinds.txt");
// inputAction.LoadFromJson(rebinds);
inputAction.LoadBindingOverridesFromJson(rebinds);
inputAction.Enable();
Debug.Log("Binds Loaded");
}
}
}
The saving works as expected however when I try to load the bindings nothing changes, Unless I uncomment the LoadFromJson, However when that is uncommented no inputs work but after I recomment it and run again it works and updates the bindings
Im not sure what to do from there
So I have an extremely basic movement set up on a kinematic rb2D. But the input randomly goes to 0,0 for different lengths of time (anywhere from a few frames to a few seconds) and is causing movement stutter. Any known causes for this?
you'd really have to explain your setup for handling input.
Pretty much everything is its default settings. I've tried the code a number of other ways (fixedupdate, update, removing the time; reading the value on only started or performed) but it all has the same issue.
Would it be best to make a separate script that returns inputs? like making a InputManager.cs script and if I was doing a dialogue system, adding it to the player script and dialogue system script?
maybe maybe not. Depends on how your game is structured and if it makes sense in your particular case. ¯_(ツ)_/¯
Maybe your code is setting it randomly to zero at some point, we gotta see more about your setup
The screenshot is the entirety of the code. Brand new project.
Did you check with another controller?
The same thing was happening with the keyboard, but I can try another controller as well
Oh okay, if it was happening, then did you debuglog only your input raw?
I debuglogged the variable that was storing the input, I didn't check to see if there was any other weird input other than the joystick/wasd happening though. If that's your recommendation, what's the easiest was to capture that?
If you debug logged the ReadValue<Vector2> part, than you are good to go. And that randomly spit out 0?
Yeah, it would work as expected for a few seconds then change to 0,0 for a few frames before changing back.
I have a problem i can move the camera on the gamepad but it isn't working on the mouse does anyone know the problem?
Hi fellas o/
When we're navigating between UI elements both horizontal and vertical axes are used to change to the next/past slider, but it behaves different for sliders by using the horizontal axis(when on horizontal slider) for changing its value. Is there a way to make it changes to the next/past slider instead of editing the current slider? only editing the currently selected slider when the submit button is pushed?
I would test it on another machine just to be sure, its not your unity or machine doing something weird here.
Oh wait, you are using fixed udpate @granite quest right? Can you try to readvalue in update
What does your readvalue output when debug.logging it and using mouse
No change. I'll try another computer.
Oh. My editor wasn't up to date. 🤦 It works now.
Thanks for the help, though!
Didnt know I had to point this out 😄 😉 Great you got it solved
Yeah lmao apparently when I updated it yesterday I downloaded the wrong version. Whoops.
Nvm i just had to add a control scheme ty.
Anyone have experience with navigation? How can you explicitly choose what to select when u click something? Like this is a very common occurence. If you're on the main menu and click settings, it should change new navigation point to be the first in list of settings but I dont see a way to change what is selected when u click something. How is that not a thing given how import it is for functionality? Am i missing something?
I forgot I could split inputs into categories and extend off those categories in my scripts whew, now i can specify without having to make a general input class
Yep - Action Maps
whats currently the best way to have a button combinations?
with the "new"(idk how new it is now) input system im having a weird issue with how when I use the key path such as <Keyboard>/escape it not only triggers with pressing escape but also when pressing e. same thing happens when I switch it to <Keyboard>/space, it triggers with space and with s, whats going on here is there a setting or something thats causing this?
I'm having trouble with a few scripts. Two different scripts have input system objects that need to be active at the same time. Does this cause issues? or can two different maps be active at the same time? If not, I might just have an external script handle all input and just send the data to the scripts I need them at.
The reason I have two separate ones is because I want to do different things to the aim input depending on the device, but I wouldn't be surprised if that had a simpler solution
Here are my error messages:
and the code in question:
private void Awake()
{
// Update script on what direction and magnitude to change aim angle
// mouse
controls.FirstPersonCamera.MouseLook.performed += ctx => lookInputMouse = ctx.ReadValue<Vector2>();
controls.FirstPersonCamera.MouseLook.canceled += ctx => lookInputMouse = Vector2.zero;
// gamepad
controls.FirstPersonCamera.GamepadLook.performed += ctx => lookInputGamepad = ctx.ReadValue<Vector2>();
controls.FirstPersonCamera.GamepadLook.canceled += ctx => lookInputGamepad = Vector2.zero;
}
private void OnEnable()
{
controls.FirstPersonCamera.Enable();
}
private void OnDisable()
{
controls.FirstPersonCamera.Disable();
}
forgot this lol:
controls = new PlayerControls();