#🖱️┃input-system
1 messages · Page 59 of 1
Hey, i have a small racing game with the new input system. So i have an action map with some actions for accellerating, braking and rotating. Support for Keyboard and Controller. How do i get it working on some Wheels like the logitech G29 (G920 etc) and other wheels? I have read something about "HID" but i dont really understand how i can map them generally to the action. i do not want to create a HID for every single wheel that exist.
Any ideas why this situation occurs?:
I have a 2D player that moves in all 8 directions and a tilemap with boxes scattered around.
If I hold 2 keys at the same time (for example W and D) the player moves diagonally until it collides with a box, then it slides along its side (so north/west) until it exists the collider's range. That's all fine, but if I keep holding W and D through all that interaction, once the player passes the box it keeps moving on one axis (north/west) instead of returning to the diagonal movement ( as it should be normal ).
The player is built using the input system for movement, so I figured it has to do something with it.
I can't wrap my mind around why this is happening. Thanks in advance!
I have been following brackets 3rd person movement video
But I don't know how I will use the new input system
What if I used the old one?? And can I use the old one??
Brackeys uses the old one so you should use the old one with it
You'd have to share your code
It's literally the most basic new input system setup there is, I didn't really code anything for it
Ok seems pretty simple to me. This is the order of events:
- You get an OnMove setting your velocity diagonal.
- Your object hits a box or whatever, so it starts sliding along the dge of that
- There's no change in your input actuation after that so the object continues sliding in it's current direction after it clears the box
You won't receive another OnMove until the actuation of the keys changes
Also are you setting up the event subscription for OnMove manually?
I see you are using the generated C# class
A fix for you would be to switch away from using events for this and instead poll the input in update:
void Update() {
Vector2 inputDir = playerInput.Movement.Move.ReadValue<Vector2>();
rb.velocity = inputDir * speed;
}```
the thing is I'm coding a local multiplayer game, so I'm using a playeInput component and 2 different control schemes on the same keyboard. I was previously using this solution, but with 2 players the input gets sent to both of them.
Or is there a way to split it here as well?
If you're using PlayerInput what's the deal with playerInput = new PlayerInputActions();
that's decidedly not using the PLayerInput component
Anyway you can get it working with events from the PlayerInput component too. Just take your current code but instead of settign the velocity in the event handler, just save the Vector2 from the input into a variable
Then set velocity in Update or FixedUpdate from that stored Vector2
e.g.
Vector2 moveInput;
void OnMove(InputAction.CallbackContext ctx) {
moveInput = ctx.ReadValue<Vector2>();
}
void FixedUpdate() {
rb.velocity = moveInput * speed;
}```
To be honest, I'm not sure either 😄 I'm still new to this system and I still can't fully grasp the concept
If you are using PLayerInput, that should not be there. That's an example of an alternative way of setting things up. It sounds like you are using a mix of two approaches without realizing it
It is indeed a mix, I used the PlayerInputActions approach at first until I had to implement multiplayer, so I had to switch and yeah I mixed them up
Hi, does anyone know, how to make interaction button with input system?
For example, I want to open the doors or pick up an item with "E" or "BUTTON EAST"
I’m a beginner at coding, so can You explain a little bit? I use 3th person starting asset https://youtu.be/4QuPlKzdq14
Starter Assets are designed to work as a quick start into prototyping and developing character controllers for various game genres, using systems and methods that are easy to build and expand upon for different projects.
▶ Read more on the Starter Assets https://on.unity.com/3gvKQAX
▶ Technical questions and support https://on.unity.com/3cZlo4P...
Hello i am reading currently the Documentation of the new Input System from Unity. There is for to create a Simple Fire Type Action this example
var action = new InputAction(binding: "*/{primaryAction}"); And i dont understand for what the "*/{primaryAction}" is. Can someone explain me what that means?
Doing this doesn't work, for some reason moveInput gets updated in that function, but in Update/FixedUpdate it remains (0,0) whatever you do, it doesn't get updated
You did something wrong then. Probably redeclared a local variable or something
I still haven't received an answer to this problem: https://forum.unity.com/threads/trying-to-use-the-new-input-system-but-having-issues-updating.1253427/
Alternatively does anybody have a link to download 1.3.0?
Well if anyone's searching for the same thing com.unity.inputsystem@1.3.0 is the git url to add
You can add the package with package manager via package-name
Hello, I'm having problems with the new input system. For some reason when I press the screen the framerate of my game goes crazy low, is this a bug from the package or those this have a solution?
Hello, I it possible to bind an On-ScreenButton component to an Input Action instead of a key?
What should I be using if I want to add a 3D looking system? For instance, using the mouse scroll wheel to zoom in.
I think you can connect scroll wheel to manipulate camera projection size
I'm thinking I need a teacher/mentor/partner to help me as in the past I was never able to fully get a good camera system working. Issues with gimbal and maths.
how to implement tap & hold interaction with one key (space key)? Like, I need to get the hold value from ctx callback for now
yeah, hope someone can help with that, working with camera is a bit tricky for me
@vocal jay
#💻┃unity-talk message
thanks for the help!!
where can i find that menu?
thanks ill have a look :D
I have the new Input System installed and am trying to use the C# code using UnityEngine.InputSystem; but it's not working saying it's not reconized.
I followed the steps but it doesn't appear to be working.
Make sure your IDE is configured properly and try regenerating project files.
Also if you're using assembly definitions, make sure they have a reference to the input system
Need help with this issue, anyone?
That worked, thank you!
um so Im making a vr game and im adding a grapple to it, this is my code and error message
Can anyone help?
you're just missing the using UnityEngine.InputSystem; directive
as the error says
press the circle
whats the best way to register input from ui clicks and drags etc ?
Would it be inefficient to use UnityEvents to program my InputAction's responses, or should I use regular delegate events? It would be more of a hassle to have that be the case, as the ease of creation would be greatly increased, but are there any performance issues with that?
Is it safe to attach the input actions to multiple game objects? Like to a MoveController and to a CombatController or will it somehow misbehave in calling the invoked methods reliably?
There's no problem with that.
Anyone know where I might find a good tutorial on implementing “Grab to move, scale, and rotate” regarding player movement for VR/Oculus dev?
Hi everyone, could someone please point me in the direction of some resources that would allow me to get my head around interactions in the new input system? Trying to use a Press and Release interaction but the official docs are not getting the ideas through my thick skull.
I don't think that's it. Unless I'm mistraken.
I believe the script is attached to the component fine.
The C# script has already been dragged/attached to it.
and did you drag that component instance into the field
or did you drag the script from the project view
Hmm. Testing brb
@glass yacht Your right.
Thank you so much!
Now to figure out how to make it send to the correct C# code/function.
In regards to getting the C# function to trigger, is this wrong?
Nothing seems to trigger the function
Is anyone familiar with the new input system able to help me get it setup and working in C#? I believe I have everything setup correctly but the C# code won't trigger/run.
Too many bindings
Start simple
Just the keyboard
Add more later
Show the action itself
Also you're almost definitely adding unecessary interactions
This?
I'm trying to make my weapon sway work with the new Input System but the weapon sway looks laggy and snappy sometimes and I havent found out why.
Weaponsway code
private void DetermineRotation(){
Vector2 mouseAxis = playerMovementInput * swayAmount;
transform.localPosition += new Vector3(mouseAxis.x, mouseAxis.y, 0);
}
playerMovementInput is the recieved Delta Mouse input but the movement looks laggy. I tried multiple weapon sways out code wise but all end up seeming laggy.
This is my Input setup for the camera
where are you running this code
In fixedUpdate
that's why
oh?
But how do I keep constant weapon sway regardless of framerate then?
Well what I can say is that input is updated each frame
in Update
so by reading this in FixedUpdate you're missing mouse input from some frames
hence the weird stuttering
mouse input is also framerate independent automatically
so the actual mouse handling can safely be done in Update without any adjustments
Aight lemme try that rq
your code is confusing me though I have little idea as to what you're repositioning with this code
and why you're changing a position inside a method called "DetermineRotation"
code got a bit messed up after trying a lot of things out.
Im changing the weapons localposition
what's the difference between scroll x and scroll y? I tried doing <Mouse>/scroll for my binding to rotate between weapons, but it's not working.
i wanted to maybe try one of those
horizontal/vertical
some mouses have horizontal scrolling features
scroll y would be the "standard" scrolling
yes
I changed the code and when i scroll my mouse wheel my debug statement in my update function only outputs 0. https://pastebin.com/fsksJCfh
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I've never seen the input system used this way 😮
I'm not really an expert on creating InputActions manually in code like this
i normally don't do it this way, someone else in my group does though, and i want to keep it consistent since he likes to keep things organized like that
i think it could have to do with being a 1d vector
and not just a single value
Two days later and I figured out the Input system isn't working because I upgraded a older map to the current Unity version.
lemme try something
I think I have the right idea but I don't quite know the string i should use for binding. I want to add a composite binding and do scrolling up and down on the scroll wheel separately, but I only know the string to get input from the scroll wheel itself, not the specific direction
hi im using the new unity input system. how can i change the scrollbar value on mousewheel scrolling?
It should happen automatically as long as your input module is set up with the defaults for the new system
i have 2 canvases
what is a more convenient way of doing this?
is it possible to do something similar using a switch statement for example?
switch - no. just subscribe to the events
InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
UnityEngine.EventSystems.BaseInput.GetButtonDown (System.String buttonName) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/BaseInput.cs:126)
UnityEngine.EventSystems.StandaloneInputModule.ShouldActivateModule () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/StandaloneInputModule.cs:227)
UnityEngine.EventSystems.EventSystem.Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:474)
Is there a way to figure out which script still uses the old functions?
I checked every script, but can't find it
Put those KeyControls in a collection and loop over them
It's the input module on your event system
Literally says it there: StandaloneInputModule
I think this would be the best place to ask for this
I'm modding a game, which we have full access to source code for, but not a buildable version, so everything is done using DNSpy and patching the assembly-csharp.dll file
I'm wanting to inject inputs straight into the game, with as high of precision as I can get
The Unity version the game was written in was 2017.4.10f1
For better clarification, I am trying to inject inputs based on a file I will read, without human input
It will read the file, then figure out what to send to the game, and what to press
I'm wanting this to be in the game itself in order to escape lag
It is a single player game, with simple 2d graphics
Oh hadn't thought about that... makes sense
Are control schemes the right thing for split keyboard controls?
I set up 2 control schemes 'keyboard left' and keyboard right' one using the wasd keys the other the arrows, but unity seems to not allow to split one device in 2.
I tried using the input manager to spawn to player prefabs but it only spawns one, always the keyboard left one too.
What exactly are you trying to do, use the arrow buttons for one input and WASD for the others?
Okay, So i have some ideas of how to fix my issue, but I dont feel like they're right.
I am trying to use a PlayerInput component detect an initial press of the spacebar as one action, and the release of the spacebar as another action. This is to get Hold time of Spacebar to create an analog jump height, but that is kinda irrelevant as the issue doesnt lie in the purpose, the issue is that Even though i am using an interaction on the spacebar actions to try to make them only run when its an intial press or a final release, its sending the event on detection of press, hold, and release no matter the interaction.
The attached images are what the relevant InputActions look like.
The root action Jump Press and Jump Release both have ActionType Pass Through and Control Type of Key.
I have both assigned to a JumpPress() and JumpRelease() method in a PlayerScript script, and I put count++; in each method to see if it was triggering properly, and each method was being triggered 3 times, 2 times if i press it fast enough (which makes sense)
I have no idea how to get the desired behavior for each action, and Ive been fiddling with it for hours.
My solutions i have in mind are just use one action and code to ignore the 2nd input to just manually add GetKeyDown and GetKey and GetKeyUp behavior but that wont always work because of this inputsystem only giving 2 triggers if the key is pressed quick enough, and just reading the values directly from Keyboard.current is just the old Input System but with extra steps which ive done in the past and I'd rather use the New InputSystem to its fullest extent.
What should I do?
No matter what setting i put my action on, it always reads three triggers of the key and not just one.
Okay, more research leads me to say that there is no way for the action to just be triggered once, apparently the input system is designed to be 'open-ended' which in my book means badly programmed
you're way overcomplicating this. Just use one action, with the default interaction and listen for/subscribe to the performed and canceled phases of it
What is the newest prod input system version? is it 1.02 ?
Because I encountered some bugs and I can see in the changelog that the newest version is 1.3
but I cannot update it in the package manager
nevermind, found it.
kinda hidden
lol
every input has a context which gets triggered 3 times
started
performed
ended
1sec I saw it somewhere
Oh i just put it in the parameters probably lemme test
or just show your line where you assigned the event
Somewhere there you can call the context phase to be triggered on
oh then you are doing the same as I am
thats good
okey 1sec
so you're basically calling a methode in your script right
yes, does the method need to have the CallbackContext parameter? thats what im about to test
correct
yeee
heres an example:
public void InputProne(CallbackContext context)
{
if(context.started)
{
// do your stuff
}
}
started gets called imidiately once you press it / or hold.
just play around what suits your needs.
What namespace is CallbackContext?
using static UnityEngine.InputSystem.InputAction;
if you are using vs code
just hover over the parameter with the not found namespace
and press
strg + .
it should give you solutions
im using vs
Should be InputProne(InputAction.CallbackContext context)
Got it
InputAction is not a namespace
Yea, thats exactly what i did
it's a containing class
InputAction is a containing class DAMN we typed the same thing
well, it works and makes my code cleaner to read
hate to see that in my parameter
whatever suits your needs
While I am at it
I just switched to the newest input system version and my look methode seems wrong now.
It seems like the mouse delta isnt getting reset.
So it just keeps moving in the last direction endlessly
do I need to reset it somehow with the context.canceled ?
depends on how you've set things up
its via UnityEvents and this used to work perfectly
public void InputLook(CallbackContext context)
{
playerMovementInput = context.ReadValue<Vector2>();
}
private void Update()
{
yRotation += playerMovementInput.x * 3f;
}
Just check if it's getting called for the canceled case, seems like not. Do you have any interactions or anything set?
And how is the action configured?
Value/Vector2?
try pass through
oh also
try removing the gamepad binding
if you have keyboard and gamepad
that likes to not work well together
just to see if that's the issue
tested it and its not the issue
issue still exists
1sec
pass through didnt work aswell
same result
add some logging
see when and where the method is being called, with what values, and what phase
so canceled isnt getting called
it just gets called once I stop the play mode
performed gets called everytime I move the mouse, that's it
yeah delta mouse
ohh
yeah I don't think that'll ever give you a cancelled
honestly for a "continuous" input thing like this it's probably better just to poll it
isnt there an easier way? o.O
Why did it change suddenly with newer version
It used to reset the input once I stopped moving the mouse
no clue
Issue previously mentioned still exists ^
My mouse delta isnt reseting its values, therefore the camera always continue to move in the last direction I moved.
Gamepad right stick works just fine, but mouse delta is causing me this weird behavior.
It worked fine in version 1.0.2
but atfer upgrading to 1.3.0 it stopped working properly.
same behavior in 1.2.0, 1.1.1
public class CL_BattleCamera : MonoBehaviour
{
[SerializeField] private float sensitivityX;
private float xRotation;
private Vector2 playerMovementInput;
private void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
Application.targetFrameRate = 160;
}
public void InputLook(CallbackContext context)
{
playerMovementInput = context.ReadValue<Vector2>();
// this value doesnt reset
}
private void Update()
{
xRotation += playerMovementInput.y * sensitivityX;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
}
private void LateUpdate()
{
CalculateCamera();
}
private void CalculateCamera()
{
transform.localRotation = Quaternion.Euler(-xRotation, 0f, 0f);
}
}
Bug in video below
What am I supposed to do with this error
Exception 'InvalidOperationException' thrown from state change monitor 'InputActionState' on 'Stick:/DualShock4GamepadHID/leftStick'
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)
I'm trying to add haptics for controllers to my game. I made this IEnumerator to play haptics for a certain amount of time before stopping. However, for some reason, whenever I use StartCoroutine to call the IEnumerator, the haptics just play for a split-second and then stop, no matter how long I set the duration for. This happens even if I'm only calling it once when doing something such as pressing a button on the controller. Can anyone see what is wrong?
maybe from having the wrong control type for the device/control it's bound to?
how and where are you starting this coroutine?
I'm using StartCoroutine. It doesn't matter where I use it. Everywhere I try it, it doesn't work. For example, I could use it in the start function. It's only being called once, but it still doesn't work.
it does m atter where you use it
it matters a lot
if it's in Update for example you can end up with multiple coroutines running simultaenously
I meant that it doesn't work no matter where I use it
what also matters is the parameters you pass in
I'm not using it in update
so I'd like to see how and where you're calling it, and with what parameters
Here, I just made this new Start function. It's only being called once. Still only rumbles for a split second.
do you have other code that is also affecting the haptics still in your game?
No, I'm not even calling the coroutine anywhere else anymore because it's not working for seeminly no reason.
When I do it in update the rumble works like normal but continues forever because it's being infinitely called, so it's not a problem with my controller
make a fresh scene
put only a script with these snippets in it:
#🖱️┃input-system message
#🖱️┃input-system message
(you can even get rid of the hasAuthority thing etc for this test)
Okay, for some reason the haptics decided to work now. I think maybe it was some sort of problem with my controller, because it was working before and then it stopped working and now it's working again. I'll just hope this doesn't happen again. Thanks for the help tho
does anyone know what this binding path was replaced with? i don't see it anymore on the options
nvm forgot these
How would I fix that?
I think I encountered this problem before. What I did was compare the value from the previous frame with the current and only process it if it changed. The probability that the mouse delta is the exact same when moving it between frames is extremely small. The solution seems janky though. There has to be better ways 😐
This seems so scuffed 😦
My game is legit unplayable right now due to this
I can’t be the only one with this problem
My problem still exists.. I have no clue on how to properly solve this. Might aswell write a ticket to unity
Just poll the input in Update
You could've moved on from this hours ago
poll the input in update? What does that mean
void Update () {
Vector2 input = myInputAction.ReadValue<Vector2>();
}```
That makes sense
ty
I think I didn't think about that because I was so used to using the Methode with the parameter which only gets called if I move the mouse
I'm trying to use the new input system to make a free-looking/rotating camera. Any suggestions?
is there a way of reading which button i am pushing through Unity events?
{
switch(context.action)
{
case context.action
}
}```
kind of like if im calling this inputaction through different events? so i can use different cases for each button instead of writing a lot of functions for each button
I've been wondering the same thing.
@valid dagger @cobalt ivy
I would suggest looking up how to rebind keys, as it requires to also get the button that got pressed.
Perhaps you can get smth useful out of it.
https://www.youtube.com/watch?v=dUCcZrPhwSo 08:29 perhaps
This Unity Input System tutorial will teach you how to implement key rebinding in your project. For project files access, check out my GitHub here: https://github.com/DapperDino/Input-System-Tutorials
Multiplayer Course: https://www.udemy....
Looks like it's using separate functions for each action/button.
ah you're right.
Just saw that aswell
perhaps deep dive into that and find out how they do it code wise?
It's not a big deal for me at just the testing/prototyping phase.
Did I think?
Oh well
I have plenty of time to learn this later.
I wonder if eating a little mold is bad...
Google says it's fine.
Bug with Delta Mouse not stopping or resetting!
In case anyone gets the same bug as me, it's an official bug now for the input system.
It happend for me when I switched from version 1.0.2 to 1.3.0.
how to fix?
Restarting unity DOES NOT fix it
you actually need to restart your whole Computer for some reason.
just wanted to type that here in case anyone is having the same problem in the future and is using the "search" function in discord! 👍
Having trouble implementing two different interactions in an InputAction: a tap and a hold, with different results from either (a dodge and a sprint).
This is the code I have in my OnDodge() function, which I'm fairly certain isn't right.
private void OnDodge(){
float holdThreshold = InputSystem.settings.defaultHoldTime;
//controls.Character.Dodge.
if (characterIsGrounded)
{
if (dodgeInput > 0.0f && Time.deltaTime < holdThreshold)
{
// For dodging (backwards)
characterController.Move(-characterController.transform.forward * dodgeRate);
return;
}
else if (dodgeInput > 0.0f && Time.deltaTime >= holdThreshold)
{
// For sprinting
characterController.Move(characterController.transform.forward * dodgeRate);
}
}
}
Cinemachine Freelook
you can't just check Time.deltaTime, you need to actually make a timer variable and increment that by deltaTime each frame to see how much time has elapsed
Right… I forgot about that.
Sorry.
Hey, I have a problem with the new Input System. I'm working on a project, and i'm using Mouse.current to get the mouse position. But then, when my friend tries to open the project in the editor, he suddenly gets a NullReferenceException (that is, Mouse.current is null). I did some research and apparently it the input system does this weird stuff on laptops (which is exactly what's happening here). Any idea on how to fix it?
Yea, i have the same problem. Did anyone can solve this yet?
You can't use Mouse.current safely if you are planning on your game running on devices that don't have a mouse.
You should check if Mouse.current is not null
But really you should try to avoid reading input from devices directly
Instead, use Input Actions
Sounds reasonable. Then how can I read the mouse position from the input actions?
You make an input actions asset
create an action that is bound to the mouse position
and read it in your code in one of about a dozen different ways 😛
Alright, and should I maybe use "Pointer" instead of "Mouse"? I mean, touchpads in laptops are sadly a thing, and idk how Unity handles those
We also have a problem that for some reason, my friend (on laptop) is unable to click UI buttons, while I (on PC) can do it just fine. Any idea on how to fix that?
There are a billion reasons why you may not be able to click them, try checking some possible reasons online (object is blocked, etc.)
The thing is, it works fine on one machine, but doesn't work at all on the other machine. The project was recently synced, so it should technically be the same on both devices. Yet the laptop struggles where the PC does not, and i'd guess it might have something to do with the Event System that is made to be working with the new Input System
And similar issue is occurring with the rest of input system - the laptop doesn't want to detect any movement, no matter if mouse is connected or not, no matter if the touchpad is disabled or not
I think this is where I should ask this question
I'm not sure how to fix this
I think it happened because I changed the file name
your name prob dosn't match the script
Make sure 1.make sure Class name matches whats in editor 2. you have no errors in console
it's telling you got errors, so it can't compile
Did you open the script in edtor and says public class ShouldHover: MonoBehaviour
There's still this message though
Does the name of the class match the filename of the script?
Reassign the script
ok sorry if this is a stupid question but im getting an error that Input doesnt have a definition for getAxis()?
Methods are spelt in CamelCase
i got it figured out, thank you!
Sure you're welcome
turns out i didnt configure VS to work with Unity.
Like this?
private void OnDodge()
{
float holdThreshold = InputSystem.settings.defaultHoldTime;
float dodgeHoldTime = 0.0f;
//controls.Character.Dodge.
if (dodgeInput > 0.0f)
{
dodgeHoldTime += Time.deltaTime;
if (characterIsGrounded && dodgeHoldTime > holdThreshold)
{
characterController.Move(characterController.transform.forward * dodgeRate);
}
}
}
No because you're declaring that variable inside the method, it's local and can't hold data between runs
You also need to separate the logic into a start dodging bit and a _check if still dodging _ bit
Okay
Granted, I'm also trying to use these interaction parameters:
Hey I'm having an issue with mouse scrolling. When I scroll one tick on my scroll wheel, it calls the appropriate function twice instead of once
probably two different phases
started/performed or performed/canceled
i added context to started and nothing else
hang on
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.
here @austere grotto
Hi I am working on a game right now and I'm having a little trouble and no videos I've seen can really help I'm not sure if its the "new" input system but I can't get my doors to work even if I put them on a hinge I couldn't make it open with an interact button or anything also the player can literally just walk through the door ignoring the collider? I'm doing something very wrong just not sure what
are you sure it's issue with input system ? try posting some code here see maybe if it's code related first #💻┃code-beginner
sounds more like an issue with colliders and rigidbodies though
This is the most current code that I was trying to use I changed the input system to both because of the Input.GetKeyDown kept making it pop up errors
#854851968446365696 to how to post code, input.getkeydown is old input
dont put input reading in fixedupdate
I changed the Character input to have an interact button too and it didn't seem to work i hit play and it worked one time but not the next play
@heavy rivet also you want to use collision.gameObject.CompareTag instead
there could be multiple things wrong going on. Again you don't wanna get your Input in FixedUpdate but in Update()
FixedUpdate occurs every physics update
@heavy rivet please post this on #💻┃code-beginner to get more people to see on this, also post useful screenshots of your inspector window too
Thank you
Hello ! I'd like to show these WASD bindings (One text for each) and to do so I add in my prefab's script a specified InputBindingComposite CorrespondingBind to say which one it should shows
I can't find a way to access the inputs of a Vector2, anyone knows how to ?
Hello. With Unity and a Quest2, I am trying to develop an application that evaluates the pose of the user's head without relying on the images from the Quest's cameras. In other, I need to access the raw data from its Accelerometer and gyroscope. In my use case, the images from cameras wouldn't be relevant at all to evaluate users'pose.
But I haven't found any way to get those raw data.
Is it possible?
I have a door, which can be focussed on through PlayerLogic. But now I want the door to temporarily subscribe to the user inputs so that I can use the mouse scroll wheel to open / close the door. What's a good way of doing so? And is temporarily subscribing to inputs on a gameobject a bad practice?
Well since you're sure that the unsubscribe method is called when the inputs are no longer needed, It shouldn't be a bad practice
You can look at the Command pattern
So there's nothing wrong with temporarily subscribing? Everything I've seen about events shows to only subscribe them in onenable/ondisable
Nope, temporary subscriptions are totally normal and good practice
Cool, tysm!
Define "not working"
Are you getting some kind of error? Explain a bit more
nvm
I currently have the cursor changed to a aiming sprite, but when I switch from mouse to gamepad, I thought the best strategy would be to then start moving around a secondary(duplicate) aiming sprite based on the gamepad input. This means I have to deal with the cursor image, and the secondary duplicate aiming sprite. But ideally i'd rather have the right stick of the gamepad & the mouse both move just one, so I dont have to have two images that I turn one off/on based on gamepad usage.
What's the best way to do this?
yes, that's the goal
and I want the solution to be expandable, so if I ever want to add IJKL for input it wouldn't take much
fyi, I have already tried this solution, which in theory is perfect for my use case https://forum.unity.com/threads/keyboard-splitter-local-multiplayer-keyboard.874135/
but in practice I get some key press ghosting which is not present when I only use Player Input with a single control scheme
Then you can literally just use multiple bindings
Hello, is it possible to self send a performed event on a specified action ?
In code and in run-time
So I'm using the send message style of control input (because of it's ease of use with local multiplayer) which will duplicate a given player gameobject whenever new input is detected to create an additional character. Is there an intuitive way to select that gameobject instance to write data into it (such as player index, color, etc) without resorting to having an auxiliary script watching the root where player objects are created and writing data into them? Honestly I'm just curious what the proper data structure is for this and that's the best way I could think how but I could be way off the mark here.
guys idk what's wrong when i add this script to my player unity crash
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camemove : MonoBehaviour
{
public float sens;
public float xrot;
public float yrot;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
xrot += Input.GetAxis("Mouse X") * sens;
yrot -= Input.GetAxis("Mouse Y") * sens;
transform.eulerAngles = new Vector3(yrot, xrot, 0);
}
}
and i have a camera connected to the player
I doubt this script is the problem
Hopefully this should be quick i installed the new unity input system package and restarted unity but i tried importing it in a script and it is saying the namespace doesnt exist. Any fixes for this?
In the experimental version of the new input system, you could declare input systems as public/private InputMaster (I am following the brackeys tutorial to learn it) but I don't think this works anymore. Does anyone know what the new version is if there is one?
It has nothing to do with versions of the input system. That's just the name he gave to his input actions asset and he checked the box to create the generated C# class from it
Make sure your IDE is configured and try Regenerate Project Files
im pretty sure my ide is configured and i already tried regenerate project files with no luck
Are you sure? This is what he did
100% sure
let me figure this out quick
Reread what I said it has all the information you need
okay
Sorry for my noobiness
I see
Thanks
I got it working
this has some weird syntax
Hi everyone, could someone possibly help me work through an implementation that is tying me in knots? I think I might be using the wrong kind of inputs but I just don't know.
In a nutshell, the game has guns - some are semi-automatic, some are fully automatic.
I have created a single 'Fire' action, given it the 'Button' action type, and added a 'Press and Release' interaction (so that the full auto gun can stop firing on release and start firing on press - or fire a single shot on press for a semi auto)
However, how would I check whether the button is being pressed or released in code? I can't seem to find the syntax anywhere.
presumably the button still returns a value between 0 and 1?
Don't use press and release
Get rid of all interactions
Listen to started and canceled to get the press and the release
Should i use a binding in input action with new input system or use Mouse.current.leftButton.wasPressedThisFrame to get left mouse clicks in world?
Making an input action will make it easier to rebind it etc. If you don't care about that, it's fine to use the other way
I've created a dash mechanic using a button, but whenever I start pressing the button, it doesn't change canDash to true. However, if I replace canDash = true with a print statement, it does actually run. Why is it not allowing me to dash/always calling canDash false?
This code makes little sense.
Why are you adding event subscriptions here?
Also canDash is just a local variable so none of what you're doing really matters
You need to make it a member variable
hi guys, im following along a unity tutorial on youtube and im running into this issue, does anyone know a fix
configure your ide#854851968446365696
and you likely don't have a field called playerInput
Just some simple spelling/capitalization errors on your part. Get your IDE configured
thanks guys
Hey I'm trying to get my player to jump and after everything works but I can't get it to jump when it takes the "Player Controller" as the Input Controller. However it works just fine using the AI Controller so I know it isn't any of the variables that are wrong. Why isn't it letting me input as a player?
My code uses GetButtonDown("Jump") to to get the input and I already checked in the project settings that I'm pressing the right button
You'd need to share a lot more details than that. Nobody knows what "Player Controller" or "AI Controller" you're talking about.
Oh right
I have an InputController script that provides the basis for two scriptable objects: Player Controller and AI Controller. The code looks like this
The both controllers override the methods, but while the AI Controller just uses default values, the Player Controller gets input
The both the move and jump method are then called in their own scripts. While movement works completely fine, jumping doesn't
So I think that Unity is somehow not getting my input but only when I get the jumping input?
you'd have to show when and how you are calling GetJumpInput
and what do you do with that desiredJump value? You'd have to make sure you use it immediately that frame
Since it's a GetButtonDown, it will turn false the very next frame, since you're reading it into that variable every frame
yep that's not right
you need to do this:
void Update() {
if (input.GetJumpInput()) {
desiredJump = true;
}
}```
OR a little more advanced with the same result...
```cs
void Update() {
desiredJump |= input.GetJumpInput();
}```
This is because FixedUpdate doesn't run every frame
so you can miss that one frame where it's true if you just blindly assign that input value into the bool every frame
the higher your framerate is, the worse that effect will be.
it's the same as:
desiredJump = desiredJump | input.GetJumpInput();```
In this case | is just the "logical OR" operator
it returns true if either desiredJump is true or input.GetJumpInput()
In english... it just says "make desiredJump true if it already was true, or if there's a jump input this frame (or both)"
otherwise it stays false
Thanks
Anyone know if this is a bug? I'm using EnhancedTouch w/ mouse simulation in update(), and sometimes it will skip the Began phase, but then call it multiple times equal to the times it skipped with only one Ended phase (so multiple touches beginning all ending on one phase). Its like the Begans are weirdly stuck and then somehow repeat sequentially. The active finger count is always only 1 during this, so it's not multiple fingers or anything (and again this is with a mouse in the player so that shouldn't even be possible).
I'd be less confused if there were equal Ended phases, but all those Begans that happen on sequential frames with a single Ended. If I click 3 times with no Began phases appearing, the 4th time will have 4 Began calls across 4 frames (the exact number to trigger this seems to change randomly, and it sometimes works properly)
For reference my code follows this basically. It also worked fine with the old input system (I think links are allowed?) https://forum.unity.com/threads/tutorial-implementing-touch-with-input-systems-enhanced-touch-api.926753/
Thanks, will give that a try, need to do some reading to figure out the syntax for that but am sure I'll get there!
All those += and <= thingies are totally new to me, feels like i'm going to have to strip out a lot of my old code to fix it up 💀
This is my setup and it does not work
and it gives me this in the input debugger if I setup 2 control schemes with a optional keyboard device
and if I disable control schemes both characters move the same way and both react to wasd and arrows
Hi, I started implementing a playerInputController which alternates between actionmaps (for example between gameplay and UI). At the beginning I put the script on the GameManager object in the scene, now I realize the script belongs to the Player object. But when on the Player object, the script isn't able to turn off the gameplay actionmap when changing to the UI screen (player is still moving when navigating UI) but on the GameManager it works as intended.
Why is the script able to turn off an actionmap on an object and not on the other?
plus if I use input manager for only bindings, like you said, it only spawns one character
can you share the code snipper and the inspector view of the player ?
I just checked and if I activate the script while in playmode, it works as intended and actionmaps are being disabled and switched. If I start playmode with the script activated actionmaps are not being disabled.
Any tips?
PS: I deleted the script from the GameManager and put it again. Now actionmaps aren't being disabled on the GameManager and on the player 🤦♂️
So, why would a script work on an object not on the other, and after deleting it from the first object and putting it back again, it doesn't work anymore?
did you use any event subscriptions ? I belive those subsist after game stop
Maybe if I restart unity it works back again
yes I started using those but I'm not experienced in scripting so I understand half of what I'm doing
so basically you have to delete those on game stop
you mean like -= and or Disable() right?
the thing is....IT WORKED
by placing the script on another object, it didn't work anymore
by deleting the script from the original object that used to work, and putting it back on, it stopped working
you see my issue?
probably because you broke the event link and or changed the code inbetween
Yes I guess🥺
restarting might fix it
but if the code still adds event subscriptions without removing them you will encouter it again
i restarted it and it workd with the original object
🤦♂️
no lets see if I restart with the other obejct
modify the code and in awake add Object.RemoveAllListeners()
so now you clean all the past links and make sure to add it too OnApplicationQuit()
I will try this, thanks a lot 👍
You-re welcome
Does anybody know how to do split-keyboard with the new input system ?
Using New Input system, I have it set up for WASD controls, but it will only read a single of the 4 keys, and wont do diagonals from two keys held. If you press another key while holding the first and then let go of the first, it will continue to input the vector of the first and I'm not sure why
How do I figure out what's going wrong?
I debugged the value but the value doesnt change when I change keys held unless I fully let go of all keys first
what do you mean by "set up for WASD controls"? Set up in code? Set up using an InputAction asset?
you'd have to share how you set everything up
show us:
- The Input Action(s)
- The bindings
- The PlayerInput component (if there is one involved)
- Your code
With further debugging it looks like its not sending a new vector, after I press a single key, it sends it once and stops.
Sure let me get those screenshots
digiMovDir doesnt get set every single frame the key is held
I copy and pasted this code from my own unity project and it worked there so I am confused why it doesnt work here despite nothing changing
is there a reason you're using digital normalized?
because I want it to be normalized if you're pressing two keys at the same time?
W+A shouldnt be "faster" than W or A individually
try letting it be whatever the default is and just do digitalMovementDirection = context.ReadValue<Vector2>().normalized;
Sure, seems super bizarre and undocumented to me if that works, 1 sec
No difference
can you show the input action setup
PlayerInput is sometimes finicky about whether to send the events for "cancelled" to zero out your vector
I'm not sure which thing refers to the input action setup
Is it this?
no
👀
Ahh it is a button, I bet in my other project its not
and Control type to Vector2
That figures, when I coped it over I had to remake it by comparing the values, I likely didnt realize/remember that I made this change to the input type
Thanks 👍
Sorry to bother you again but I switched over to the other project, where I got the original code from.
In that other project, it WAS working, but for some reason all my copies of unity are completely fucked up, someone in Unity-Talk told me to delete my Library folder, and after doing that, now the input system is totally broken and I have no idea why or how to fix it.
This one's move buttons ARE set to value and Vector2, all the same exact code, but this one is behaving like a Button, not like a value
Debugging the value shows that its acting like a button not a value, it sets one single time on initial press
but its not set to button, at all
how would deleting library affect new input system?
Is there steps I need to do to regenerate this?
Do you have any interactions set?
How's the binding set up?
Identical to the other project, events, same code
Im not sure which thing refers to an interaction or a binding
Unity told me to change my unity version to a newer one, I just wiped out my project and github pulled the pre-changed one, Input is working again there
Except
Digital normalized?
I cant tell you WHY its working because its set to button
so as far as I know it shouldnt be working, but it is
Yes digital normalized
Didn't we turn that off in the other one?
You may have told me to and either did it and turned it back, or never did it, because its set to normalized atm
Its also set to button, which means none of this should be working, but it is working
and thats concerning
I cant explain it and I cant figure out why its working in 2020.3.13f1 but not in 2020.3.32.f1'
anyone have experience with hooking up a hotas to the system
You can't have fields outside your class
That's a basic C# thing, nothing to do with the Input System itself
How do get the axis of mouse x / mouse y with the new input system
Hello everyone, is there any way to trigger an Input Action from the UI Toolkit? Like, I have a 'Travel' Input Action which is executed on 'T' key presses, I'm trying to do something like "travelButton.clicked += simulateTKeyPress;" or any way to do the same Input Action from a UI Toolkit button, all the info I can find is related to canvas/old ui and can't understand the documentation pretty well, any tip would be appreciated, excuse is my english is not perfect and thank you for the help!
How do i assign a task to a button in inptu sustem
you wouldn't. Rather you'd have some function that you call both from your input handling code and from your UITK event handling code.
wdym by "task" and "button" in this context?
You can bind Mouse Delta to an input action
a method
key board button
like w
a sd
Okay, so from input handling code I would call something like this, because the performed callback needs a callbackcontext right? I made it public to call the same method from the UITK, and passed a 'new InputAction.CallbackContext' from the button.clicked callback since I dont have a context there, do you think that I'm doing this correctly?
you need to make a shared method you call from both places
void Travel() {
Debug.Log("Travel");
}```
Then you call that in both places
public void DoTravel(InputAction.CallbackContext ctx) {
Travel();
}```
likewise, you call Travel() from your UITK stuff
Awesome, thank you so much @austere grotto !
I have posted this questions in two threads but I think this might be the appropriate place to ask. I do apologize if I make anyone feel like I'm spamming.
I'm currently playing a strategic match-three game so I want to create a piece of software that can quickly receive input from the game and test the moves so I can see what the board will look like after I make a certain move. I think the base of this software is a 8x8 match-three game in Unity but I don't know how to quickly provide input for it. What methods would you recommend to quickly transfer the board from the game to my software? Thank you very much.
the 8x8 grid is just 64 squares. Just pass an array of 64 elements (can be ints for example) describing your game board
Oh wait you;re saying... there's some existing built game and you are trying to write a program in Unity that plays that game?
also I don't see how this is the right channel for this at all
Hi im having an issue where I am pressing a button and a function which is assigned to a different button is being activated instead of the function assigned to the button im pressing. is there any way i can fix this?
Seems more like a #📲┃ui-ux question
or wait unless you mean keyboard button?
oh yeah sorry
how would I make it so a inputs method would run over and over while its being held down
Use Update
either:
- poll the action in update:
InputAction whatever;...
void Update() {
if (whatever.IsPressed()) { ... }
}```
Or use events:
```cs
void MyHandler(InputAction.CallbackContext ctx) {
if (ctx.started) isHeld = true;
else if (ctx.canceled) isHeld = false;
}
void Update() {
if (isHeld) ...
}```
ty
New Input System: Does The Mouse Scroll Wheel Go by Scroll(Mouse)? If it does what value do i use for it? I tried using double and it just get getting 0
this is input sytstem
Yeah no this has nothing to do with the input system (old or new). Maybe a #📲┃ui-ux question or just #archived-code-general but it's quite a vague question.
Hi, i'm trying to find either the pointerdata or raycast result for current hover, or the currently hovered gameobject. So far i found that i had to override InputSystemUIInputModule, copy the internal corresponding editor logic and override UpdateModule(), where i check GetLastRaycastResult().
The problem here is that it is documented everywhere that the pointerid should be negative for mouse input, but for me the pointerid is 2,
which makes me think that whatever i build upon this will at some point behave unexpectedly.
So my question is, is there a better way to get the result i need and if not, how can i get a consistent or reliable pointerid ?
heya
cant find any real information on this
how can i get the mouse's world position with the new input system?
you don't. You can get its screen space position
the ways to convert that to world space are the same as they always have been
if there a way to know when an action is performed and when it stops?
Bit confused, folks - I'm trying to detect a double-click-and-hold, but detecting a multi-taps only seems to detect the start of the double-click (ie. each single click) and when the double-click has been released. Any clues?
Yep there's events for started, performed, and canceled
You can't count on those WasPressedThisFrame etc functions for complex interactions
Those are basically for basic buttons only
So that would be the performed event of MouseRghtClickDouble, right?
so could i check if an action is being performed and change a variables' and then when its cancelled it sets it back to the original value?
should i use an if statement to say if started then change this and same for canceled?
Still can't seem to get Unity to recognise a double-click-and-hold... =/
I can't test for the double-click-and-hold because I seem to need to release (cancelling the 'hold') in order to register the double-click.
Should I just assume this is impossible for the Input System? Seems like a simple timer testing for two 'started' events would fix it, but I could be missing something.
I want to replace the old input system with the new input system (The script uses Input.GetAxis(Axis)) which the best choice two axis or one vector 2??
not sure about best but I use Vector2
thanks
I have a button for jump how I can get the equivalent to the GetKeyUp and GetKeyDown??
well idk it's different everyone uses a diff method. I'm still not used to it completly , i'm using a simple boolean with sendmessages in my inputs class cs public void OnJump(InputValue value) { JumpInput(value.isPressed); }
then i docs public void JumpInput(bool newJumpState) { jump = newJumpState; }
so for me is simple if(inputClass.jump){//dooJumping}
@whole mist I learned this a year ago from one of the Unity projects, so not sure, maybe someone else has a better answer . Hope it helps
ok thanks
Anyone know if there has been any update regarding the Input System Mobile/Unity Remote situation? Everything i found was like 2 years ago saying SoonTM
There we go, I'm on the Docs now and I can see it
It's the "Add Positive/Negative option"
what a bout the pos/neg i want it to be keyboard
Wait no, that makes it a 1D vector
You need a 2D vector, which is the "Add up/down/left/right composite" option, which you seemingly don't have
Can you select the Movement action and see if you can change its type from Button to anything else
I found the solution
hi so im trying to fix an issue where after you stop pressing keys to move for a second or 2 you still glide slowly decreasing to come at a stop at whole. how an i fix that. i tried increasing friction but my game has platforms and its hard to get on slanted platforms
is there a way to simulate touch input from a mouse using the new unity input system? when i enable it it starts throwing pointer should have exited errors
Whenever i press the gamepad actions, i am not able to use the keyboard actions, so they dont get called. before i hit a key, keyboard actions are working fine. any idea why?
you don't need to use a composite for the gamepad binding
that might be contributing
i split keyboard and gamepad because i need that the keyboard controls can only move horizontally in a range of -0.5 to 0.5, while the gamepad can -1 to 1
processors on the binding action itself did not work somehow
I understand that I'm saying the gamepad binding doesn't need to be a composite binding
you mean that i can put them together in one composite binding?
but then i do have the problem i mentioned above
No
I mean the keyboard uses its own composite
And the joystick just has a normal binding for Left stick/horizontal
Just this but make the gamepad not a composite
composite is a default property, i cannot remove it
I have no idea what you mean by that
Did the new input system have a way to easily find which control scheme is currently used? like if i have a Keyboard&Mouse or Gamepad control scheme, i would like to do some code differently depending on the control scheme currently used by the player
Mostly for stuff like aiming with a mouse or the stick
Is there any way to disable a single action in the input system?
Yes InputAction has a . Enable and Disable methods
Im doing this and using cinemachine for my camera, but when I disable the look control it still receives my input
hypothetically speaking if you were going to use a special input registry common in fighting games IE: ⬇️ ↘️ ➡️ punch = fireball, how would you go about implementing that?
so i updated to the new input system but it seems there is no way to reference it in code
fixed it
is there a way to rebind these directly through code?
In the Last of us 2 you can shake the ps4 gamepad to toggle the flashlight. Is there a way to detect that in Unity as well or is it some sort of license you need to buy from Sony
I am getting this error with the new input system and I'm not sure how to fix it. It says something is null but i'm not understanding what is null. The input action isnt null afaik
Double clicking it to find out where/what is null doesnt open visual studio
Re-selecting invoke unity events added a Default Map box to the script that seemed to fix it
How do i get a 2D vector binding through code and how can i change it at runtime
How do I properly dispose of the actions from a previous scene that I've listened to? OnEnable for a script I assign an action like so: _rollAction.performed += OnRoll; and OnDisable I remove it like so _rollAction.performed -= OnRoll;
But when I switch scenes I sometimes experience the action calling from the previous context and failing due to null reference exception
that code looks correct.
Maybe share an actual example of an NRE you're getting and the corresponding code?
No need, thanks for confirming that is correct. For anyone else that may stumble upon this issue, I just fixed it by ensuring that the Disable code above was called after the Enable code. I had an InvokeRepeating function that was enabling the input actions just after I had called to switch scenes, so I just cancelled that and it worked
I seem to be having trouble figuring out how to get a touch position return from an input path that also performs a cancel call when the touch is released. Is anyone able to help out with how that can be done from one action?
it can't be done
Why are you trying to do that from one action
is there an on touch up event in the new innput system?
Thank you!
I was thinking about something the wrong way, so I abandoned that course of action.
However, now I'm wondering if there's a way to figure out or force the event order of certain actions that would be called on the same frame?
Basically, I made a click and drag for mouse and keyboard. I always have the mouse position from Drag(). But now I'm updating it for touch, and only have the touch position at the time of touch. I need that initial position before the execution of my main method, Click(), but the order is sometimes random, so i get bad results.
So, now I need to make sure my Drag action is called before Click action each frame they both occur
does upgrading to the new input system makes OnMouseOver and OnMouseExit stop working?
yes
they are not supported in the new input system
you should migrate to IPointerEnterHandler/IPointerExitHandler
yeah discovered it by noticing one thing in my game suddenly not working anymore
How to read "Jump" Action as a trigger when subscribing to his events ? I don't like the idea of checking WasPerformedThisFrame() in Update. Is There a better solution?
Subscribe to the performed event
it will set bool to true but i want to let bool act like a trigger.
perfomed => true then false
IDK what you mean
your subscription code will do whatever you want
you don't have to set something true there
you could have it call the Queen of England if you have her phone number
the real way to do this is:
bool jumpRequested = false;
void HandleJumpInput(CallbackContext ctx) {
jumpRequested = jumpRequested || isGrounded();
}
void FixedUpdate() {
if (jumpRequested) {
jumpRequested = false:
PerformJump();
}
}```
something like that
or just...
void HandleJumpInput(CallbackContext ctx) {
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}```
¯_(ツ)_/¯
No, thats ugly for me.
public event Action IsJumped;
public bool JumpInput;
private void OnEnable()
{
_jumpInput.action.performed += OnJump;
_jumpInput.action.canceled += (ctx) => JumpInput = false;
}
private void OnJump(InputAction.CallbackContext ctx)
{
IsJumped?.Invoke();
JumpInput = ctx.ReadValueAsButton();
}
Came up with this solution
huh
how is that a soluition? What does it even do? What if you release it before the jump is actually performed? The jump won't happen
what's the point of JumpInput = ctx.ReadValueAsButton(); - you already know this is a performed call
In my mind input should be only operated in input related class. I created InputReader where i store pulbic {get; private set;} properties and change them by subscribing to inputactions
that's not really going to be feasible when the jump input thing is something that needs to be consumed by the jumping code
its really subject to change and i maybe will change it
you will need to.
regardless with my example the FixedUpdate doesn't need to be in the same class as the input callback
it was just an example to illustrate how the "trigger" behavior works
you consume the user intent when you do the jump
I could just
public bool jumpInput
private void Update()
{
jumpinput = false
if(jumpAction.WasPerformedThisFrame())
{
jumpInput = true;
}
}
I guess but then what are you doing with jumpInput after? and in that case why not just use a property:
public bool jumpInput => jumpAction.WasPerformedThisFrame();``` and skip the Update altogether?
Thats what i was looking for. Thanks for this. How I didn't figure it out before
Just be careful it depends how you are using this. If you read this value in Update somewhere else it will be ok. If you try to read this in FixedUpdate it won't work reliably.
Is read input in FixedUpdate wrong? When do you need to read input in FixedUpdate?
Reading update like this in FixedUpdate is wrong because FixedUpdate doesn't run every frame
WasPerformedThisFrame will only be true for exactly one frame
so if FixedUpdate doesn't run on that particular frame, you're out of luck
That's why if you need to know the input intent for something like this in FixedUpdate, you use something like this #🖱️┃input-system message
Ok, you didn't understand my question, nevermind. Thanks for help
It's not that you would need to read the input in fixed update, it's if you need the input result for physics related actions.
Since jumping typically involves physics, that would be checked in FixedUpdate. However, you would need to check the input for that. You would get bad results sometimes since FixedUpdate is not run every frame.
The answer was yes (it's wrong), and never (in FixedUpdate).
Not sure how the above answers didn't read that way though, they clearly say the same thing with much more detail.
Saves the inevitable "why" response.
Some people can't read context clues, especially if English isn't their first language and they're communicating in English.
Not saying it to be mean, it's just how it is sometimes
Always can ask to clarify rather than dismissing the answer as not having understrood the question.
Very true
Yes, I'm not a native English speaker but i know that read input in FixedUpdate is not a good idea.
Btw, does anyone know if I'm able to force the event order of actions that occur in the same frame?
My question was to look if I don't see some secret techniques that involves trying to read input in FixedUpdate. But anyway, thanks for conversation
not if you're doing things event-based, but if you poll them yourself you can do it in any order you like:
void Update() {
bool jump = jumpAction.WasPressedThisFrame();
Vector2 mouseDelta = pointerMoveAction.ReadValue<Vector2>();
// etc...
}```
Dang, might need to resort to 1frame delayed coroutine if I don't want to refactor my entire script 😅
Just double checking, it's possible to do events and this example together right? There's no setting that needs to be switched for it like the behavior?
hmm.. I also seem to be having trouble figuring out how to get the specific action cached like you would in your example. I've got the input component cached, but can't seem to go further.
I'm asssuming I use the actionMap with a string of the action name?
what's the "input component"?
There are many ways to approach using the new input system, all with differences in how things work
I've got the PlayerInput component attached to an object with the action asset referenced.
I just recently started learning this system and this was how I learned to do it 😅
ok so PlayerInput is what you're talking about
that's a very specific thing
PlayerInput is meant to be operated in one of three modes - you've selected Invoke Unity Events
so it will call the functions you set up inside the > events foldout there in your inspector
Yup, got that part. So I'm guessing your example doesn't work with this setup?
no not really
😩
You can still get at the input actions from a PlayerInput
but it's cluckier
clunkier**
ya, I'm realizing that as I go down this rabbit hole of properties lol
PlayerInput pi;
InputAction jumpAction;
void Awake() {
pi = GetComponent<PlayerInput>();
// this is <action map name>/<action name>
jumpAction = pi.actions["Player/Jump"];
}```
Oh, so the string is the path like from ctx control path?
not sure what ctx control path is
it's <action map name>/<action name>
from your Input Action Asset
no it's different
Ya, figured that out 😅
Thanks for the help
an alternative is simply don't use PlayerInput
I like to use InputActionReference
Unfortunately this is the only way i know how to use the new InputSystem and everything is almost done already 😅 The only thing it doesn't work for is touch support. Mouse and keyboard works exactly as intended
you can do this:
[SerializeField] InputActionReference jumpRef; // assign this in the inspector to the correct input action
void Update() {
if (jumpRef.action.WasPressedThisFrame()) ...
}``` etc
But i will keep it in mind for next time i use the system
There are many ways to use it
it's very flexible
which unfortunately can be intimidating if you're new to it, because there's a lot of confusing options
Ya, I was very used to the old system, but my partner wanted to use the new system for a reason that I forgot and it was about time I learned it anyway.
Just gonna take some time
Hey, how can one integrate controls from input devices like a drone transmitter in unity?
Can someone help me with the new input system? I've used it before, but now I'm in a new project and it's seemingly not working for no reason. Here is the script I'm using to read the input:
using UnityEngine;
using UnityEngine.InputSystem;
public class CharacterController : MonoBehaviour
{
CharacterInputs characterInputs;
CharacterInputs.DefaultActions actionMap;
InputAction movement;
Vector2 moveVector;
Rigidbody2D rb2d;
void Awake()
{
rb2d = GetComponent<Rigidbody2D>();
characterInputs = new CharacterInputs();
actionMap = characterInputs.Default;
}
void OnEnable()
{
characterInputs.Enable();
actionMap.Enable();
movement = actionMap.Movement;
movement.Enable();
}
void FixedUpdate()
{
moveVector = movement.ReadValue<Vector2>();
Debug.Log(moveVector);
}
}
Here is the asset:
It's auto-generating a script
Is there some setting somewhere that would disable the new input system? I looked at my old project, this is EXACTLY how I have it in that project but it works there and not here.
Also these are literally the only two assets in my project (besides my scene). I just attatched my movement script and a rigid body and a capsule collider to a simple capsule sprite in the game and made a rectangle for the ground.
show the actual configuration for the input action
right now you're showing the binding
What do you mean the actual configuration?
Click on Movement
in the input action asset
to show the configuration for the Movement action
also can you explain what you mean by "it's not working"? What is happening that differs from your expectation?
Oh sorry. moveVector always reads 0,0
ok now a screenshot of this?
Yes, give me a few minutes I will give a screenshot. It might be a little bit though. Should I @ you when I do?
sure
@austere grotto
can you try changing the binding from digital normalized to... not that
whatever the normal thing is (I forget)
Yea i’ll try. Its weird though because that’s how i have it in my other project
Does my script doesn’t look like it’s the problem right?
maybe also try reading the input in Update instead of Fixed?
Yea i tries that too, didnt do anything
silly question but did you enable the backends for the new input system in this project?
Edit -> Project Settings -> Player -> Active Input Handling is set to Input System (New)?
yes I did. I actually clicked the button that was supposed to to that automatically, but it wasn't done. I had to manually do it. Is it possible there was something else that was supposed to be enabled?
before I asked for help here and it restarted unity by itself
the only other thing I can think of is something with control schemes?
I don't really know how control schemes work and sometimes they trip things up
I deleted the control scheme and it still doesn't work
like im stuggling to understand why it wouldn't work if I have everything exactly the same as in my other unity project. Is it the version? I'm on unity version 2021.2.3 with input system v1.1.1
the other unity version was 2021.2.13
I wouldn't put "unity bug" out of the realm of possibility
maybe try upgrading the project to the latest LTS version
which coincidentally was released today: 2021.3.0
(after taking a backup or committing to version control)
I'll try converting to 2021.2.13 since I don't have to download that, and my other project works in 2021.2.13
it works in the newer unity version
I don't know if this is directly an issue with the input system, but I might as well ask here. I've got a function to shoot my gun, but sometimes at random times, when I click the gun will shoot infinitely (until it runs out of ammo or you press the mouse button again), and I've got so many checks to see if the mouse is really being pressed, I've got no idea here.
void Update()
{
if(Input.GetKey(KeyCode.Mouse0) && currentBullets > 0 && reloading == false)
{
if (Time.time - lastfired > 1 / fireRate && Input.GetKey(KeyCode.Mouse0))
{
lastfired = Time.time;
Shoot();
}
}
}
void Shoot()
{
if(Input.GetKey(KeyCode.Mouse0) && currentBullets > 0)
{
RaycastHit hit;
if(Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
StartCoroutine(bulletHole(hit));
}
shootSound.Play();
muzzleFlash.Play();
StartCoroutine(illuminate());
recoil_script.RecoilFire();
weaponHoldRecoil.RecoilFire();
currentBullets--;
shellParticles.Play();
}
}
share the full script?
found anything?
any solutions at all?
is it shooting like... very quickly?
Once a frame?
Or it's just continuing to shoot once a second until the ammo is gone
I've got it at 10 shots per second
oh right firerate
yeah that's what I mean
is it shooting 10 per second still
or it's shooting really fast, like once per frame
Basically I'm asking if your issue is that the game thinks you're just holding the mouse button down, or if the timing part of your script is not working
When it goes out of control, it's still going at 10 shots per second
Do you happen to have any extra mice attached to your computer?
bluetooth one maybe?
Nope, just the one
or maybe your mouse is dirty? 😛
Lmao maybe
I'm currently using a wireless mouse, I'll try plugging in my wired one.
yeah maybe try that
yeah
and turn the wireless one off so it doesn't interfere by accident
just tries the other mouse, same issue
do you happen to adjust timeScale in your code at any point?
maybe some kind of application focus issue in the editor?
Like it gets stuck held down and the program loses focus and it still thinks it's held down?
idk
I just did some debugging, and I found out that even when I'm not holding the mouse down, the game still thinks I'm holding the mouse down. I checked that with this script:
if(Input.GetKey(KeyCode.Mouse0))
{
Debug.Log("MouseDown");
}
else
{
Debug.Log("MouseUp");
}
try Input.GetMouseButton(0) instead does that change anything?
(it shouldn't)
do you have a touch screen btw?
Nah
I'll try that
I mean, there's no more infinite shooting but now my gun isn't automatic. The whole point of me using Input.GetKey(KeyCode.Mouse0) was to make the gun fire for as long as the mouse is being held down.
this is still using the old school way of input, checking for input in the update loop every time. You want to switch over to an input action event instead
Don't think I've used that before, could you show me an example?
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...
I said MouseButtonDown by accident. Changed it to GetMouseButton
this is the new way to do it. You'd create an input action in your PlayerControls() input action asset that fires off your performed event when held down
I don't think switching to the entirely different input system is really what is needed here
Just tried that as well, same thing
GetMouseButton works the same way as GetKey
it returns true as long as you hold it
As in, the same issue
The new input system just makes so much more sense to use once you get it down though
ah yes
sure but the issue this person has is either in their non-input-related code or their hardware
and it shores up the Update vs FixedUpdate input issues that have plagued beginners for forever
so switching input systems right now is not going to help them
hmm, sometimes I've had mice with a double click issue
logitech made some G502 series with crappier switches inside that I had to replace
My issue only seems to occur when I double click really fast
do you get double click issues any other time or just in this game
Pretty much my first time doing a gun system
see if you get a red banner when just clicking normally https://codepen.io/blink172/pen/vERyxK
I got a red banner
are you mashing the mouse or just clicking normally
Fast double click
it turns red for me if I mash it, but my mouse doesn't have a double click issue
My finger's doing that tho
Yeah, I think that's the same for me
I mash it with 2 fingers and I can get it to turn red
if you're getting it with one finger then your mouse might have that issue
With my gun, holding down the mouse button works normally, it's only when I mash the mouse button
by chance is it a logitech mouse?
I tried with 2 mouses, one is a logitech, but the one Im using right now isnt
you could try using an autoclicker on your game to test
take the hardware out of the equation
I'll try that
For reference I had to replace my logitech switches with Kailh GM 4.0 Mouse Switches. They were some other brand before
Omron's I think
I tried with the autoclicker, no issues from what I've seen
Hi i have an issue, my character (the tank) have not the same rotation speed when i switch the resolution (see the video)
i use this code (see screenshot 1) for rotate the tank
and the input actions of new input manager in the second screenshot
Someone know how i can solve that please ?
Is this code in Update? FixedUpdate?
The three first lines in Update() and the last one in FixedUpdate()
Hi guys. New here. Hoped to get some directions on how to solve the touch input problem I have. Have you played Townscaper? I a trying to implement a similar Camera controller. Touch/hold pan, but touch/release place an object. Currently when I touch the screen and hold I can pan but also I place an object 😦
So you... Photoshopped the image? Why not share your actual code
...... For better visibilty.
I show that for information but the problem is not here i think, the problem could be from New Input Manager, but not sure
does UI not work with touch in new input system? I can't press a button with my finger in my iOS build, and all my googling tells me others seem to be going back to standalone input
the best way to share your code when you want help is to show the code exactly as it is. Modifying it to "simplify" etc only sows confusion and potentially hides your issues. Show your actual code, ideally the whole script, in a paste site as per #854851968446365696
AFAIK it works fine.
PlayerInputActions _playerInputActions = new PlayerInputActions();
seems to not work
is this not the proper object name anymore?
That depends on what you named your generated C# class.
Nvm im just a little braindead
Happens to the best of us.
How would I got about something like: if space is pressed, do x? Google told me to use GetKeyDown, but apparently Input System Package doesn't work with that.
Suddenly my input module is listed as disabled in the input debugger? Why is this?
the component is enabled...
I think the getkeydown is for the old input system. For the new input system you have to listen to events such as if the key is pressed, performed, or canceled.
Figured it out - had to get a keyboard object and make a local var from it to than do a .getPressed() off of it
ima assume you are using the new system, if so, did you enable it via code on the OnEnable()?
The component? No, it’s enabled in the editor. I tried adding another component on a different object so I could receive player input which used to work but everything broke
Is there a way to add directives to the auto-generated class? I provide a prefab which supports both new and old input like so:
public class PlayerInput : MonoBehaviour {
#if (ENABLE_LEGACY_INPUT_MANAGER)
public FrameInput GatherInput() {
return new FrameInput...
}
#elif (ENABLE_INPUT_SYSTEM)
private PlayerInputActions _actions;
// omitted for brevity
public FrameInput GatherInput() {
return new FrameInput...
}
#endif
}
Which works fine, but people will still get a bunch of compile errors due to the auto generated script. I can uncheck it when exporting my package, but there's no guarantee I'll remember each time.
Ideally the generated class should contain these directives by default, right?
The video show the problem:
I was doing camera for third person game and i got into a bug when I move backwards (toward the camera position) the camera "sallow" the player
its to much code files for me to send in here So please DM as soon as possible
Everytime I press the "Jump" input it shows this error and i'm not sure how to fix it, the error information doesn't give me any guidance
I need the specify the generic value?
Hey all, I know there have been many conversations about this, but I don't see a concrete answer on forums or pinned in this chat. I am following https://forum.unity.com/threads/implement-a-mouse-drag-composite.807906/ on how to get drag functionality on the new input system. I have included the two scripts and set up the input map per example. I am getting "Started" on any click "Performed" on click release and "Cancelled" twice after pointer move after any click is performed. I am not sure if that's the best we have currently, but I would expect "started" to only fire when click held + movement occurs. "Performed" to occur continuously while held and moving, and "cancelled" once click is released.
It does work in between the early firing and double cancel, but I would have to play Boolean gymnastics to sort out am I actually in a drag state or not
does anyone know the layout for a retroflaf snes controller
Are you the real Tarodev? Lol
Hi, i'm learning how to make an fps with unity's Microgame FPS tutorial, and i noticed that they basically use the old input system, if i want to advance in the game (especially just add a splitscreen), is it better to keep the old one or try to redo a new project with the new one ? (or its just a matter of taste? ahah) thanks
a conversion would probably be better in the long run for added compatibly , the Legacy Input works just fine with gamepads though, if local multiplayer is your thing , you can always use both and transition when you are comfortable with the new system
Ok thanks !
Is there a way to use the input system manager to implement an onEnter and onExit function for a specific buttom?
I wanna make it so that an action will be performed as long as a button is being pressed down
Use a script with IPointerDownHandler/ IPointerUpHandler or an Event Trigger component with those same events
Or wait are you talking UI button
Or input button
input button
That would be me, yes
whoa its Taro lets go!
anyone have a guide on setting up analog movement on gamepad?
► ANIMATIONS
https://drive.google.com/drive/folders/1j2HicZMabg4h2Oe8ocxGNuKBHY5kzFJA?usp=sharing
► PLAYER MODEL
https://drive.google.com/drive/folders/1X6DLqSsLT2EAIYpcZGYL-Z93hYOo2sxa?usp=sharing
► EPISODE TWO
https://youtu.be/c1FYp1oOFIs
► SUPPORT ME ON PATREON!
http://www.patreon.com/SebastianGraves
► ASSET STORE PAGE (Animations & Model...
At around 4:11 it has something similar to that
Though the green header thing will need to have the pass through vector 2 for the analog to work right
thanks
there is no stick deadzone option in this version of unity i just downloaded
was it moved somewhere else
That’s strange, I have no clue
Only know this much since I saw this video like yesterday by chance
can anyone help please i have two sound devices and look to make my game to pick up which one i want it uses anyone know or point me in to the right place on how to do this please
What's the best way to convert the RebindActionUI component's text components to TMP_Pro components?
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Samples.RebindUI.RebindActionUI.html
hey does anyone know how i would get the exact position of the mouse?
i believe it has something to do with how i set up my input action map
i'm using the new input system package i believe
version 1.3.0
Just make an input action bound to Pointer Position or Mouse Position
^ your input action also has to be of Value or Pass Through (any) and not Button
whenever i try printing it, it just prints out (0.0, 0.0)
That's the Delta, not Position
Delta = pixel change from last frame
Yeah, and a new screenshot of your current input action
you bound it to delta
and why are you using PassThrough
should i be using value instead?
value/vector2
in the awake func?
for now yeah sure
none of the tutorials said to do this lmao
hey im using the new input system. i restarted my computer and now my mouse polling rate is really low, but only in game? My game isnt lagging, and my mouse works fine otherwise. I looked in the input debugger and yeah, mouse events only come in every second or two in play mode
they definitely all do 😛
this is very bizarre
restart computer/unity again?
i did restart unity, let me try my computer though
would i have to disable it on exit to prevent a memory leak
That's not... how memory leaks work
so no?
There are good reasons to disable it at certain times but doing so is not related to preventing memory leaks
nope!
figured this out!
Hey guys, I'm using Input System 1.3. Any idea why this is happening?
- Give gamepad input
- Give keyboard input
- Player Input > Events > UI > Point (CallbackContext) gets triggered
It's almost as if keyboard & mouse is seen as one device, so switching to keyboard triggers the mouse to fire a point event. I couldn't find a way to distinguish between this and a true point event.
Hello! Im changing my codebase to the new input system, but im stuck on this...
if (weapon.isAutomatic) shooting = Input.GetMouseButton(0); //hold
else shooting = Input.GetMouseButtonDown(0); //tap``` how would i change this to the new input system?
```cs
public void OnFire(InputAction.CallbackContext context)
{
}```
The way you "ideally" should use the input system is fundamentally different to how you're using the old one in the example there
A quick and dirty equivalent though would be to use Mouse.current.leftButton.isPressed/Mouse.current.leftButton.wasPressedThisFrame
yeah that would be quick and dirty indeed
probably have two different actions for Hold and Tap interactions right?
It definitely works as a quick "I want to port this to the input system", but ultimately you would want to use interactions yeah
and then ReadValue triggered or some shit
yeah so
public void OnFireHold(InputAction.CallbackContext context)
{
}
public void OnFireTap(InputAction.CallbackContext context)
{
}```
i don't think you even need the methods tbh
just thing.triggered contains the bool
true
all my other actions are a method, plugged into the inspector
try ```cs
shooting = YadaYada.FireTap.triggered;
hm
i think it'll make more sense to keep to the system
i guess
especially if i come back after a break or sommit
yeah makes sense
public void OnFireHold(InputAction.CallbackContext context)
{
PlayerStats.Instance.weaponStats.ShootButtonType = context.interaction.Equals("Hold");
}
public void OnFireTap(InputAction.CallbackContext context)
{
PlayerStats.Instance.weaponStats.ShootButtonType = context.interaction.Equals("Tap");
}``` im confident this isnt correct
yea no, this is wrong
if (weapon.isAutomatic) shooting = Input.GetMouseButton(0); //hold
else shooting = Input.GetMouseButtonDown(0); //tap``` i only need to change the right-hand assignment of this right
i'd just do this...
OnFire(CllbackContext ctx) {
if (ctx.started) {
shooting = true;
}
else if (ctx.canceled) {
shooting = false;
}
}
void Update() {
if (shooting && isReadyToFire()) {
if (!weapon.isAutomatic) shooting = false;
Shoot();
}
}```
something like this