#🖱️┃input-system

1 messages · Page 63 of 1

barren dust
#

@austere grotto Your suggestions worked great, thanks very much.

manic dirge
#

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.

barren dust
#

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?"

jagged wyvern
#

yea

#

InputSystem.onActionChange += (obj, change) =>

barren dust
#

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.

barren dust
#

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.

mighty ivy
#

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

flint snow
#

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?

left quarry
#
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

austere grotto
left quarry
#

It should check each weapon one at a time and if the binding is pressed shoot that one

austere grotto
#

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

left quarry
#

Is there a better way to do it?

austere grotto
#

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?

austere grotto
left quarry
#

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

austere grotto
#

This might be the hackiest way of using the new input system I've seen yet.

left quarry
#

wdym by that lmao

austere grotto
#

dealing directly with Controls instead of Input Actions

left quarry
#

Yeah, I think that you usually use the old system for that but that wasn't working nicely with my specific need

foggy ginkgo
#

you can make that in seconds yourself

visual ermine
#

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

timid flare
#

Does anyone know a good asset to use to have a remap menu ingame?

tame phoenix
#

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

tame phoenix
austere grotto
#

best you can do is work on the performance of your game and make sure you're reaching the highest possible framerate

sour drum
#

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

deep grove
#

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.

twilit sapphire
#

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

brazen gale
#

hey im in the input settings

#

whats the word for

#

ctrl?

#

like is it control

#

or..?

bold jackal
#

or alternatively you can press the listen button

patent tartan
#

How do you guys typically handle input within a state machine? In a separate script or within each state?

deep grove
stark notch
#

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

undone imp
#

Hello! Did someone update to 1.4.1 and W,AS,D keys stopped working in a axis binding?

bold jackal
#

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

austere grotto
stark notch
#

yeah i found it

austere grotto
#

Pardon the pun

bold jackal
bold jackal
austere grotto
bold jackal
#

you can call a method in another method?

#

what's the syntax for that?

austere grotto
#

Of course...

#

That's the only way to call a method

bold jackal
#

true lol

austere grotto
#

MethodName();

bold jackal
#

doesn't work

#

needs parameters from input system

#

actually wait

austere grotto
#

Huh

#

You didn't share the whole method

bold jackal
austere grotto
#

So I assumed it was a regular method

#

With no parameters

bold jackal
#

my bad

austere grotto
#

Just get rid of the parameter

#

This is something you'd call yourself

#

Not something you'd call as a callback

bold jackal
#

I can't get rid of the parameter in the method

austere grotto
#

Why not

bold jackal
austere grotto
#

What's the run action supposed to do

bold jackal
#

this is in the Start() function

austere grotto
#

You have confused some stuff here

bold jackal
#

Handle movement and friction

austere grotto
#

All of that should just be in FixedUpdate

#

Why do you want to bind it to input

bold jackal
#

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

austere grotto
#

None of that seems relevant to input

bold jackal
#

otherwise I would do it a different way which is what I had before, without functions

#

hmm

#

hold on

bold jackal
#

and it works magically

austere grotto
#

Yeah

#

Because like I said that part doesn't make sense

bold jackal
#

ahh alright thanks

halcyon lagoon
#

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

austere grotto
#

What arrows, and what command?

halcyon lagoon
#

UpArrow , DownArrow ....

#

if (Input.GetKey(KeyCode.UpArrow) & Input.GetKey(KeyCode.DownArrow) & Input.GetKey(KeyCode.LeftArrow) & Input.GetKey(KeyCode.rightArrow))
{
print("...");
}

austere grotto
#

That will print if you press them all the same time

halcyon lagoon
#

Yea

#

But I want it to activate when I click on them but not at the same time

austere grotto
#

You'd have to put the keycodes in a List and keep track of which one you're listening for next

austere grotto
#

I'm not going to hold your hand through it

halcyon lagoon
#

UnityChanBugged .

#

if (Input.GetKey(KeyCode.UpArrow) | Input.GetKey(KeyCode.DownArrow) | Input.GetKey(KeyCode.LeftArrow) | Input.GetKey(KeyCode.rightArrow))
{
Count += 1;
}

#

If (Count == 4) {
print("....");
}

halcyon lagoon
#

Nvm , I solved it

proud tangle
#

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?

prisma vapor
#
  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

prisma vapor
proud tangle
#

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

dusty hemlock
dusty hemlock
mental musk
#

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

mortal ridge
torpid saddle
#

My friend is trying to make a hotkey menu but it isn't working for him

austere grotto
#

Without sharing some details, hard to help

torpid saddle
austere grotto
#

details, as in code, etc.. Why am I getting screenshots from a discord chat

torpid saddle
#

For a better explanation from his cuz he didn't explain it that well the first time lol

torpid saddle
#

So its just the default scripts

mental musk
main tangle
#

hello how can i make my button prompts change when i use a different input system like a controller

jagged wyvern
#

yes

zinc stump
main tangle
#

i dont use text i use iamges that pre made for every input system

zinc stump
#

same thing, initialize them with other images

main tangle
#

ok

jagged wyvern
#

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

main tangle
jagged wyvern
#

player input component

main tangle
#

yeah i cant find it

jagged wyvern
#

you have the package or just built in input?

main tangle
#

built in input

jagged wyvern
#

oof, idk then

main tangle
zinc stump
#

Not familiar with controllers, but whatever you use to detect switching to controller you can trigger the change from there.

main tangle
#

so do u know how to detect it

zinc stump
#

You are the one who's implementing it

main tangle
#

im a beginner

#

ok i look up a tutorial

zinc stump
#

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.

main tangle
#

does this work
if(Input.GetKeyDown(KeyCode.anyjoystickkey))

jagged wyvern
#

test it with debug log

sly frost
#

How Can i Click a Button on UI with GamePad in old input system ?

#

For Example Press Start To Ready

jagged wyvern
#

you want a click and a gamepad button press?

sly frost
#

I want to Click on a Button when i press "X" on my Controller

#

Without The Button Selected

jagged wyvern
#

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

zinc stump
sly frost
#

Ty Both of you...

dry olive
#

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

vale flame
#

How can I get the current device connected to the InputSystem ?

vagrant whale
#

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

austere grotto
vagrant whale
#

nvm it's because i'm stupid 🥰

#

if anyone gets this issue it was because i had multiplied it by Time.deltaTime or something

austere grotto
#

Mouse input?

vagrant whale
#

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

austere grotto
#

good explanation

vale flame
#

Is there a way to find the current device (Keyboard or Gamepad) other than with the onDeviceChange event ?

full forge
#

hey folks, how is the input system in 2020.1.36? it used to hit performance real bad on the switch in earlier versions

mortal ridge
rugged breach
#

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.

minor eagle
#

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?

sly frost
#

How can i Change Mouse Sensitivity in New Input System

#

I want to Control it with a Slider

austere grotto
deep grove
#

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?

scenic ferry
#

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

deep grove
#

Whelps, found the solution right after posting. Should have google harder, lol.

static mauve
#

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 ?

austere grotto
#

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

static mauve
#

Yeah that was it thanks, i had it initiazed before but i didnt realise i had to put it into the awake method

static mauve
#

Sorry i might have another dumb question but is it normal for a button tap to always return a 0 or False

dawn sapphire
#

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?

austere grotto
#

graphic raycaster on the canvas?

dawn sapphire
#

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.

austere grotto
#

or sorry - what part isn't working?

dawn sapphire
#

Also, Built-in UI Buttons(I think they also use pointer events)

austere grotto
dawn sapphire
static mauve
#

How can i get a input to return to a default bool value

dawn sapphire
tame oracle
#

Hi guys, so I am wondering if it is possible to use scroll as select to trigger certain event

tame oracle
#

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

static mauve
#

The value of ModifierBool remains True after its pressed, is it possible to get this to reset to a false after each press.

full forge
limber axle
#

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

austere grotto
fallen minnow
#

anyone know why whenever I move a slider on my scene another slider is the one that is moving?

vocal jay
#

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?)