#🖱️┃input-system
1 messages · Page 63 of 1
How can I handle input from two gamepads. I've looked up some videos online, but the solutions are unsatisfactory because I don't want to spawn in a player prefab, I just want to separate the input from two gamepads.
Is there a generic way to ask the input system if there is currently any input of a given type?
I'm aware of things like Keyboard.current.aKey or Mouse.current.scroll, however these become somewhat cumbersome when you need to be checking for potentially 3 or 4 different types of possible input for a given action.
What I'm looking for it a way to just ask something like, "Is this particular action being performed by any type of input?"
I don't think I understand how to use that to do what I'm trying to do. Basically I have some code that is running in Update, and I only want it to run if a valid input is being performed.
Thanks for sharing that, but unfortunately it's beyond my skill level to understand. I'll have to find some other way to do what I need.
if i want to get input events until something happens, how can i stop it once its done....the docs give this kind of example InputSystem.onEvent.Call(eventPtr => { // do stuff }); but once i 'do stuff' i want to then stop the code being called under certain conditions, but CallOnce isnt the same thing
this turned out quite simple i think
private void OnEnable()
{
buttonPressDelegate = InputSystem.onAnyButtonPress.Call(control =>
{
if (control.displayName == "A")
{
//do something
}
});
}
private void OnDisable()
{
buttonPressDelegate.Dispose();
}```
seemed to do the trick
Hi there
does anyone know a way to prevent action overlap if they have different modifiers?
Like if I have
Undo with Ctrl+Z
and Redo on Shift+Ctrl+Z
how can I prevent both actions from firing when I press Shift+Ctrl+Z?
private void OnEnable()
{
foreach (Weapon w in weaponsList) w.binding.Enable();
}
void Update()
{
foreach (Weapon w in weaponsList)
{
if (w.enabled)
{
w.binding.performed += ctx =>
{
var control = ctx.control;
button = control as ButtonControl;
};
if (w.automatic && button != null && button.isPressed && Time.time > w.nextFire)
{
w.nextFire = Time.time + w.fireRate;
Shoot(w);
}
else if (!w.automatic && button != null && button.wasPressedThisFrame && Time.time > w.nextFire)
{
w.nextFire = Time.time + w.fireRate;
Shoot(w);
}
}
}
}
void Shoot(Weapon weapon)
{
GameObject projectile = Instantiate(weapon.projectilePrefab, firePoint.position, firePoint.rotation);
Rigidbody2D rb = projectile.GetComponent<Rigidbody2D>();
rb.AddForce(firePoint.up * weapon.force, ForceMode2D.Impulse);
}
private void OnDisable()
{
foreach (Weapon w in weaponsList) w.binding.Disable();
}
I have a weird issue with this code, if any weapon has a binding to a key, pressing that key will fire every weapon at the same time
For example, left click should only fire one of the weapons, but it fires all of them
why wouldn't it fire all of them?
It should check each weapon one at a time and if the binding is pressed shoot that one
also cs w.binding.performed += ctx => { var control = ctx.control; button = control as ButtonControl; }; you sure you want to be doing this every frame?
doesn't seem like it's doing anything
other than leaking a ton of memory
Is there a better way to do it?
yeah do it once
not in Update
also i don't understand what it's doing really
but you're resubscribing that listener every single frame
so you're going to end up with thousands of listeners
anyway...
Is there something in here that's supposed to be connecting an individual weapon to an individual button?
yeah, the w.binding part
but you only hav ea single button variable
Ok thank you, that made me think and I figured it out
I just added a ButtonControl field to the weapon and made the script use that instead
This might be the hackiest way of using the new input system I've seen yet.
wdym by that lmao
dealing directly with Controls instead of Input Actions
Yeah, I think that you usually use the old system for that but that wasn't working nicely with my specific need
the "binding" is just adding your lambdas to actions
you can make that in seconds yourself
Hi there, I'm having a problem implementing controller input into my first person game... I have movement and such working perfectly for keyboard and mouse but wanted to add controller functionality... I can walk around although when it comes to looking or rotating the player the camera does alot of wierd things such as rotating on the wrong axis... as well i have tried to implement sprinting but for some reason it only works when i walk side to side... Any help would be appreciated.. Thanks
Does anyone know a good asset to use to have a remap menu ingame?
Hey guys I have a question, I'm using Ipointerhandlers to handle input in my game and when I drag cards around in PC they are very responsive.
but when I build to Android, when I drag card they 'trail' behind my finger and follow it instead of being under ot all the time, it just doesn't feel as responsive
How can I fix that and make it responsive?
It's kind of just a consequence of having a lower framerate
best you can do is work on the performance of your game and make sure you're reaching the highest possible framerate
I'm having an issue where the RebindUI just refuses to rebind to E
ive tried changing all the other keys just incase duplicates were in the way, but that didnt help
nothing in my performInteractiveRebind is saying anything against E
it simply just wont rebind to E
How do i do double tap with unity new Input system? I read something about adding AddListener to another gameobject, but i haven't quite got it. But i especially don't want to add a delay to my Press function. So my need would be, Press A > do something, in 200ms quickly release and press it again for a Double tap function.
Instead of: Press A function wait for a delay which used to determine if a 2nd press is inputted.
There's a multitap interaction already built into the input system: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.4/manual/Interactions.html#multitap
hey so i just started using the input system and it has worked rly well. Im making a gun for a tank that shoots when you press r1 on the gamepad and it works but it doesnt stop shooting as i dont know what i would do to stop my bool "isFiring" could anyone help me and see where im being stupid its probably rl;y easy i just dont know where the get button up is or anything im confusing m,yself haha
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class TurretController : MonoBehaviour
{
public bool isFiring;
public BulletController bullet;
public float bulletSpeed;
public float timeBetweenShots;
private float shotCounter;
public Transform firePoint;
private PlayerControls playerControls;
private InputAction fire;
public float oneSec = 1f;
void Update()
{
if(isFiring)
{
shotCounter -= Time.deltaTime;
if(shotCounter <= 0)
{
shotCounter = timeBetweenShots;
BulletController newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation) as BulletController;
newBullet.speed = bulletSpeed;
}
}
else
{
shotCounter = 0;
}
}
private void Awake()
{
playerControls = new PlayerControls();
}
private void OnEnable()
{
fire = playerControls.Controls.Fire;
fire.Enable();
fire.performed += Fire;
}
private void OnDisable()
{
fire.Disable();
}
private void Fire(InputAction.CallbackContext context)
{
isFiring = true;
Debug.Log("We Fired!");
}
}
thats the code :)
bottom part is where the fire action is called and all the input stuff
hey im in the input settings
whats the word for
ctrl?
like is it control
or..?
How do you guys typically handle input within a state machine? In a separate script or within each state?
I'd say separate file for input handling is desirable. My input triggered regardless of states. But i subscribe/unsubscribe depending on the state.
within the state
Hello with the old input system how do i properly detect scroll wheel movement up and down?
i want to use it for a selection thing
Hello! Did someone update to 1.4.1 and W,AS,D keys stopped working in a axis binding?
I have my input on the horizontal axis in the update method and my logic for running in a method I created called "Run()", but the character doesn't move
There's a mouse scroll wheel axis
yeah i found it
Is Run() ever running?
Pardon the pun
how do I make sure it's always running?
ahaha
You'd have to run it from somewhere. FixedUpdate I guess?
true lol
MethodName();
my bad
Just get rid of the parameter
This is something you'd call yourself
Not something you'd call as a callback
I can't get rid of the parameter in the method
Why not
What's the run action supposed to do
this is in the Start() function
You have confused some stuff here
Handle movement and friction
This code here should be called from FixedUpdate
All of that should just be in FixedUpdate
Why do you want to bind it to input
so that when I make a state machine, I can have the function in 1 class
and have it be called by the state machine handler
None of that seems relevant to input
otherwise I would do it a different way which is what I had before, without functions
hmm
hold on
ahh alright thanks
I want when I click on the arrows, it does the command, for example: the up arrow," then" the down arrow, "then" the arrow ....
Provided that he does not press the arrows at the same time
What arrows, and what command?
UpArrow , DownArrow ....
if (Input.GetKey(KeyCode.UpArrow) & Input.GetKey(KeyCode.DownArrow) & Input.GetKey(KeyCode.LeftArrow) & Input.GetKey(KeyCode.rightArrow))
{
print("...");
}
That will print if you press them all the same time
You'd have to put the keycodes in a List and keep track of which one you're listening for next
How can I do that?
I'm not going to hold your hand through it
.
if (Input.GetKey(KeyCode.UpArrow) | Input.GetKey(KeyCode.DownArrow) | Input.GetKey(KeyCode.LeftArrow) | Input.GetKey(KeyCode.rightArrow))
{
Count += 1;
}
If (Count == 4) {
print("....");
}
Like this ??
Nvm , I solved it
I'm working on a multiplayer game using the new input system. The game exclusively uses gamepads for input. When testing with the game open twice (or with the game open and the editor in Play mode), gamepad input ceases to work on both instances of the game, no matter which one is currently focused. Mouse input seems to work fine though. Is there any way to get gamepad input working in this sort of situation?
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
i'm looking for a way to get axis in new unity input system
how'd i do that?
tried searching but haven't find anything yet
anyways... i've found the solution which was pretty simple
changed active input handling to both
There is a way to do it via custom input maps, but honestly the new input system is so wacky it might not even be worth trying to implement lol
For the input you're trying to use, it has a ReadValue<T>() method. You can get different value types from an input (i.e. a Vector2 for X/Y axes) https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Actions.html
It's not bad, it's just obtuse
Is it possible to listen for a DualShock touchpad swipe in the new input system or is it something Sony reserves for themselves?
Just like the shake sensor etc
not sure if it supports it out of the get go, but if it doesn't you can simply add it as your own device code
My friend is trying to make a hotkey menu but it isn't working for him
Without sharing some details, hard to help
details, as in code, etc.. Why am I getting screenshots from a discord chat
For a better explanation from his cuz he didn't explain it that well the first time lol
He's saying he used the default premade rebind ui with the new input system
So its just the default scripts
https://forum.unity.com/threads/rebinding-keys-isnt-reflected-in-existing-controlschemes.829191/ he said like this if you still don't understand 
Really? That's interesting. Do you have any sources for me to look into how to do that? If not that's fine tho!
hello how can i make my button prompts change when i use a different input system like a controller
yes
You can initialize their text from an ScriptableObject for example, and if other type of input used swap for another SO with alternative text.
i dont use text i use iamges that pre made for every input system
same thing, initialize them with other images
ok
also text mesh pro has a way to add sprites
and you assign a code to that sprite and whenever you type use that code in text it will show a sprite
where is this
player input component
yeah i cant find it
you have the package or just built in input?
built in input
oof, idk then
Not familiar with controllers, but whatever you use to detect switching to controller you can trigger the change from there.
so do u know how to detect it
You are the one who's implementing it
In old system Input Manager sets up all the buttons including for controllers. You are the one writing code to take input from them, Your code decides where to allow input from controller. When you do that, then you switch button labels.
does this work
if(Input.GetKeyDown(KeyCode.anyjoystickkey))
test it with debug log
How Can i Click a Button on UI with GamePad in old input system ?
For Example Press Start To Ready
you want a click and a gamepad button press?
I want to Click on a Button when i press "X" on my Controller
Without The Button Selected
I guess you could make a script with a public enum, the enum is the text of the button, and you set the name in the inspector so each button litsens for a button press and when the button is pressed then execute the onclick function
To visualize you need to send click event manually for triggering from code. https://answers.unity.com/questions/945299/how-to-trigger-a-button-click-from-script.html
Ty Both of you...
I think my issue is very similar. I have a full screen button with "touch to start" text on my intro screen. when a gamepad is detected it changes to "push any button to start" i'm not quite sure how to detect "any button" to load the next scene though
How can I get the current device connected to the InputSystem ?
Input System basically gives me a random value every time i press WASD
i have no idea where i've gone wrong
lemme try and get a recording
showing the code and the settings for the input action(s) would be good too
nvm it's because i'm stupid 🥰
if anyone gets this issue it was because i had multiplied it by Time.deltaTime or something
Mouse input?
ik that's vague and you're meant to do that anyway but just like get the raw input data before you scale it to each frame
OK I KNOW IT NOW
i was multiplying by Time.deltaTime within the OnMove() function which made it scale to the frame where you started pressing the button instead of whatever frame it's currently processing
good explanation
Is there a way to find the current device (Keyboard or Gamepad) other than with the onDeviceChange event ?
hey folks, how is the input system in 2020.1.36? it used to hit performance real bad on the switch in earlier versions
the new input system is way more performant than the old one. i can't remember any time where it would perform even close to as bad as the old one
Hi, does someone already use the new Input System with phidget HID? I have a PhidgetInterfaceKit 8/8/8. The input work well with previous input system and phidget .net lib but with the new input system, the input system already steal the control.
If i follow the HID support guide https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/HID.html from unity I'm not able to use the Auto-generated layout, inputs are not detected as GenericDesktop/Joystick, GenericDesktop/Gamepad or GenericDesktop/MultiAxisController.
If if override the HID fallback it's the same. I chek with the InputDebug, even if the device is mounted on the debug view I can't see any change in the value colomn.
When I declare a new input action and use the Listen option to detect input nothing happen if I press a button.
Hello, I have a simple question, what is the equvilent of Input.GetKey? I've been subscribing to .preformed but it only registers once and I tried looking on the net and I could only find solutions with using bools and I just wanna ask if there is a simpler way to do it?
How can i Change Mouse Sensitivity in New Input System
I want to Control it with a Slider
it's not something you do at the input system level. you do it at your script level
Hello, i'm making an SMG with hold button to shoot for my FPS today. And as you can see in the pic, i've been using bool to check button hold for thing like "Crouch". But problem is that i have to process the _isAutoShoot and PlayerShoot at different places, which i don't find very convenient. Any other way to do "Hold to shoot" with Unity Input system?
Is there a way to know what binding triggered the action? You can press any key from 0 to 9 to select some characters but I don't want to make individual actions for each
Whelps, found the solution right after posting. Should have google harder, lol.
This returns a error in the console reading NullReferenceException: Object reference not set to an instance of an object
PlayerController.OnEnable () (at Assets/Controls stuff/PlayerController.cs:31). I'm not sure why, any possible solutions ?
you never assigned it to anything...
Controls input < this creates a variable called "input" which starts out as null
input.Enable() < You are trying to enable null, which is an error
you forgot to initialize it
Yeah that was it thanks, i had it initiazed before but i didnt realise i had to put it into the awake method
Sorry i might have another dumb question but is it normal for a button tap to always return a 0 or False
wdym?
The scripts I've been using with pointer events and buttons stopped working while I was trying new workflows with new Input system, I have an Input Manager to check UI collision on mouse pointer and It detects the collision, but the pointer events not working anyway. Could anybody help me?
do you have an event system in the scene?
graphic raycaster on the canvas?
Yep here is my event system
and raycaster
Strange thing is, this method detects the UI objects
So it can't be about the collision etc. , I suppose?
I'm restarting Unity rn.
what doesn't it detect?
or sorry - what part isn't working?
The scripts which uses Pointer events like these.
Also, Built-in UI Buttons(I think they also use pointer events)
and what specifically is happening? The callbacks aren't running at all?
Yeah, the interfaces don't get triggered.
How can i get a input to return to a default bool value
I figured it out, It was about these settings all along.
Hi guys, so I am wondering if it is possible to use scroll as select to trigger certain event
Also is it possible to add KeyCode to select the event instead of using mouse click
Now I am using Select, but I want to use a keyboard key to replace it
The value of ModifierBool remains True after its pressed, is it possible to get this to reset to a false after each press.
really!? in 2020.1.17 the new ones showed up whereas the old one didn't
Guys. I need the lantern from anyone with experience with the input system. I'm trying to figure out how people switch between just one player input and the player input manager
I have a simple main title menu. I use a player input on the main menu object to control input and navigate through it. So far simple and works well. Then when creating a new game, I switch a GO on to activate the interface for joining the game... So I deactivate the other player input first so it does not interfere with the PIM. This does work and all
However, After that, I'd like however was the first player to get the control of the menu and disabled the PIM. This is where I'm confused on how to go about it
I haven't found anything to "Take the Player input" I got from the PIM and set it on the mainMenu input so the player 1 will be the one with control from now on
Player Input doesn't seems to have anything that I can assign a specific controller to it or anything
subscribe to the canceled event too
anyone know why whenever I move a slider on my scene another slider is the one that is moving?
Any idea why I can't create a linux building referencing InputSystem.Switch even though it says on the package site that it's supported?
I get error CS0234: The type or namespace name 'Switch' does not exist in the namespace 'UnityEngine.InputSystem' (are you missing an assembly reference?)