#🖱️┃input-system
1 messages · Page 50 of 1
same code works in MonoBehavior
I assume that has something to do with subscenes. I havent used it in subscenes before
Hello Community, so i make the UI button in unity so i use script like this to prevent the input mouse pass trough UI button,It's work in Editor but not after i build it in Android device, i am using Unity 2019.4
how to make it work same as after build especially on mobile
Why are you calling OnDragStart and OnDragEnd manually
the event system will call it for you
and if you use the event system properly there's no need for code like this
I have been trying to use the interfaces generated but isn't there a solution where you implement only what you want ? i could just use SendMessage() but its slow
UnityEvents are the easiest way to get the most out of the input system
It's for mods i can't use the editor i think its best if i use interfaces on the behaviour but it would be great if you didn't have to implement the whole inputmap in the script..
alrighty.. so... is there a singular Input statement that handles both get key up and key down? I'm trying to make it so an object's scale is transformed ONLY when the button is pressed... do i need to have two statements for that? I hope there's a way to only transform it when there's the button being pressed ;-; right now, I've got
if (Input.GetKeyDown(KeyCode.LeftShift))
{
transform.localScale = new Vector3(1, .5f, 1);
}
But i want it to return to the normal size when it's done being pressed...
(for a crouch feature obviously)
you mean like, you want it to execute while the key is being pressed or when it gets pressed or released
I just started using unity and whenever I type input into my code It doesn't highlight it for give me options
because it's called Input not input
programming languages care about whether something is uppercase or lowercase
you sure?
mhm
only while.
then you want Input.GetKey
I tried that but it's not resetting the scale :,>
well is there any other place where you're setting the scale than that if statement
ok
no place where I'm resetting it 😦 I'm just pretty sure in pygame (python's 2d module) i didn't have to reset it, it only transformed when i pushed the button, and no other reset was necessary. I was just wondering if there's a way to do it like more efficiently 😦
well this ain't pygame
you can do something like ```cs
if (Input.GetKeyDown(KeyCode.LeftShift)) {
transform.localScale = new Vector3(1f, 0.5f, 1f);
}
if (Input.GetKeyUp(KeyCode.LeftShift)) {
transform.localScale = new Vector3(1f, 1f /* or whatever it normally is*/, 1f);
}
Yeah lol ugh that's annoying, that's what i figured i had to do but it just seems inefficient is all, thanks. 😛
np there's nothing inefficient about it
it's just two if statements
can't get much more efficient
yeah but it would just constantly be checking for a keyup too even if there's no keydown being pressed
I sure hope so lol
I am having some weird issues. Can I have multiple of player input on certain part of UI screen? E.g. a Main Menu has it's own Player Input, but when you join the "Campaign" menu UI (Just main menu game object active is false and the Campaign gameobject active to true)
any ideas why my button will click the first time, but not the second if i dont move my mouse? im ussing the new system and simalting touchsreen
I'm a newbie to input system, followed about 6 tutorials, and found my console is spammed with :
InvalidOperationException: Cannot read value of type 'Vector2' from control '/DualShock4GamepadHID/leftStick/left' bound to action 'Gameplay/SteerL[/DualShock4GamepadHID/leftStick/left,/XInputControllerWindows/leftStick/left]' (control is a 'ButtonControl' with value type 'float')
I have no real idea what it's trying to tell me, my setup looks like this:
Maybe you're reading your action incorrectly? I guess you're reading it through ReadValue<Vector2>(), but it looks like a button
its a value vector2 yeah
I don't get why it would think it's a button, its the leftstick input
It says leftStick/left, not just leftStick
hmm, i figured leftstick/left meant pushing the left stick.. left lol
I think you might have added an action which by default is of Button type, then added binding leftStick/left and then changed the action type to be Value of Vector2
Be careful there 😉
yes I think you're right, when i added it again it changed the type looks correct now
but I had to delete/re-add, not just change it
I think I can just change it to "steer" and extract the left/right vector from that now, thanks, rubber duck
Can you confirm what "Control Type" i need to be using for an analog trigger, for throttle? trying Analog
Yeah I guess, haven't used it yet though
hmm right trigger brings this up (dunno what it is). I'll go do some investigating 😄
I have it set to get a message in console when I start the game and press space but I get nothing at all
If you add some Debug.Log outside of if, do you see it printed?
Debug.Log("Some message");
if ...
Then make sure your script is attached to some GameObject in the scene
the docs say MonoBehaviour.OnMouseDown() works on a Collider or GUIElement... but then says GUIElement is obsolete and removed 
how do you get a mouse click on non-colliders then..?
OnMouseDown is quite outdated
you should be using the IPointerDownHandler interface from Unity's event system
I just had a friend install my mobile game on their Samsung S21 standard model, and none of the UI button click events are working at all. I've tried multiple apks to troubleshoot, but not getting anywhere at all. The buttons are showing perfectly scaled, but the click is just not triggering for him on the S21. I've had over 100 downloads and no one has complained about any other model too, and this also works great on the phones I've personally tested. My app is built in Unity Version 2019.2.18f1 (prior to LWRP) and I've been using the new input system for over a year now (which I've been using version 1.0.0 but today I tried updating to 1.0.3 to see if that would help on the S21 but it's still having issues). I'm really stumped on what could be the issue here, and was wondering if anyone has faced a similar issue at all, or has any thoughts on what I could try to do to fix this? I was thinking it was a scaling issue perhaps, but it doesn't seem like this is the case as everything looks aligned correctly on the menu. If it helps too, I'm just using the straight up OnClick() events and my event system seems set up right as it works fine for other Android devices.
Thank you, @austere grotto. I'll post over there.
so.. I tried this out today and followed an example from the docs but I can't seem to get to it work
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/EventSystems.IPointerDownHandler.html
I have the exact same code as the example with my own class name, the Start method is definitely called, but the OnPointerUp and OnPointerDown don't get called
I tried with a collider and without, but nothing works
what did I forget to use?
ah, I think it requires to be used on a UI object... no idea how to do that yet
you need physicsraycaster on your camera to get event system events on 3d objects
ProGrid cant be installed in package manager, but i need it to help snap things onto spaces like here
can someone help? I would like to be exakt on the lines
I'm trying to bind the right analog trigger for throttle in my game, but It brings up this HDRPGraph, with no apparent way to disable it?
This is with a PS5 controller, Any solutions?
can or cant?
its a preview package
if you cant see it you have to enable preview packages in the Project settings
@teal ravine there isnt a toggle for that in hdrp asset etc? Also do you get that in release build? I think it should only exist in dev builds (unless you use some older version)
Hey, same issue here. Dualsense support got delayed and it’s not there in 1.1. So, most of the buttons on controller are mapped totally wrong and not even close to dualshock 4 sadly. They are testing it though.
I looked up the git URL and typed it out there. I dont know how to enable preview packeges..
Edit > Project Settings > Package Manager > Enable Pre-release Packages
Ye i found it. Tx
So when I start the game from the menu screen scene I get a problem with the mouse where it goes outside of the gamescreen and keeps rotating - which makes it very hard to move. If I start it in the gamescene i click onto the game and the mouse keeps inside the game window.
The dialogue system I added doesnt work either and I have a feeling its because of the mouse input problems
@timber robin hey, i dont know if you remember, but i asked here before if someone knew how to detect if a controller/gamepad had been switched on or plugged in, and you replied with an answer.
Sorry, I interact with a lot of people, so I don't. But if you say it's so, then it's so. 😆
it is, and i greatly appreciate your help. i was just wondering if you have any further knowledge or experience rigging that function up with code? 🙂
I've actually never used it. It was just something I remembered reading.
And I can't try it right now, I'm currently in the middle of a game jam. Lol.
no worries m8. thanx for replying thou. ill see what i can find out. thou its very scarce with info on how to code it.
The new input system is a bit vague in that regard, yeah. Plus multiple implementations as well.
yeah. bit of a mess on how to implement the code they have on display to use.
From what I've read the PS5 controller simply doesn't have support, the reason is that the right triggers are firing multiple button events so eventually it hits the shortcut for HDRP
I just had to buy ANOTHER controller this week, an xbox one
Yea that’s what I said. I saw the github commit where they are testing it yesterday, seems like it will come out in next update.
help
update -> Update
ohh tnx
set up your IDE using the relevant configuration link in #854851968446365696
This fixed it
already did that
clearly not since it's not configured
I have a 2D-Vector, and it's not resetting to 0.0,0.0 when not pressed
Which is strange because I have an identical one that works that way
how are you reading the values
I'm not 100% sure but I think that style only gets the performed callbacks
which don't include the reset to 0
just one of many reasons PlayerInput sucks
hmm
oops
do i have to save it because i did that last night
did you restart VS since doing it? monobehaviour will be green and it will say Assembly-CSharp where it currently says Miscellaneous Files
yeah that's how we can tell it isn't currently configured
so its fine now 👍
not if it still looks like the screenshot you just showed
still not configured
notice how it still says "Miscellaneous Files" and how MonoBehaviour isn't green? those are both indicators that it is not configured
if you have gone through the steps to configure it, then fully close visual studio and open it by double clicking a script within the unity editor
then go to #854851968446365696 and find the IDE Configuration section, click on the relevant link and follow all of the instructions in that link
great! completely restart visual studio
appreciate your time and effort finally
Hey, i need to get the last pressed key, because pressing A then B (or A and B but A first) should produce an action. I cannot really store the last key pressed because i use events. Is there another way ?
why do events preclude you from storing the last key pressed?
because it looks like this
and i dont want to go to each functon i call to chage a global variable somewhere
you don't have to make your event listeners one-liners
you can do whatever you want in them
i can write
controls.TopDownControls.Move.performed += _ => cam_controller.move = _.ReadValue<Vector2>() || lastPressed = 'up';
you mean ?
not really, that code makes no sense
you can write multiline lambdas though
or just use a real method
controls.TopDownControls.Move.performed += WhenMoveHappens;
void WhenMoveHappens(InputAction.CallbackContext c) {
cam_controller.move = _.ReadValue<Vector2>();
lastPressed = "up";
}```
though that code doesn't make a ton of sense either tbh
are you trying to do like a mortal kombat style "move" system
i guess i'll just do something like :
controls.TopDownControls.Move.performed += _ => cam_controller.move = _.ReadValue<Vector2>();
controls.TopDownControls.Move.performed += _ => lastPressed = "up"
it's a RTS system like starcraft, where you can select a unit and do A then click to attack, or R then click to patrol etc...
now that i think about it i only have to keep the info for the chosen keys, and for any other key pressed set it to null or something using input.anykey or it's equivalent in the new system
what do you need to remember last pressed key for for this?
I would think that pressing A for example just puts you into a different mode
where you can then just choose where to attack
what you need is a simple state machine more or less where you have modes like:
Idle
Attack Placement
Patrol Placement
etc.
because if you have a unit selected && you press A && you left click, it attacks, but
if you have a unit selected && press P && left click, it does nothing
right - state machine
which i guess you're kinda doing a light version of with your "lastPressed"
but I'd formalize it a bit more and make it not directly related to the input so much
Looks like you are trying to read a float while the input is setup to be Vector2
Yea seems fine. The code part is what is most likely wrong
Visual Scripting, not really.
Any way to reach the team working on Input System?
Your best bet is here I guess or through a bug report
This bug has been here since the beginning of Input System, which makes Input System completely unusable if you need to query touches manually (eg genres like rhythm games).
I've tested it with the latest build today and confirmed the bug still exists.
The issue is already been reported for over 1.5 years and no sign of it being fixed.
https://issuetracker.unity3d.com/issues/inputsystem-android-touch-dot-isinprogress-gets-stuck-when-multiple-touches-are-applied-to-touchscreen-quickly
Did you try to manually check against with their phase status, are they keep being stationary? @crisp smelt
Yes, they are all stuck on being stationary
you could just try to manually set them at the end of the script to cancelled and see what happens in the next frame, it should only update the once that are still active
How would I do that?
For some context I did not file the issue, but I can see it happening by just showing InputSystem.EnhancedTouch.Touch.activeTouches, and that's a read only array.
Oh you cant set touches manually, dang. Hm, let me think
Some threads say its a phone thing, not a unity issue. hm
Well, it certainly doesn't happen with Input Manager
If the touches are misreported by the hardware then it would happen to both.
If it was that easy 😉 So the legacy input manager is working, yes?
Yes.
It's as simple as printing out InputSystem.EnhancedTouch.Touch.activeTouches vs Input.touches
You can see ghost touches getting stuck with Input System which doesn't happen with old Input Manager, on the same device.
Not even specific to just my device, many people tested and confirmed it.
I totally believe you there, was just quoting the threads as a second thought. Well not sure if there is a way to manually force the inputsystem to update.
Do you need the stationary phase for your app right now? If not, I would hack myself around it until its fixed or someone else fixes it.
I do yeah, rhythm games do need to detect touches that are held down (but not necessarily moving)
If it's just for detecting taps/releases then that would be completely fine.
Okay, thats an issue. hm
I mean you rbug report side says "Fix In Review", so maybe
Maybe 🤞
It's unfortunate because for rhythm games, it's critical to get the precise timing of player input so you can judge them fairly (hardcore rhythm game players can 100% tell) which Input Manager doesn't do
🤞 for you, it will get fixed soon. I voted for it at least, as this is some serious thing not just in games but multitouch screens for exhibitions and stuff.
Just wondering, could you just use began and cancelled to check instead of stationary?
I actually don't know for those ghost touches that get stuck on stationary, if a cancel event was ever fired.
I suppose if it does get fired, I could manage my own list of touches with that.
Hard to suggest anything without knowing your game, but you could try to bypass stationary and just use began and cancelled (which might not get fired on the ghost touches) to see, if the player started and ended at the right time instead of check holding with stationary.
Actually now that I can recall, cancel definitely isn't fired.
An action player is required to complete is to tap, follow, release in one continuous motion
People have reported that the release isn't being recognized which is what led me to finding this bug.
So from all the game can tell by querying active touches, player just holds the touch there permanently.
So cancelled is fired only on the "real" touches, so you coul duse them?
But you can't tell
If a touch has started, then stay stationary for rest of the game, you can't tell if the player is actually doing exactly that, or it's a bugged touch that isn't being cleared.
So its there forever?
Yep.
This is a photo someone sent me earlier
It's reporting 10 active stationary touches, and well, you certainly can't see 10 fingers.
Yeah thats weird. We will have to wait for the fix I guess
Did you look into enhancedtouches? @crisp smelt https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.html
Yep, the bug is with InputSystem.EnhancedTouch.Touch.activeTouches.
ohh, woops, missed that
I think the higher level APIs (directly sending events in response to inputs etc) are fine with Input System
Or at least I haven't heard people screaming about it.
How do I switch the enabled action map when a button is pressed.
I have a menu that you hold the input to keep open. So I want to switch from my "Gameplay" action map to my "UI" map when the button is performed, and then back when it is canceled.
This is a simple example I made of it. This freezes Unity though.
private GameInput input;
void Start()
{
input = new GameInput();
input.Gameplay.Enable();
input.Gameplay.Inventory.performed += OpenInventory;
input.UI.Inventory.canceled += CloseInventory;
}
public void OpenInventory(InputAction.CallbackContext ctx)
{
input.Gameplay.Disable();
input.UI.Enable();
}
public void CloseInventory(InputAction.CallbackContext ctx)
{
input.Gameplay.Enable();
input.UI.Disable();
}
the problem is that if you enable an action map it will immediately fire the events if the control is actuated
so it's inifitely swapping back and forth
I'd probably put this action (toggling the UI) into a third action map that is always enabled
OH, I figured it was some sort of infinite loop, but couldn't figure out where. But it shouldn't call the canceled event if the button is still down right...
oh hmmm 🤔
I put Debug.Log in both and added an auto return at the top after it had been called x number of times. Only the cancel event for the UI map was called, the performed for the Gameplay map was only called once at the start...
I just made a new map "GameplayAndUI" for it. Feels a bit ugly, but it works really well so... ehh.
is there a way to continuously poll the analog sticks, such that it always has the latest value? currently with the new input system, if i move the stick fast it only reads a few values and doesn't capture the last position of the stick (completely left)
ReadValue<Vector2>() inside of an Update method.
Hello. I'm having trouble with the input system package. I have everything hooked up the way I need it, and everything in my script is correct. I've set up an interact key and I'm able to interact with my 3D environment with it. However, somehow the key is getting pressed three times when I only press it once. I know this because the console within the editor is outputting three different messages. Does anyone know the fix to this? (Haven't found a resource online that helps). Here's my Interact method just in case. I've also included my input actions map.
public void Interact(InputAction.CallbackContext input)
{
cameraPos = Camera.main.transform.position;
rayDirection = Camera.main.transform.forward;
if (Physics.Raycast(cameraPos, rayDirection, out vision, rayLength))
{
if (vision.collider.CompareTag("Tree"))
{
vision.collider.gameObject.SetActive(false);
Debug.Log("You chopped a tree!");
}
}
else { Debug.Log("You can't interact with anything here."); }
}
Are you adding the method to the event multiple times?
No, I've only added it once.
You're talking about this, right?
Does that then make code like
private void OnThrottle(InputAction.CallbackContext context) { ... }
pointless if I need to manually poll it anyway to get the proper values?
Yup. (The cs goes after the 3 ticks with no space and the code is on the next line)
i spent an hour moving all my input code from the update method into event driven like that, now I have to move it all back 😄
oh wait, it needs to use event driven for regular buttons
Yeah, I wasn't sure what system you were using. Try simplifying to get it to work properly, then go back and change it to get it to work how you want.
Why? You should only need things that use the mouse or joystick. Also, you could probably reorganize your code so that it isn't as hard.
I just followed a tutorial which hooked up the .performed events to handlers in my class, before I noticed the issue with having to poll it
use an input action reference and bind to it instead. it's hard to say why this is freezing
you can read the values in an update
use an inputactionreference to get something in the inspector you can use to specify what you need
for example, a vector2 or whatever
public class MyBehavior : MonoBehaviour
{
// This can be edited in the inspector to either reference an existing
// action or to define an action directly on the component.
public InputActionProperty myAction;
}
Got it now, thank you
Hi, does anyone know why when saving any script with the Input System in the project, it completely errors out the input system and makes it unusable untill i replay the scene?
Because recompiling while in play mode is going to cause issues for play mode. You can configure unity to exit play mode to recompile
Gotta provide more info than that, mate. Maybe share the movement and input code.
thats annoying, the old input system works just fine when saving during playmode
other than that the new input system is awesome
It's not an issue with the input system, you recompile so the script is likely losing its references. It will happen to non-input related scripts as well
#854851968446365696 will tell you how. It also tells you what kind of info to include in questions, as well as some other useful stuff
It will
That's not even related to the Input System. You should probably ask for help in #💻┃code-beginner
Also for future reference, you can find the relevant channel to use in #🔎┃find-a-channel
Thanks for this pointer, my game falling apart during a recompile was so annoying 🙂
I'm using default events, does the EventSystem component even do anything then? I wanted to switch to IPointerClickHandler as MouseDown reacts even if it's below the Canvas UI. Do I have to switch the Input System?
the event system is a completely separate beast from either input system
not sure what you mean by "default events"
there is an input system that you do not need to install via package manager and one you need to install. I was wondering if IPointerClickHandler only works with one of them
my input worked with MouseDown on Monobehaviour, but it was getting events through the Canvas. I read that IPointerClickHandler solves this, but now I don't get any events at all.
Event system / IPointerClickHandler works with both input systems
OnMouseDown only works with the old one as far as I know
ok... hm I've switched to the new input system. but I guess I am missing something else for this to work
If you're trying to use IPointerClickHandler on a 3D/2D game world object you will need a few things to make it work
as it was supposed to work in both
- Event System in the scene, also with an Input Module component on it (the correct one for your input system)
- PhysicsRaycaster on your camera
- Collider on the object
- Script with IPointerClickHandler interface on the object
oh, I think it might be physics raycaster. I dont have it on all cameras
yes that was it. damn
thank you
I guess you need it on the camera that renders what you want to click
I only had one on the UI not on the game visuals
First time using any type of input system. How would I call these input buttons? The second image shows the code I have but it says Keyboard does not contain a definition for 'Move'.
I have changed my code to this and it works, however it just detects the key specified and not the key from the input system I set up.
Have you visited docs? 🙂
Yes, currently you don't use actions you've set up, but the actual keys
I tried looking at docs but from what I could find everything refers to using this way of getting input which I find somewhat confusing.
I liked being able to say if (Input.GetKey(KeyCode.W)); But I can't do that with the input system. A video showed the method I did before and I want to do something like that/like the Input.GetKey but instead of KeyCode.W or wKey I want to refer to the specific bind I made.
Is there a way to do that other than the image I just posted?
i recommend checking out some tutorials about getting input using events with the input system. there's also the quick start guide from unity that you can take a look
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/QuickStartGuide.html#getting-input-indirectly-through-an-input-action
the old non-event based input system was convenient for getting up and going quickly. However, an event driven system has a number of benefits and the setup isn't bad once you are familiar with it.
You can too still do this. Keyboard.current[Key.A].wasPressedThisFrame
anyone ever use a gamecube to usb adapter with unity? cant seem to get the Y axis for the c-stick or dpad
Can the new input action support multiplayer in PUN 2 or Fusion?
Yeah but that still means I am looking for the key A. I want to call the input keybind I made because I want to allow players to change keybinds.
Personally I feel like the input system is too complex for just calling the keybinds. This is 100% my opinion but for now I think I am just going to make my own input system script with variables for example string moveForward = "w" and then just use Input.GetKey(moveForward).
That feels so much simpler than what the input system makes me do. Unless there is a way for something like that but I missed it but it seems to me like there isn't.
You can
1.1prev has proper extensions for it, but you can watch.... Lemme get link
Hope some of those help :)
Ok, will have a look. Thanks for the link.
There's a bunch of reasons to migrate upward, but it's a bit of a learning curve
I made those tutorials after struggling thru migrating, so they're all in that context.
Ok
I'm using the new input system and I would like to disable the "onMove()" callback based on a condition
I know I can prob do something like this:
moveAction.performed -= OnMove;
But how do I get access to the moveAction?
found it 😄
they are completely orthogonal concerns, so yes.
Can we please get support for Unity remote 5 🙏
what do you expect cs Destroy(obj, 0, 5f); to do? what is the 0 meant to do?
also why is this in input system
you're not even using anything related to input 🤔
It’s supposed to be 0.5f
ok so, did you fix that
Yes
and it works i assume
No
in what way does it not
np ig
I have a listener here that's waiting for a .performed
{
playerControls.Movement.Moveandlook.performed += move;
}```
Is there any callback that's continuous? This is to move a player, so currently every when you hold W it moves slightly and stops. I'm trying to avoid populating Update
most straightforward thing is to poll the inputaction in Update.
performed will get called every time the actuation of the control changes though (and remains nonzero)
yeah I just stuck it all in update in the end
how are you reading it?
under normal circumstances it will give you a value between 0 and 1
not sure what you mean
with my eyes lol
input system i assume
im setting up a gamecube controller in unity
I'm not a mind reader
I'm not sure the GameCube controller is really going to be fully supported by Unity (or anything except a nintendo console), so let's start off with - you might not be able to get this working without some custom hardware
and you're reading it how?
its through zadig
WIth Input.GetAxis?
yes
what is zadig?
a driver that converts the gamecube to usb to a typical windows controller
at least i believe thats what it does
could be wrong
but either way, the controller can operate just fine with analog input in dolphin for example
not really sure - at this point you're dealing with a bunch of unsupported software and hardware 🤔
Is this a project just for yourself?
sorta yeah
just wanted to see if i could get it in the game im making
i guess ill see if i can find a way to get it through code
you might need some kinda native windows plugin to get this working
is there a way of setting up the circled input as digital while keeping the others as analogue?
can anyone tell me how i can get the mouse screen position using the new input system ? Mouse.current.position returns a Vector2Control instead of a Vector2, and i have no idea how to extract coordinates out of this
ok i got it it's Mouse.current.position.ReadValue();
make it a separate InputAction
I tried that but unfortunately it can't call both inputs simultaneously. In this case (tank controls), you'd have to stop walking forwards to turn, as 'stick left' and 'stick right' are in the other input. So when you hold the diagonal, whichever input triggers first is the only input until you reset the stick to 0,0
why can't it use both input simultaneously? Sounds like a limitation of your code not the input system
I'm not sure. It could because it's not liking 2 simultaneous inputs for a Vector2?
The full process is I read the vector2 from 'moveandlook' in the input system, then SmoothDamp it, and extract .y and .x for forwards/back and look left, look right.
// Get movement inputs, smooth input, reset previous movement
movementInput = playerControls.Movement.Moveandlook.ReadValue<Vector2>();
currentInputVector = Vector2.SmoothDamp(currentInputVector, movementInput, ref smoothInputVelocity, 0.2f);
if(movementInput.y == 0)
{
currentInputVector = new Vector2(0,0);
}
runningInput = playerControls.Movement.Running.ReadValue<float>();
// Convert V2 input into floats
verticalInput = currentInputVector.y;
horizontalInput = movementInput.x;
// Set speed and direction
curSpeed = moveSpeed * verticalInput;
Vector3 z = transform.TransformDirection(Vector3.forward);
Anyone know how to replace Input.GetMouseButtonDown/GetMouseButton with the new input system?
create an InputAction bound to the mouse button and use action.WasPressedThisFrame() and action.IsPressed() on it (assuming oyu're on Input System v 1.1 + )
how do I install 1.1+? Im stuck on 1.0.2
from the package manager. it might not be available in your current version of unity
if you don't have it then you can use
action.phase == InputActionPhase.Started``` and ```cs
action.ReadValue<float>() != 0``` instead
im on 2021.1.21
then it should be available in the package manager afaik
I just uninstalled 1.0.2, maybe it will come up now
or maybe it's only for 2021.2+ idk exactly
either way you can use those alternatives
alright thank you
yup this was the problem, I installed 2021.2 and it is showing up now
thanks
var mouseX = Pointer.current.position.x.ReadValue();
var mouseY = Pointer.current.position.y.ReadValue();
// Mathf.Clamp(-mouseY, -lookXLimit, lookXLimit)
_cam.transform.localEulerAngles = new Vector3(-mouseY, 0, 0);
transform.rotation = Quaternion.Euler(0, mouseX * lookSpeed, 0);```
should i change this to use the actions stuff
im having an issue where if i lock the cursor and set it to hidden then im not able to move the mouse
but if i dont lock it moving the mouse causes it to go offscreen
yes because you are using the position, which doesn't change when locked
what should i use
bind an input action to pointer/mouse delta
and read the value of that each frame
yes. but you have to increment a seperate variable if you want to use it with Quaternion.Euler()
yes - i'm suggesting a 1:1 replacement for the current thing he's doing with Pointer.current.position.ReadValue()
im used to the old input system so this is new to me
the new one is definitely so much better 👍 you'll get used to it quick
so i add the Player Input component to my player prefab?
i would suggest using the InputActionAsset itself rather than the playerinput component
@sinful turtle
how?
have you created any input action asset?
yes
ok, go to it, and in the inspector click 'generate c# script'
ok
when you have, in the script you have, add a private <<GeneratedScriptClass>> _controls;
done
in OnEnable() put _conrols = new <<GeneratedScriptClass>>() and then _controls.Enable(); and in OnDisable() put _controls.Disable();
actually put _controls = new <<GeneratedScriptClass>>() in Awake()
wait
im using mirror for networking
i think it would be better to go in OnStartLocalPlayer
probably. although i have no experience with mirror. but put it somewhere where it get's called when the script is being 'Activated' and 'Deactivated'
ok, so have you created an actionmap in the asset itself and added some controls?
ye
ok, then in your code you can write: _controls.<<ActionMap>>.<<InputBinding>>.ReadValue()
ok so i think i got it all working
yeah?
one thing
var mouseDelta = Pointer.current.delta.ReadValue() * (Time.deltaTime * mouseSensitivity);
_mouseX += mouseDelta.x;
_cam.transform.localEulerAngles += new Vector3(Mathf.Clamp(-mouseDelta.y, -lookXLimit, lookXLimit), 0, 0);
transform.rotation = Quaternion.Euler(0, _mouseX, 0);```
i have this, which kinda works but sometimes the camera can rotate past the max or min
ok, why are you using the Pointer class now? XD
o
i forgot to change that
var mouseDelta = _controls.Player.Look.ReadValue<Vector2>() * (Time.deltaTime * mouseSensitivity);
looking up towards the limit causes it to start shaking the screen
it's probably because you are adding to localEulerAngles
you should clamp localEulerAngles, not the vector you add to it
oh
90% sure that's what's wrong
guys,why are the axis a float?
it gets an axis from the input manager
and the axis is between -1 and 1
although an exception is the mouse
?
it's value will be the mouse delta multiplied by the axis's sensitivity
so it just gives negative and possitive numbers for that specific axis?
ye
for example that Horizontal axis
it will be 1 if you press D and -1 if you press A
and 0 if you're pressing neither or both
i heard there is a newer input system?
idk if that's true or something
what is it?
you can install it through the package manager, it's called "Input System" but i'd recommend you to use the old one
the benefit of using the new input system is that it is much more customizable
is it ```if (Input.GetKeyDown(KeyCode.Space))
{
something happens;
}```?
that's the old input system
in the new input system you'd have some input map and then you'd do for example ```cs
controls = new Controls();
controls.Enable();
controls.Main.Jump.performed += _ => {
//something happens
};
although there are many other ways in the new input system
I'm migrating my mobile UI touch controls to start using the new input system. The way I have my non-mobile controls set up is with the new input system, and instead of using the generated code, it's using the Player Input script to send Unity events to my custom playermovement script. An example of my 1d axis horizontal movement binding script:
public void OnHorizontal(InputAction.CallbackContext context) { horizontalMove = context.ReadValue<float>(); }
The On-Screen Button scripts seem to work perfectly for most of my mobile buttons, but I'm using the On-Screen Stick script for my joystick and it is not allowing me to move it around unless I uncheck the Auto-Switch boolean option in the Player Input script before runtime. I have to have this checked for my non-mobile release though in the case the player is switching from a keyboard to a gamepad controller at runtime. And also setting playerInput.neverAutoSwitchControlSchemes = true; at awake if it's mobile is not allowing me to move the joystick either. It has to be unchecked before runtime. Was wondering if someone can help me out with getting this joystick to work with autoswitch still enabled on my PlayerInput script.
Unity version is 2020.3.18f1
New Input System is 1.1.1
And this is what my Player Input script looks like with the event call and Auto-Switch on.
Update: just generating the scripts from my input action and using a new instance of that in my script seems to have fixed it. I guess I won't question the other approach I was doing before.
I'm using the new unity input system and I cannot pass the input system generated C# class as a reference to another script through the inspector. For some reason, the public field "controls" is not visible. I tried forcing a serialization, but it did not solve the issue.
public class Player : MonoBehaviour
{
public InputMaster controls;
private void Awake()
{
controls.Player.Shoot.performed += context => Shoot();
}
private void Shoot()
{
Debug.Log("Test");
}
private void OnEnable() { controls.Enable(); }
private void OnDisable() { controls.Disable(); }
}
And InputMaster is your generated c# class name right ? @brave barn
You haven't created an instance of controls
It is not serializable and will not show up in the inspector
That's not how the generated class works
You create one with new InputMaster()
Has the way this is handled changed in recent versions of Unity? I'm pretty sure it didn't require me to instanciate last time I used the new input system.
Yes
Alright, I got it to work by instantiating it in the awake.
Hi everyone.
Been trying (real hard) to get a mouse press (button down) fire an event. For some reason the callback gets fired both on mouse press and release. What is the correct setup for this? I couldn't find a specific example nor could I get it to work by trial and error. Thanks!
New input system BTW, if that was not clear
I cannot get rid of 'The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) [Assembly-CSharp]' I have rebuilt proj files (after deleting them) making sure it is set to VS code, the system is set up to the new system
Hi i need help with input system .the perform happens only once
is there a solution to make it happen like all the time?
It has not changed no. Last time you used the input system you probably did not use the generated class file.
Depends on how you set things up but either check for the 'performed' phase or value != 0
Either set a bool true on started and false on cancelled or else just poll the input action in update instead of using events
Thanks
How do I unregister an action?
PlayerInput playerInput = GetComponent<PlayerInput>();
InputAction moveAction = playerInput.actions["Move"];
moveAction.performed -= Onmove;
this doesnt seem to work?
Does anyone know why this action input button for VR Bluetooth controller is not working but the Action Input for the Key (E) is working?
Look at the Creating Actions in code
From the doc
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Actions.html#creating-actions
And take the time to read all this page it’s worth it 🙂
I just want to bump this
Is anyone facing random issues in the newest version of the new input system 1.1.1 where the On-Screen Stick will, at a random time, just start following any touch you make on the screen, even if it's outside of the image you had the script on? I saw this post recently on an older version of the system, but I'm facing it with the newest.: https://forum.unity.com/threads/how-to-prevent-touchscreen-controls-getting-stuck-using-the-input-system-samples-example.965738/
And also, this never happens in the editor (I'm using 2020.3.18f1). Only when I build it and run it on my Android device.
Hey, I am using the new Input system, how do I stop the movement after I release the WASD keys?
Also, when I change direction to the opposite with multiple buttons pressed it doesn't work
Hello everyone! I've been having some issues setting up the Input System for my new project. I've done it before, but this time around it's telling me that the namespace "InputSystem" doesn't exist. I've tried unisntalling and reinstalling the package, updating my .NET SDK, so I'm not sure what other options are left here
Yes
Just VS
well, I presume it should not say Unloaded here
so I'd look into whatever causes that
Can you right click on it and reload it?
Yea, it asked if I wanted to install missing features so I'm doing that first
Alright, I installed the missing features and it no longer says unloaded but i still get these errors
@glass yacht
It looks better at least, did you restart, I'd probably try that next
I did but let me try one more time
Yup, still getting the same thing
Is there anything meaningful in the notifications? I'd try logging out and in (or restart the computer) if that's not what you did. If not, I'm out of ideas.
It worked btw so thank you more!
how do i fix this has something to do with the input system i think
you have enabled the Input System and set your project to use that but are attempting to use the input class for input. Either switch to using the Input System for input or change your project settings
the setting is in Project Settings > Player > Active Input Handling
its not there
what isn't where?
Active Input Handling
yes it is, you just aren't looking hard enough.
ok i found it thank you
Hey, how do i check if a button is not pressed with the new input system? I need a specifc action to occur depending on whether Shift is pressed or not (so Shift + button = something and only button = something else)
You could just set a boolean to true like shiftPressed in the beginning and then set it to false in the end. Then just check for that boolean in the other action methods
So i'd need a new action mapped like "Shift" and basing on whether shift is held or not, modify the bool, right?
That's what I would do, yeah
how come nothing is showing up in my properties tab? I want to add a path to my <No Binding>
How can I move a player left and right with the same CallbackContext? Since there's only one called "Move" with Unity Events
how can add support for 4 different types of devices and each not trigger each other actions? i'm using the generated c# class and i classify myself as a newbie with the new input system
Hey, why my buttons can't outweight other buttons, example going from right to up
This was never an issue with GetHorizontal/Vertical old input system
anyone know why the input system does not work with controller at all in a build of my game? - works perfect in the editor
Hey I am using a new Input System and for some reason if I am going right or left I can't overweight the right and left with up or down buttons, could anyone guess what am I doing wrong?
I solved my issue....
I didn't press Save Asset button while I was making changes to the input system, so all the time I thought I was doing something wrong.
Would anyone know the fix to my question above? It's kinda urgent
anyone able to send a link to a good tutorial on input and multiplayer input?
when playing Minecraft the mouse pointer isnt visible and the playerCharacter rotates its body as we move the mouse
how do i implement that in a fps game i am making?
please ping me when anyone responds
Hide the cursor:
https://docs.unity3d.com/ScriptReference/Cursor-visible.html
FPS movement:
https://www.youtube.com/results?search_query=fps+movement+unity
thanks
What's the replacement for Input.GetAxis("Mouse X") in the new input system?
Rather, is there a way to get the mouse input without using CallbackContext
Mouse.current.position.ReadValue(); will give you Vector2 value then you can get X or Y from it.
the new input system is a hell to work with state machines....
Use sharpdx instead then? 
Unity literally slows down if I use single input action multiple times, wtf
using the minis midi input with the input system i have a scene that, when loaded on it's own, works perfectly (4 separate midi input channels doing what they need to do). when the scene is loaded as part of the build after a different scene, midi channel 1 also triggers the midi channel 2 action. i've tried loads of different workarounds (even inserting extra scene to "reset" the input system) but this continues to happen, any ideas here?
how can i get input from one specific controller?
Wdym
If i have multiple controllers, assign one to a specific GameObject so that it is controller by this specific controller. I researched a bit and the only thing i get is that i need multiple control schemes and an Input Action component on the objects
Use hardware Id to identify each controller
And then I bet you can do it
Kay thanks
I'm having a bit trouble with the input system in the WebGL version of my project. I am using the old unity input system and the unity UI and when I click a button, it keeps on getting pressed repeatedly until I click somewhere else. How can I fix this? 🤔
I should add that it works great in the desktop release and the editors play mode
Question, I'm working on a multiplayer set of code. What I've done was instantiate a NetworkController for the player to join and play in the game, but then it doesn't have a actor or pawn to spawn in the world. I can instantiate a player game object, but how do I assign the current player's controller to that game object?
It's not like I could do something as
playerGameObject.GetComponent<PlayerInput>().Assign( this.playerInput );
```?
Hey Friends! Would anyone be so kind to link me to a solid guide to help me create a 3D Isometric Character Controller? I unfortunately cannot seem to find an up to date one. Thank you so much!
I literally cannot set an input, when I type "LeftControl" to Positive Button it gets deleted
what the fk
that's it
I'm fucking done with this glitchy mess
can't focus on what I'm gonna create cuz of these constant glitches
left ctrl
It's not a keycode, it's also not just a space
Has anyone had any PS4 controller issues with the new input system UI mappings with their Windows build? The controller works great in the editor, but when I build out my application with Windows x86_64, it's very janky. The joystick works fine as do the cardinal buttons, but the d pad gets screwy. Windows controller and keyboard work fine, although keyboard does not work when the PS4 controller is plugged in when running my Windows application. I'm on Unity 2020.3.19f1 with the new input system version 1.1.1.
I can't even get my DS4 to work with pc using wireless bluetooth 😦 How did you get yours working? Did you use microUSB cable or some kind of adapter?
I've only been trying with the USB plugged in. My old version of the input system seems to work fine, but something about 1.1.1 that it doesn't like. Does yours work in the editor?
Nope. Not even the xbox 360 controllers nor the xbox one either!
It used to work before, but something happened and now they just stop working.
Using 1.1.1 of the new input system?
Let me check...
What did ya know?
Also, for the sake of it, this is what my input schemes look like.
See if downgrading the version fixes the issue you're experiencing? I might do this later after work.
sounds like a real bug
you might want to try to go back to 1.1.0-preview.2 which in my opinion is the most reliable version
Thanks, @sharp geode ! Has that worked with a PS4 controller on a windows build for you?
@sweet niche looks fine to me. I recently had a funky issue with my UI mapping where I had to copy the UI action map from the input system package's default input action and that stopped an issue I was having with my joystick sticking when tapping a button with the On-Screen Button script attached to it.
Wonder if this is happening for you now
Yes @sharp geode. 1.1.0-preview.2 fixes my issue. I don't know if this will mess up the touch buttons on my mobile yet, but I think for now, I'll just create my PC build with 1.1.0-preview.2 and hopefully by the time I push a new version up to Steam again, they'll have this fixed.
Thanks a lot
Update on 1.1.0-preview.2 though, it doesn't seem to read some of my keyboard buttons. I think there is something going on with the default input action maps that they keep changing in each of these versions. In the 1.1.1 version, my UI buttons work good, but navigation on the PS4 controller doesn't. In the 1.1.0-preview.2 version, the UI buttons all seem to work out great, but the player controls on the keyboard for me are messed up.
Maybe recreate those
Yep, doing that as we speak
So, it looks like if I have a controller plugged in, the keyboard input will allow all my input mappings except my 1D axis bindings that I have in my horizontal movement. But once I unplug the controller, the scheme switches fine and works on the keyboard. I guess I'll have to create a Vector2 binding for my entire movement if I want to make this work, although I'm not sure if a Vector2 movement will work based on what I'm seeing with the 1D axis stuff.
Well, dumb me. If you're using 1.1.1, just add the D pad stuff in the navigate section of the UI of the DefaultInputActions Action Map
i feel like this has been asked before but
how do i ReadValue<>() a bool from a keyboard space action?
what control type do i use
oh should i use ReadValue<float>() != 0?
Reposting this in hopes somebody can help me with this issue:
I'm having a bit trouble with the input system in the WebGL version of my project. I am using the old unity input system and the unity UI and when I click a button, it keeps on getting pressed repeatedly until I click somewhere else. How can I fix this? 🤔
I should add that it works great in the desktop release and the editors play mode, I have also seen the button working flawlessly on other peoples browsers
I'm trying to use the "Virtual Mouse" device for the gamepad with the PlayerInput component. It works when there are no control schemes in the inputactionasset. However once you add a control scheme the Virtual Mouse isn't detected for a User.
How can I link the Virtual Mouse to a User with the PlayerInput component?
here doesn't appear in the "Paired Devices" section
EDIT:
FIXED: For those wondering of the solution: InputUser.PerformPairingWithDevice(virtualMouse, playerInput.user);
I am using the new input system in a combination with FiniteStateMachine and for some reason, when running input on start and on exit It runs N times and slows down the game
has anyone had similiar issues?
i added starter assets in my project
then i deleted it cause of this error
what do i do now?
Thanks to my self that i made a backup of my own project
(Regarding the new input system) Is it possible to get on code an input button to show as a string on UI? For example, if the currently active input for jumping is the "D" key I can grab it on code and use it as a string?
Yea rebinding examples should go through this if nothing else
hi all , anyone know how to get values from the keyboard with the new input system that are floats ?
like 0.5 0.4 -0.3 and so on ?
i am only getting 1 0 -1
From the gamepad i am getting the values
both vector2 are analog
hey guys do you know why this is happening , i'm trying to set the position of the player when he join but it goes where the Input System spawned the player before i implemented this
Unless you have one of the few keyboard models in the world that do, your keyboard isn't reporting beyond on and off.
If you are looking to smooth the input, you can use Vector2.MoveTowards or some other smoothing method in the script.
Can someone help me understand how PlayerInput.Instantiate() works? Does that means that player 1 would "attach" to the newly created gameobject instead of creating player 2?
Based on the docs I think it only ever expects you to use it to create a new player, not rebind an existing player to a new object
never tried it myself though
Yea it seems to be an Instantiate wrapper with some values that will be set on the PlayerInput component on that prefab
Ok so how do I go about spawning a player "actor", but the player input are driving from a "NetworkController", namely a spectator game object not attached to a player "actor" yet.
I have the Player Input on the "spectator" camera, but when I spawn the Player that "hooks" into, I have to feed the input to the player somehow?
I tend to just go for a separate Player gameobject that primarily hosts PlayerInput and some component to manage and send input to controlled gameobjects.
Then you can just unhook the spectator camera and hook in the controlled entity
That's the thing how do I do that? The "Spectator" is just a camera gameobject, that have Player Input, NetworkObject, and Player Handler (Just basically spectator behaviour)
I can parent this "Spectator" to a newly gameobject, but then how do I go about Attaching handlers to that?
Funny I'd say "possessed" a player
Ok so in this case here I have to use Player Input for controlling "Player". How do I give User 1 to control Player 1 character?
wait ,is there a way to change player spawn position because i tried scripting it but it seems like it's setting another position after i set it?
like when i use Join When Action is Pressed
Sounds like a #archived-networking question, right?
does local multiplayer is networking?
Oh it is local, are you using any networking or just your custom join method?
nah i'm using custom join method
but it seems like when i set the position , the input system set another one for me
And it is set in your onjoined where you set playerInput position?
or it just doesn't change the position for some reason even tho it should
well i'm doing playerInput.gameObject.position
it should work right?
Should be transform.position
oh wait i know.
thanks !!
also , how can i make the connected players join without pressing a button?
sorry btw for crossposting
This is such a general question. You have to explain your setup, so we know what you mean? Generally answered, if they connect, put the function you use on button right inside your connected function
well , when you connect your controller or your keyboard for exemple , i want my game to automatically add a new player without them pressing a button or adding a prefab of the connected player when i'm changing the scene instead of having them always press a button to join
i know i can do that with join manually but how can i get all the connected controllers?*
well then listen for the connected function and use that to handle the join then
yeah but is the connected function only on the playerInput?
like OnPlayerJoined is only executed when a player press a button or something like that , but it's not executed when a device is connected right?
the new input system might have a function for that or a callback, gotta check google for that
ok ima check
devices should give you the current once, maybe you gotta filter for gamepads or what not, but API should get you started there
ok thanks
i found something interesting i think this might fix my issue https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.InputDeviceChange.html
that looks perfect for your case 🙂
yup!
in my opinion yes it is
Much more versatile yes
Can you suggest a good tutorial to learn it?
Unity has a lengthy one on their YouTube channel.
do you know why for some reason it doesn't get called?
How do I add a sprint action? I'm confused on what the correct way to do this
public void OnSprint(InputAction.CallbackContext context)
{
isSprintHeld = context.ReadValue<bool>();
}
I have this code? basically I just want to know if the button is down, yes or no
So my action type is a Value
but what's my control type?
there's no 'bool' option :/
so then if the value is not zero that means it is being held, right? so just use that
isSprintHeld = context.ReadValue<float>() != 0
this would make isSprintHeld true if it isn't 0 and false if it is
i mean there's many ways to do what you are trying. but this does exactly what you wanted to do in pretty much the same way you wanted to do it
is this the optimal way?
You can also do context.ReadValueAsButton()
it does the exact same thing though
ic, thanks 😄
How do I get input from the player to the ui in the new input system... I found in the upgraded event system a navigation event toggle.. How do I use it.. I looked for help from unity support.. I can't find something to help me
I want to use it to detect if the player moves up and down in a drop down
Hey guys, so im getting this error the whole time even tho im clearly not using the old input system anymore... anyone had the same issue/can help?
it says you're calling Input.GetMousePosition so go through your scripts and remove any mentions of that
im 100% sure I didnt use any of that.. but here are the last things I did befor it startet to show up:
is There anything that has to do with mouseinput that im not aware of?
if you're sure you're not calling it then try saving all your scripts or restarting unity
also tried.. nothing changed
not sure how to help here sorry
np thanks anyway
Ohh I got it... I added a ui canvas, and I needed to update the Eventsystem to the new input system
is there a way to add a controller bind with get key down?
With the old input system? I don't think you can at runtime. IIRC you can modify the file manually through code and relaunch the game.
Hey, everyone! I have a question to those of you who have shipped Unity games to consoles before: Did you use the Unity Input System or some third-party plugin like Rewired? I'm being told that the new input system doesn't work well with consoles yet.
We're using Input System on internal projects on both prev and current gen consoles, including gamepad specific bindings on PC without any issues. What "wouldn't work well" have you heard about it?
Thank you, that's good to hear, I was kind of hoping for that. We're working with an external studio that helps us with ports and installed Rewired, but we keep having trouble with it that we didn't with the PC version using Unity's Input System. They didn't elaborate on what exactly doesn't work well with consoles.
Maybe someone had a bad time with it in the past or maybe there's just stubborn programmers at the studio 😛
I know of one studio that had issues with Rewired but that specifically for Stadia, but I also heard a lot of people really like rewired. I guess it boils down to if you want to trust a 3rd party to fix any issues related to input. Input System is open to modification after all so in theory you could implement any fixes yourself.
Having made the switch recently, I can say that so far we're having a bunch of trouble with input and movement that may or may not be Rewired's fault. 😅 Also, from what I've seen so far, Rewired's UI is not the best...
Decent chance that there have been input system kinks on consoles in the past 6 months as the input system is getting mature. Rewired has been there for a while, so I can see it being a safe fallback for a lot of studios.
I see. In that case, I'll just hope that this will be ironed out by the time our next release draws close so we don't have to deal with another plugin.
Hello, I am new to Unity have a problem about taking input. I am having "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." error while using UnityEngine.Input.GetKeyDown (System.String name) function. I have tried this in two projects (also not being able to get InputValue), but could not find a workaround. As far as I understand, Unity can get input (I checked using one of Unity's features but forgot where I found it) from keyboard, but for some reason, I cannot get keyboard strokes trigger something in code (the game is unresponsive when I press something). I have also checked online but could not find a decent solution to solve this issue. Has anyone solved this issue?
you'll want to switch back to the old input system which you're trying to use
Edit -> project settings -> Player -> Other settings and change the Active Input Handling to Input Manager (Old)
I removed the legacy input code (Input.GetKeydown) and removed the error. However, I was getting input from InputValue in OnMove() method. I was fallowing the Roll-a-Ball project from Unity tutorials, where until I integrated the UI, controls were working just fine. After implementing UI, the keyboard input stopped working, I probably got the error as I was trying to read input from keyboard to test it out. Now it keyboard input does not work without any errors...
if you go on the event system i think there could be a component which is for the old input system, unity will have a prompt telling you to switch to the new component if that's the case
Can anyone help me out with this please? - https://answers.unity.com/questions/1864481/new-input-system-multiple-controllers-plugged-in-i.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.
Do i need to declare a main controller with the new input system? as multiple devices plugged in causes unexpected issues.
This respects the InputSystem's "Press Threshold" setting, fyi
makes sense
Not 100% if this is the channel for this, but I have a terraria-like game with destroyable blocks. When a block is hovered, it lights up by enabling emission on the mesh. On the player gameobject, I have a click action script that reacts different ways to different things being clicked. It doesthis by casting a ray, returning the label, then working with that information. This system works great, but I cannot click through colliders, so if I place a sphere collider on my player (for interaction radius) there is no way to detect if the mouse is in the radius and clicking something clickable. It only returns information on the sphere collider, not anything behind/inside it. Is there a better way to restrict range on objects that can be clicked from the player's location?
Can't you just do a Vector3.Distance check?
or if not, you can just use a LayerMask on your raycast to exclude the player's sphere collider
I could do the mask, but I need to know if the mouse is within that radius
Vector3 distance might be the move
hi all how can I go about getting the value from this thrust value please, the examples dont seem to mention much
You have the OnWhatever etc etc, so in this case its saying OnMovement but I have no idea how to get the data inside
@lilac hazel which data you are looking for exactly ?
The input values?
You can do Mouvement.ReadValue<Vector2>()
ReadValue<float>() on either the InputAction or the InputAction.CallbackContext parameter to your method
I have an inventory button, the function simply sets the window to display if it isn't active, or deactivate if it is active. Even with the On Button Released option in the actions settings this causes an infinite toggle between states and so the window never leaves. How do I detect if a key is pressed in code?
show your code
You should generally just be listening for the performed state/event of the button and it will just happen once when you press it.
{
if (_input.inventory)
{
if(InventoryObj.activeSelf == true) { InventoryObj.SetActive(false); }
if (InventoryObj.activeSelf == false) { InventoryObj.SetActive(true); }
}
}```
when I hit I, the inventory appears and disappears
So, I am not sure how to listen for when it is performed
Just looks like a logical error in your code honestly
if(InventoryObj.activeSelf) { InventoryObj.SetActive(false); }
else { InventoryObj.SetActive(true); }```
Or even better:
```cs
InventoryObj.SetActive(!InventoryObj.activeSelf);```
InventoryObj.SetActive(!InventoryObj.activeSelf); this causes the menu to toggle infinitely off and on
the way you have it right now, if it's currently active, it will be deactivated by your first if statement, and then the second if statement will also run
inifinitely, or just as long as you hold the button down
infinitely
my inventory is being called in the update code
then you're just doing this every frame, so of course it will keep toggling forever
unless you have some code that is checking for some input
Well, the action mapping is set to only toggle the action as a button press
Is your code related to input at all? I can't tell from the code you've shared so far
It uses the input system and action maps
You just showed some code and said it's running in Update()
Ok and how did you set this up?
How are you listening for the button presses
there are many ways to do it
show more of your code
its just the starter asset third person controller from the asset store
that starter asset doesn't have an inventory screen as far as I'm aware
im just trying to toggle the inventory by listening for the key. _input.inventory listens for the key but doesnt respect the fact that the action is mapped to a button press
_input.inventory listens for the key
It does? That doesn't look like any way to listen for input that I've seen. What is_inputand what is_input.inventory?
what is StarterAssetsInputs? Is that the generated C# class file from the InputActionsAsset?
That's not a correct way to listen for input
If anything that's just checking if it's null
which it won't be
You probably need something like:
_input.inventory.phase == InputActionPhase.performed```
phase does not exist
What is the type of _input.inventory?
mouse over it, your IDE should tell you its type
doesn't sound right
_input might be InputActionsAsset
but _input.inventory should be ActionMap or InputAction or something
private InputAction InventoryAction;
if it's an InputAction then it will have a phase property
InventoryAction = PI.actions["Inventory"];```
Then InventoryAction.phase should be a thing
Also if you're using Input System version 1.1+ you should also be able to use InventoryAction.WasPerformedThisFrame()
ohh
private void MyInventory()
{
if (InventoryAction.phase == InputActionPhase.Performed)
{
InventoryObj.SetActive(!InventoryObj.activeSelf);
}
}
this causes it to disappear after toggling multple times
"disappear"?
I can bring it back the same with while it toggles multple times
wdym by disappear
how and where are you calling MyInventory()? And what does "disappear" mean? Is the object being destroyed? Deactivated? It's supposed to be getting deactivated
I hate this new input system. This was so easy to do with the old one. Just get key down, no big deal
At this point it's not the input system causing you issues
its called in update
Also can you show how you set up the Inventory action in your Input actions asset?
You should just have it set up as a basic button with no interactions or anything
Action Maps: Player Under player there's inventory, and in inventory there's the path with is the I key and its set to Press and Release
yes but the properties for Inventory should be set up as a button
like this
and get rid of the Press and Release interaction
it's causing issues for you
You want a basic button with no interactions
now it ceases to do anything
I was looking at this
no idea how this works
yes you can go event based but that will probably end up confusing you even more
probably
I'll probably just have to write a coroutine to stop it activiating so fast, which I didnt want to do
you really don't have to
the setup we have discussed will work
you have something out of place somewhere
You can also try InventoryAction.phase == InputActionPhase.Started
That causes it to work, but wonkily, toggling multiple times unless I super fast tap the key
even then it still will likely toggle multiple times
Something isn't right - can you share the current state of your code and screenshots of how you configured the input action, including all the bindings?
Thanks so much !
Hi so I seem to be running into a problem when it comes to setting up a button as a mobile jump button I can get it to work fine but I made it so that if the player dies they respawn and so since the player object gets destroyed and a new one spawns from the prefab the jump button loses the jump function since its assigned from the original player object. I've tried to assign the jump function from the prefab but when I try that the jump function doesn't work at all. Any help or maybe a different way of doing it will be appreciated.
Get an instance of your player, like a static one and just use that in your button to call Character.Jump();
Thanks that helped a lot!
What's the difference between CallbackContext and InputValue?
Hi,
I'm a beginner so please bare with me.
I am making a FPS controller with the new unity input system.
My input works absolutely fine when using mouse and keyboard.
Yet when I add bindings for a generic gamepad I get stutter issues when using the WASD - movement keys.
My gamepad look axis (right stick) is also slower in turn speed than my mouse.
The stutter with the WASD feels like the input is pressed but then abruptly stops whilst sometimes, I can press the WASD and have nothing happen at all - while the gamepad left stick moves the player just fine.
I have deleted previous the Gamepad bindings and this fixed the problem but obviously I want to use Gamepad as well.
I will provide details / pictures of how I have set up my Input System:
I have the 'Movement' action properties set to:
Action Type = Pass Through
Control Type = Vector 2
then separate control scheme profiles - one for keyboard, one for gamepad.
For the WASD I have a 2d Vector Composite Type and the Mode is set to digital normalized.
For the gamepad I have a binding with a stick deadzone processor.
For the 'View' Action I have Action Type = Pass Through and Control Type = Vector 2
I have delta [Mouse] for the binding with the control scheme set up on the Mouse profile - previously had this in keyboard profile but switching either made no differences in regards to the issue.
For the gamepad set up I have the binding on the Right Stick gamepad, Processors are using stick deadzone.
with the dead zone options for either profiles on / off I still run into the two problems I have stated:
-
WASD stutters or does not work, randomly
-
Right gamepad stick turns extremely slow, while mouse turn speed is perfectly accurate
Please if anyone can help i'd be so appreciative
@chrome walrus is this for the second issue?
do I use another processor and times the amount?
Oh dang, I kind of jumped through your message, sorry 😄 yeah for the mouse gamepad difference 😉
just scale the gamepad input if you want it to be faster
how do I get it to match the mouse speed?
Trial and error
got it
there is no math for mouse to gamepad 🙂 as all can be different somehow.
I suppose you don't know why my WASD is stuttering?
so you might want to add a setting later for sensitivity
Okay, wasd is stuttering? hm, let me see. did you send your code too
I am following a tutorial but it works fine until I plug my gamepad in
then the gamepad kinda becomes reliable with movement
Oh, so you get input form gamepad and wasd at the same time
yeah I want the player to be able to use either whenever they want
but the gamepad kinda interrupts the WASD
I thought it might be something to do with the deadzones?
sorry im very new to all this
Well, it sounds like your gamepad is sending input while in 0 position, so this is some drift issue with your gamepad. did you try another? Did you try to higher the deadzone to the max to just "kill" gamepad input?
Just make like 0.4 and 0.6 or something, but not sure if this actually interrupts the input or just kills the vector2 output. But Id say, its your gamepad sending dead values
Happy to hear back what has been the issue, you are veyr welcome 🙂
ah just tested it
no matter where I change the deadzones it still has the same issue
try another gamepad to be sure its not something else.
okay i'll have to find one
You could just bind mouse 1 and 2 to the action of w and s for example just to test out if you can walk with either or at the same time
Did you remove the deadzone just to test that out too?
oh the joypad
no i'll do that now
and yeah it works fine with the mouse bound to 1 and 2
So, back to gamepad, deadzone removed, still that issue?
is wasd bound to keyboard too?
yeah
Can you show your setting for WASD?
Oh wait what. what did you do with the joystick?
why separate all directions? Just do this:
Oh sorry, my bad then
Did you just debug log your input you get? Just to see if there is dead input somewhere
so tap wasd, then use joystick, then let go everything an dsee what comes in as vector2
okay I will try to figure out how to do that
let me show you what I have
so on the awake
setting up the inputs right
um how do I send code
So just debug.log input_movement
sorry for being such a newbie
All good, you can send code with three times ` or just use hastebin
{
if(input_Movement.y <= 0.2f)
{
isSprinting = false;
}
var verticalSpeed = playerSettings.WalkingForwardSpeed;
var horizontalSpeed = playerSettings.WalkingStrafeSpeed;
if(isSprinting)
{
verticalSpeed = playerSettings.RunningForwardSpeed;
horizontalSpeed = playerSettings.RunningStrafeSpeed;
}
//Effectors
if (playerStance == PlayerStance.Crouch)
{
playerSettings.SpeedEffector = playerSettings.CrouchSpeedEffector;
}
else if (playerStance == PlayerStance.Prone)
{
playerSettings.SpeedEffector = playerSettings.ProneSpeedEffector;
}
else
{
playerSettings.SpeedEffector = 1;
}
verticalSpeed *= playerSettings.SpeedEffector;
horizontalSpeed *= playerSettings.SpeedEffector;
newMovementSpeed = Vector3.SmoothDamp(newMovementSpeed, new Vector3(horizontalSpeed * input_Movement.x * Time.deltaTime, 0, verticalSpeed * input_Movement.y * Time.deltaTime), ref newMovementSpeedVelocity, playerSettings.MovementSmoothing);
var movementSpeed = transform.TransformDirection(newMovementSpeed);
if (playerGravity > gravityMin)
{
playerGravity -= gravityAmount * Time.deltaTime;
}
if (playerGravity < -0.1f && characterController.isGrounded)
{
playerGravity = -0.1f;
}
movementSpeed.y += playerGravity;
characterController.Move(movementSpeed);
}```
so I'm presuming the newMovementSpeed might be the issue?
I'll put a debug log in the the update event to test while you read this
first just debuglog the input_movement, is it 0,0 if you touch nothing after you controled with wasd and joystick first
okay so it freezes on (0,0,0.0) say if I switch from the left stick to wasd
if I don't touch the left stick - wasd seem to work fine
and the left stick is fine with moving - lots of numbers for both
but it is as soon as I have used the left stick and switch
So if you use the left stick and then let go and use wasd, it starts spazzing out but input is still 0 if you let go wasd again?
no sorry
basically it works
only when I release the left stick and either press the wasd
or have the wasd already held down
it goes to all the zeros
I can move again fine if I just use the left stick again
so when is it spazzing out? 😄
it isn't sorry I just meant the numbers move
there is another issue
sometimes even when I press WASD and haven't hit the stick
it will move fine
then stop and get stuck at 0
this was the stuttering effect
(im sorry if i'm not being very clear)
Oh well, then you might just have to go from ground up, check whats your movement is doing. Remove all interpolation and just use raw and then add stuff one by one.
I suppose I'll just use the old input system
and get rewired or something when I have money
what a bummer
Thanks for helping me twentacle, I appreciate you taking the time out of your day
sorry we could not get rid of your problem. Still I do not htink its the input system itself. But maybe its a bug. Best of luck figuring your way out 🙂
Thanks
Making my own pairing system for the input system since I'm not a fan of the PlayerInputManager
How do I associate InputActions with a device? I've now got pairing implemented, and now I want the players to receive the correct input.
Each player has a reference to the device ID it's paired to. How can I reference InputActions that use WASD and gamepad analog stick from just the device ID?
If I just do this:
movement=controls.PlayerActions.Movement.ReadValue<Vector2>();
where controls is a new instance of the auto-generated C# class from the input actions asset.
It doesn't stop the keyboard from controlling players paired with a controller and vice versa
I've tried looking through PlayerInput.cs and PlayerInputManager.cs for answers, but I can't really find anything.
Anyone know how this is achieved with the PlayerInputManager?
controls.PlayerActions.Movement += ctx => movement = ctx.ReadValue<Vector2>();
that's how I do it and how it always works for me
I'm not sure if you're looking for this since I just saw your discussion
Can someone help me with the ui how do i make it so the input affects a parameter of a object
there is anyway i can trigger a press button event without using Update and FixedUpdate?
Yes the new input system allows you to respond to input using events
how the code look like? can i have a docs or something?
Hey, so im trying to do something when i press grip on my vr controller. (if (grip pressed & is touching wall) --> start climbing)
How can i do this?
Does Xbox one compiled games use the Cursor (lock states) by chance? I use the cursor to judge to see if my script needs to reassign a button to selected game object for controllers but idk if it would work in concept due to xbox not being a desktop with normal keyboard/mouse
You can use M&KB on Xbox, so yes? Xbox specific questions should go in the Xbox forums though as most info is under NDA
I'm new to the NIS, I've forgotten how to add subscribers to an event
void Jump()
{
}
do I need to add a parameter to my method or something?
oh
(InputAction.CallbackContext context)
Sometimes buttons get "stuck down" int he new input system
Like i'll be holding right and then let go of it and it keeps holding until I tap right again
as if that somehow "resets" it
the code is all adapted from old input system where it worked perfectl
for instance this used to be * input.getAxis
this has happened on previous unity new input systemp rojects
that Ialso adapted from old input system
and also had the exact same problem
which is why I abandoned them
Looks like you're adding your input to your turnMovement variable instead of setting it. Unless you have some other code that zeroes it out, adding zero won't change it.
Overall it's hard to say what the problem is without:
- seeing more of the context of the code
- seeing how you've configured your input actions and bindings
yeah, it gets zeroed out every frame
it was addition in the version beforehand as well
it only gets "stuck" if I hold down a movement button, then hold down another button, and let go of it
it seems more like a glitch than some sort of systemic problem
try removing all of the bindings except one for a bit and see if that changes anything
thign is it only triggers if another binding(IE, for the boost/nitro) is held
so that would mean I couldn't test the problem
No I mean the bindings for the Move action
leave the other actions alone
You have 4 separate bindings for Move, I've seen issues with that, especially if any of those devices are currently plugged in.
I only have the keyboard plguged in, no gamepad or XR controlle
Here's a video showing the problem
with a keyboard overlay from OBS
notice how even after I let go of d the thing still moves right or a for left
and that only when I tap them again does it stop drifitng like that
looks like it only does it when you're boosting right? Can you print out what the input values you're getting are at that time? I'm not convinced it not just a logical error in your code
It only STARTS when I'm boosting, but it continues after I let go fo the booost or the boost runs out. The movement is handled IDENTICALLY whether you are boosting or not - literally exactly the same
I have no code that modifies your movement depending on your boost
Also @austere grotto Printing input values every frame confirms the problem
even when I let go of A or D the input still prints
as if I was
How are you reading hte input
are you just reading the value in Update?
Or using events?
yea
That's not wrapped in any if statements or anything?
You don't have any interactions or processors on the input action or the bindings do you?