#🖱️┃input-system

1 messages · Page 13 of 1

viral orchid
#

check what lang your keyboard is in???

#

in windows

#

its a long shot

mental jackal
#

its English (US)

viral orchid
#

mine works lemme see what it looks like rq

#

go edit/project settings/input manager/ check the box for 'Use Physical Keys" see if it works

fallen charm
#

self and def dont exist as options

mental jackal
#

where would use physical keys be?

viral orchid
#

oops ive made a mistake. im using the old one

#

sorry about that

mental jackal
#

ohh all good

#

im using 2020.3.24f1 if that helps

viral orchid
#

no its not the unity version its the input system package version thats the reason ours are different i think?

mental jackal
#

oh i see

#

so should i update it?

#

or

viral orchid
#

ive got the old one

mental jackal
#

so should I change it to na older version?

viral orchid
#

your version should be fine. im using something similar for my game:

using UnityEngine;

public class PlayerMovement2 : MonoBehaviour
{
private CharacterController2D controller;
private float moveSpeed = 5f;
private bool jump = false;

private void Awake()
{
    controller = GetComponent<CharacterController2D>();
}

private void Update()
{
    float move = Input.GetAxis("Horizontal") * moveSpeed;
    jump = Input.GetButtonDown("Jump");

    controller.Move(move, jump);
}

}

#

just copy my code and pray it works lol

mental jackal
#

alright

viral orchid
#

oh wait you dont have controller

mental jackal
#

ohyea

viral orchid
#

or do you

mental jackal
#

im using keyboard

viral orchid
#

you can use my code only if you are using a character controller

mental jackal
#

ohhh

#

i should mention one thing

#

im using 3d aswell

#

sorry for not mentioning earlier

viral orchid
#

oh im in 2d. just find a script online for player movement so you can work on something more interesting

#

google 'player movement script unity'

#

modify it to your liking after it works

mental jackal
#

yeah thats what i did, I followed a youtube video and I got to this point, but the movement inputs just seem to be flipped

#

its odd because when i originally launched unity, there was literally 0 inputs in the input manager so I had to set it to default

viral orchid
#

so your input horizontal is making you jump and input vertical is making you move side to side

#

bruh your player object might be rotated 90 degrees

mental jackal
#

OHHHH

#

Im totally unsure why

#

but

#

it wasnt rotated at all

#

but rotating it 90 degrees fixed it??

viral orchid
#

big win

mental jackal
#

yeah

#

ty for the help though!

#

i was losing my mind lmao

viral orchid
#

ok now you can stop worrying about this crap

#

yw

restive grove
#

hey guys, I'm trying to code a game that basically involves moving sprites and snapping them into specific locations on the screen. I got the functionality to work so that I can hold down the left mouse button on an object, drag it to move it around, and let go of the left mouse button to put it down, but I can't quite figure out how to get it to snap into position. I have a function I'm working on that somewhat works, but the problem is it snaps both the goal position and object into the center of the screen immediately on start and I'm unable to move the object again (it's still trying to select the object in the inspector though). Here's a link to the code I'm currently working with --> https://gdl.space/utecorodet.cs. If anyone can help or give advce I'd greatly appreciate it!

fair mason
#

ah the input debugger has this

pulsar cloud
#

Hello ! (i know this is a frequently asked question but i tried so many things that didnt workd) This is a very simple error but i cant get it to work.. Basically, my inputs work on the editor but when i build they dont work anymore.. and thats it. I dont have build error or anything btw.

austere grotto
pulsar cloud
#

there are no errors, it says

austere grotto
#

Add logs where you subscribe to the inputs and logs where you use them

pulsar cloud
#

on my player i have the movement script and i have the player input action component aswell, and the mode is "Send messages" so the in my code i do something like "OnRightClick()" and when i right click it call this method

#

so i dont have subscriptions to the inputs etc..

half swift
#

so im here now @supple crow @turbid olive (sorry for the ping

pseudo dirge
#

heyo i have the same problem can you say how you solved it?

patent lark
pseudo dirge
#

thank you :))

restive grove
tight nebula
#

i know very little, as i'm just getting started, but that's what i would do, or if you're deep into game development , but you are pretty set, you can do something where like if it's every 7 units do something like

if (pos %7 != 0) {
  position -= pos%7;
}

or something akin to it

tight nebula
#

just thinking about it, what i would do depending on your system is have the xyz, then based on an imput lerp from a to b with an animation or whatever you want. then also set some gate where it can't be changed again until that value is reached. ie

eventCalledFromInput() {
  if (player.worldlocation == desiredLocation) {
    changeLocation() {
      desiredLocation = logic();
    }
  }
  else {
    alert("you can't do that dummy!")
  }
}
tight nebula
#

(no idea with the above sorry)

i'm having an issue currently trying to grasp the new input system. for some reason if a key is reset back to 0, it doesn't trigger a call unless another one is being activated.

ie, if i press w and let it go, this code will think w is still pressed, does anyone maybe know why?

#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;

public class Test : MonoBehaviour
{
    //public InputAction playerControls;
    private TestPlayerInput input; 
    public Rigidbody rb;
    
    [SerializeField] private byte movementSpeed = 1;
    [SerializeField] private byte usrLookSensitivity = 2;

    private Vector2 moveDirection;
    private float moveDirectionX;
    private float moveDirectionY;

    
    
    private void Awake()
    {
        input = new TestPlayerInput();
    }

    
    
    private void OnEnable()
    {
        input.Enable();
    }

    
    
    private void OnDestroy()
    {
        input.Disable();
    }

    
    
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("test.cs loaded");
    } 

    
    
    // Update is called once per frame
    void Update()
    {
        //this calls the fuction assigned to get value each time the input changes
        input.Player.Move.performed += MovementValues;
    }
    
    
    
    void MovementValues(InputAction.CallbackContext value)
    {
        Debug.Log(value.ReadValue<Vector2>());
        Vector2 movement = value.ReadValue<Vector2>();
        moveDirectionX = movement.x;
        moveDirectionY = movement.y;

        if (moveDirectionX == 0 && moveDirectionY == 0)
        {
            moveDirectionX = 0;
            moveDirectionY = 0;
        }
    }

    
    
    private void FixedUpdate()
    {
        rb.velocity = new Vector3(
            (moveDirectionX * movementSpeed),
            0,
            (moveDirectionY * movementSpeed)
        );
        
        Debug.Log(rb.velocity = new Vector3(
            rb.velocity.x + (moveDirectionX * movementSpeed),
            rb.velocity.y + 0,
            rb.velocity.z + (moveDirectionY * movementSpeed)
        ));
    } 
}
tight nebula
#

got it, it's because i needed to add:

input.Player.Move.cancelled += MovementValues;
sly oak
# restive grove hey guys, I'm trying to code a game that basically involves moving sprites and s...

This is a basic gameplay but seems like you are overcomplicating it a bit rather than laying the foundation.
For snapping stuff to locations most basic approach would be to code a grid of [n x m] where each cell would denote a position. Upon hovering your item over this area you can distance check each position (or use colliders/overlap queries whatever fits) and upon releasing you can set the position to the value present in grid, cell size must be > (the largest item on your grid) just so that they can be arranged easily.
At last simply scale grid to screen or vice versa.

Checkout codemonkey's grid implementation, It would be a good start for you!

restive grove
violet hazel
#

Have you tried turning off code stripping? Or added a [Preserve] attribute on the methods so they don't get stripped?

dawn pebble
#

not sure whats going on, but I'm having a weird issue
heres my basic rotation code (in FixedUpdate):

float mouseX = Input.GetAxisRaw("Mouse Y") * -lookSpeed;
float mouseY = Input.GetAxis("Mouse X") * lookSpeed;
float roll = Input.GetAxis("Roll") * rollSpeed;
gameObject.transform.Rotate(mouseX, mouseY, roll);

float angle = Quaternion.Angle(transform.rotation, prevQuat);
if(angle > 12f)
    Debug.Log("dx: "+Mathf.Abs(mouseX-prevX)+", dy: "+Mathf.Abs(mouseX-prevY)+", dr: "+Mathf.Abs(mouseX-prevR)+"\ndangle: "+angle);
prevX = mouseX; prevY = mouseY; prevR = roll; prevQuat = transform.rotation;

my problem is for 4-5 frames in a row randomly MouseX or MouseY will be unreasonably high and not change. heres an example of the problematic output:

#

is this likely a unity problem or is my mouse just broken? I dont seem to get any unusual mouse input anywhere else

sly oak
austere grotto
#

That just means FixedUpdate ran 4 times that frame

#

You absolutely only want to read mouse input in Update

#

If you need to consume it in FixedUpdate the appropriate technique is to accumulate it in Update and consume it in FixedUpdate

#

simple example @dawn pebble

Vector2 accumulatedMouseDelta = Vector2.zero;

void Update() {
  Vector2 mouseInput = new(Input.GetAxisRaw("Mouse X"), GetAxisRaw("Mouse Y"));
  accumulatedMouseDelta += mouseInput; // accumulate mouse input
}

void FixedUpdate() {
  Vector2 mouseDelta = accumulatedMouseDelta; // copy the mouse delta
  accumulatedMouseDelta = Vector2.zero; // zero it out so it's "consumed"

  // use accumulated delta here
  transform.Rotate(mouseDelta.x, mouseDelta.y, roll);
}```
dawn pebble
#

I was thinking fixedupdate since my movement is going to be physics based

#

but it reading input multiple times makes sense

austere grotto
#

Also since you're just using transform.Rotate, which is teleportation as far as the physics engine is concerned, you could also skip this complexity and just call Rotate directly in Update

#

This complexity would make more sense if you used Rigidbody.MoveRotation for example

dawn pebble
#

im planning on using a torque system, I just left it simple while I work on other mechanics

austere grotto
#

Then yes -- accumulate/consume is an appropriate pattern for handling torque from mouse input

rare patrol
#

Does anyone have any knowledge or resources on how to support HOTAS setups with the new input system? I'm making a VR cockpit game and would like to support HOTAS as an optional way to control the ingame joysticks and throttle. Joystick input seems pretty straightforward in the input bindings (see pic) but there doesn't seem to be an existing binding for a single-axis throttle input, or a twist input for the joystick. Am I missing some way to create your own bindings for stuff like this, or do I need to rely on users with HOTAS setups to interactively rebind the throttle control to match their hardware?

sly coyote
#

hey, I have problem with input system on phone, it's my code

using UnityEngine;
using UnityEngine.InputSystem.Controls;

public class Movement : MonoBehaviour
{
    private SimpleInput input = null;
    private Rigidbody2D rb = null;
    private float movespeed = 10f;

    private void Awake()
    {
        input = new SimpleInput();
        rb = GetComponent<Rigidbody2D>();
    }
    private void OnEnable()
    {
        input.Enable();
    }
    private void OnDisable()
    {
        input.Disable();
    }
    private void FixedUpdate()
    {   
        rb.velocity = input.Player.Movement.ReadValue<Vector2>() * movespeed;
    }
}
#

and tthis game pad can move, but he isn't work

austere grotto
#

Seems ok. Use debug.log to see what the input data is reading?

sly coyote
#

ok i'm idiot xDD

crimson schooner
#

Appreciated

frosty quartz
#

!code

sonic sageBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

frosty quartz
#

im having trouble with some code. im following a youtube tutorial. it's specifically making me open unity in safe mode and giving me the console error of "Assets/scripts/MovementStateManager.cs(49,10): error CS0102: The type 'MovementStateManager' already contains a definition for 'Gravity'" heres the code https://hastebin.com/share/qisijokawu.csharp

austere grotto
#

You have a field named Gravity and a method named Gravity

#

They can't have the same name

frosty quartz
#

gotcha, i wasnt sure what it meant

#

understood

#

it was two capital letters

austere grotto
#

It's the fact that you used the exact same name for both things. Making one capital and one not just means you are giving them different names, since C# is case sensitive

frosty quartz
#

yeah

fallen charm
#

So I have a question. Is it really bad to have input relating things in update methods?

#

I swear guides online always gaslight me

#

this one says not to do input in update methods, but then how else do you do actions where you hold down the button? (Like for example a rapid fire gun)

austere grotto
cloud epoch
#

Hello there 👋
I'm not sure if that's the right channel, but I'm facing a problem regarding UI Toolkit's text field.
Although my keyboard is connected, and is detected for any other inputs from my game, it seems to not be detected by the text fields. Do you guys know how can I fix that?
I can actully select the field, but when I write something, nothing is actually writing

Update: When I change the current value via code, I can remove chars (select, etc...) but cannot add any

sly oak
# fallen charm this one says not to do input in update methods, but then how else do you do act...

Gave it a read and here are my two bits if it helps anyway.

Most probably they refer to physics simulated game where it is absolutely necessary for input - dependent simulation to occur before update as physics step isnt tied to frame Update. However using .IsPressed for button types usually breaks the point of adding interactors processors and modifiers so I find .WasPerformedThisFrame() better, Still exploring this part btw.

Might be a long shot but Ig the term Input Processing is also ambiguous between The 'processors' which one can embed in the binding compared to actually process the input. Since 'processors' are part of the state of Input, Its better to embed them with actions in action map compared to executing them 'Updates()'.

In the end there is no perfect solution or silver bullet. Play with it look what works for you and decide. Check out samples as they provide a greater context for dealing with different situations, samyam on yt is also a decent resource for overview of different aspects.

heavy grotto
#

I was trying to use Netcode for GameObjects together with the new input system, but realized that would not be possible because the first prefab created is the only one whose inputs are detected by the event system.
Is there any way for me to try and make this work?

glass abyss
#

I started a new vr project in 2022.3.1 and the input binding window is broken, has anyone seen this before?

heavy grotto
#

I think Unity's dark mode is broken in the Input System UI

glass abyss
#

hmm, I haven't had any problems with it previously, is this a new thing?

heavy grotto
#

I think so

#

When Codemonkey made a video on the new Input System, that didn't happen and he had light mode on, but on mine I get the same thing as you and every time I open that menu I get a warning realated with the dark mode

#

try switching to light mode I guess

glass abyss
#

it looks like right click the items works so at least I can work around it

#

changed theme and restarted but no change

#

but yeah I see the warning "Unable to find style 'ToolbarSeachTextField' in skin 'DarkSkin' Used"

#

looks like maybe someone misspelt that

heavy grotto
stark acorn
#

Having a curious issue on Steam Deck, the input debugger reports the **Select **and **Start **buttons as **swapped **(testing through remote input debug at runtime) and indeed they are!

This happens both while using the Steam Deck's built in controller, as well as any external XInput controllers. Windows build, run through Proton.

Testing the same Xbox controller on my windows desktop and it reports the *correct *button mapping.

I think this used to work correctly, perhaps a couple versions ago? Has anyone else experienced similar mapping issues?

stark acorn
#

Hmm alright, seems to be a bug in Input System. I've imported the "Visualizers" sample in a new project in Unity 2022.3.2f1, built the "GamepadVisualizer" as a windows app and there too, Select and Start are swapped on Steam Deck using XInputControllerWindows.

#

I mean, it matches the layout displayed here 😛 just no controller has that layout

#

(Start should be on the right)

#

aha!
windows build through proton: swapped ⭕
native linux build: correct ✅

summer marten
#

Hi,
I want to build an UI Selection System where I have a stack of selections. That way, if an Event was not consumed by the "currentSelectedGameObject", it can search for a Listener further down the stack. I also want to add additional Navigation events for paging through menus with LT and LR. Because I can't find a clean way to implement these features with the "InputSystemUIInputModule" (new InputSystem), I'm thinking about building my own UI InputModule so I have total freedom on how I want my Inputs from the InputSystem to be converted to UI Events.
However this InputModule is a REALLY complex class and I don't know if this is the right move. On the other Hand this class needs to handle a LOT of usecases like AR, Mobile, etc. For me it would only be Mouse and Controller so it might not be so bad.
Has somebody had experience with building their own implementation of BaseInputModule? How paintful is it? 😄

river sandal
#

Hey Guys! Quick Question... With the new InputSystem and "Send Messages" - i easily receive a Button press in my script with OnButtonPress(InputValue value). I would now like to get the actual key that was pressed - a string of "a" for example when button "a" was pressed... Can not wrap my head around and can not find a solution anywhere

austere grotto
#

A few notes to unpack here:

  • Typically each significant "button" you can press in the game should be its own input action. If you have other buttons that do the same thing, they can be bound to the same action, but if you have buttons that do different things, they should be bound to different actions This is how the input system was designed and this is what will be the most straightforward and supported way to work
  • SendMessages mode is quite limited, only giving you an InputValue, which barely has any information in it. Other modes of operation such as UnityEvents mode will give you a CallbackContext which contains a lot more information.
barren mantle
#

How do I specify which mouse button in a 'pointer down' event on an event trigger? I need to deactivate an object from that event but only if the left button is clicked

barren mantle
#

Also, when I call a method on that click event and use Input.GetMouseButtonDown(0) the condition still read as true when I click the right mouse button, so I can't seem to return early. Is there utterly no distinction between different mouse buttons in the "on pointer down" event?

#

That seems ridiculous so I must be missing something

#

Why would Input.GetMouseButtonDown(0) return true on right click?? It works completely normally in every other use case but this one?

austere grotto
barren mantle
barren mantle
austere grotto
#

It should have been a parameter in the first place

#

And it comes from the event

#

Well actually EventTrigger uses BaseEventData

#

You need to cast it to PointerEventData

#

You also need to properly assign it in the EventTrigger inspector with the dynamic parameter

barren mantle
#

The problem is that I'm trying to trigger the player inventory object to disable, but that object doesn't have it's own raycast target, so I was sending a message from a background object, which does have a raycast target, to the ScreenGroup class attached to the inventory screen group.

#

So I was specifying the object and method to target, then I tried using IPointerDown handler and it made every UI element in the inventory object close the inventory instead of only the background bc every child counts as the parent's raycast target

#

I need to deactivate the parent of the background object when it's clicked, or somehow stop or allow only specific children from triggering the inventory screen group's event

#

Or I could just quit with the event system and just create a new class for the screen background objects

urban tide
#

Hi, I need help! I'm implementing mobile-support for my camera controller but these scripts for some reason do not support multitouch.

I want to make it so that touching the touchpad with another finger "overrides" the input but the input stays on the other finger that touched first which isn't really "multitouch-worthy"

https://pastebin.com/HKEz6cn6

If you want to see what I mean please test my prototype https://drive.google.com/file/d/134HDj5Z_gMCwcr8to8yyhJhW_iU68kTR/view?usp=drivesdk

How to reproduce the problem:

  • Use your first finger to touch the dedicated touchpad that covers the entire right side of the screen (this works)
  • Use your second finger to again, touch the touchpad, but this in any way does not add nor override to the input created by your first finger

Why this is an issue - players are going to have unique and intricate button layouts, and there will be moments where they'll touch buttons on the right side and then attempt to aim using multiple fingers, however with the current issue I'm facing this will not work as intended. The "aim" input will simultaneously overlap with the button input and using another finger in an attempt to aim on another spot of the touchpad will not work.

https://cdn.discordapp.com/attachments/726882388646428824/1119083180931162112/SVID_20230616_095618_1.mp4

timid dagger
#

My DuakShock4 is being detected as both DualShock4GamepadHID and XInputControllerWindows, which leads to having all inputs being doubled and being interpreted as 2 different kinds of gamepads. Other people who tested the build had the same problem. Unity version: 2022.2.0f1, Input System 1.4.4. The problem also seems to appear on Unity Version 2022.3.2f1 and Input System 1.6.1. Any ideas on what to do to get rid of the wrong gamepad detection?

shrewd hare
#

Hi I was coding the initial stuffs like player input and after some test I've been wondering if someone knows the default speed

austere grotto
#

Wdym by default speed?

shrewd hare
#

transform.Translate(Vector3.right * Time.deltaTime * rightInput);
It moves kinda slow for what I'm planning and I was wondering how many units the charcater/player makes per second

austere grotto
#

You're typically expected to multiply your own speed variable in.

#

Typically everything will be normalized to 0-1

#

So I guess the answer to your question is 1

shrewd hare
#

rightInput = Input.GetAxis("Horizontal")

austere grotto
#

Yes read the docs for GetAxis

#

It returns -1 to 1

shrewd hare
urban tide
#

Can I get the raw mouse vector2 input in the new input system?

sly oak
river sail
#

does anyone know how to get the left joystick from a 3ds in unity 5.6.5f1? im trying to remake a game for the 3ds but i just cant get access to the joystick.

versed plover
#

Does someone know how to move the Canvas so the mobile screen can move with drag detection?
When using drag detection it need to move over the gridmanager, but the 3 black boxes need to stay at the same place

cosmic saffron
#

hi, i heard the new input system has or had performance problems with quest. Do you know if that's true, or if so, if something was fixed there?

tame oracle
#

I have a button that calls StartRebind in this code when clicked: https://hatebin.com/jriszvprqj
but I get the following error when trying to re-enable the inputAction:

#

I'm on version 1.6.1

pulsar sinew
#

HELP PLEASE: I want to simulate xr controller grip button press using new input system. Found out InputSystrm.QueueEvent(); can do it but i couldn't figure it out how to use this.

dusky olive
#

down here

tame oracle
lone python
#

Hello, when I connect my ps4 controller with USB all my commands works,
But when I connect it with bluetooth I can’t moove with y axis
Someone can help me please ?

tame oracle
tame oracle
quasi dove
#

Question:

1: How do I rebind Composite Buttons? For example, I'd like the player to be able bind either DPad or Left Trigger, depending on what they prefer in my rebind options. (Or WASD)

My current code is as follows:

public class RebindKey : MonoBehaviour {
    public GameObject rebindPrompt;
    public InputActionReference inputReference;

    private InputActionRebindingExtensions.RebindingOperation rebindingOperation;
    public string exclude;
    public string bindingGroup;

    public void DoRebind() {
        rebindPrompt.SetActive(true);

        rebindingOperation = inputReference.action.PerformInteractiveRebinding()
            .WithControlsExcluding(exclude)
            .WithCancelingThrough("<Keyboard>/escape")
            .OnMatchWaitForAnother(0.5f)
            .OnCancel(operation => SaveRebind())
            .OnComplete(operation => SaveRebind())
            .Start();
    }

    public void SaveRebind() {
        rebindingOperation.Dispose();
        rebindPrompt.SetActive(false);
    }
}

I'm also wondering:

2: How can I go about allowing for two inputs to one keybind via rebinding? I tried increasing the OnMatchWaitForAnother but that didn't seem to work.

tame oracle
#

not sure about multiple bindings though

worldly breach
#

Is it possible to do create custom bindings? Lets say I would want for keyboard and mouse have direction from center of screen to mouse cursor for a vec2 input for a Action.

surreal moth
#

What is the correct action type/value/binding for detecting the pressure value of a shoulder/trigger?

#

as in these things 🤔 unless I am mistaken and they're binary pushed/notpushed

#

the word 'Trigger' is used a lot for unrelated stuff like events so I am not finding the info I want online 🤔

#

Axis - Left Trigger perhaps?

quasi dove
#

I'm trying to enable the canceling of changing a Keybinding via

.WithCancelingThrough("*/{Cancel}")

However, even after rebinding Cancel to be Select on the controller, B still works...

Has anyone else ran into this isuse?

The end goal here is to hopefully have Select and Escape be Cancel buttons.

austere grotto
keen wave
#

Hey guys, I have a few questions about the new input system. I am trying create a rebind system that can allow for both primary and secondary/alternate input as well as bindings that allow for modifier keys such as: <shift> + <key> or <control> + <key>. I was wondering if it is possible to achieve these features with the new input system and if so, how would I go about adding them?

#

For reference, I am trying to get something similar to this:

quasi dove
surreal moth
#

low priority visual question, is there a way to re-arrange the events list so L and R are side by side? R got added later

austere grotto
keen wave
quasi dove
keen wave
#
Action primary secondary
Up     <W>      <Up Arrow>
Down   <S>      <Down Arrow>
Left   <A>      <Left Arrow>
Right  <D>      <Right Arrow>
#

Unity's tutorials tend to have one button/field for all mappings but I would like to separate them like above, would I still use composite bindings or would I define a primary and secondary map for each action?

quasi dove
#

Right so I'm just referring to the modifiers (Shift + Ctrl / Key) combo. Those are Composites still.

As for having a Secondary Map, you would just reference the actions other index instead.

So if you take a look at this screenshot:

action.bindings[0] would point to LeftStick
action.bindings[1] would point to the Comp of Kebyoard-Movement.
action.bindings[2] would point towards "UP"
action.bindings[6] would point towards Keyboard-MovementAlt

keen wave
#

Ah, thank you. This is what I've been looking for 🙂

quasi dove
#

I'm just figuring it out myself. You can do a recursive check in the OnComplete which will allow you to step over all the comp keys as well, so you dont have to have a rebind button for each indvidual key.

private void PerformRebinding(InputAction inAction, int inCurrentBindingIndex) {
        //Update display text

        rebindingOperation = inAction.PerformInteractiveRebinding()
            .WithCancelingThrough("<Keyboard>/escape")
            .WithTargetBinding(inCurrentBindingIndex)
            .OnMatchWaitForAnother(0.1f)
            .OnCancel(operation => OnCancel())
            .OnComplete(operation => OnComplete(inAction, inCurrentBindingIndex))
            .Start();
    }

    private void OnComplete(InputAction inAction, int inCurrentBindingIndex) {
        rebindingOperation.Dispose();
        inCurrentBindingIndex++;
        if (inCurrentBindingIndex < inAction.bindings.Count && inAction.bindings[inCurrentBindingIndex].isPartOfComposite) {
            PerformRebinding(inAction, inCurrentBindingIndex);
        } else {
            rebindPrompt.SetActive(false);
        }
    }
keen wave
#

Quick follow up question, how would you go about prompting the user if they try to bind a duplicate key or overriding the key. For example, if the player tries to bind "<W>" to another action then it will set "Up" to <unbound>?

quasi dove
#

Haven't figured that out yet tbh.

And truth be told, I'll probably just let the user have duplicate inputs. Personally, I hate games that stop users from doing that. I understand, maybe complications/issues but yeah lol

keen wave
#

Fair enough 😛

#

Thanks for your help 🙂

quasi dove
#

I saw it somewhere in the docs tho, so I know its possible to check.

I guess logically, OnComplete you could step through all actions and all bindings, and if it matches with what you just set, you just null it out.

#

At least thats what I'd probably do.

keen wave
#

When creating the rebind functionality, it seems that the UI is tighly coupled to the rebind system in most examples. As someone who is venturing into UI Toolkit, is there a way to apply separation of concerns between the rebind functionality and the UI itself? I was thinking of maybe using events on the rebind system but was wondering if anyone has some examples on how to keep the UI separate from the rebinding logic?

light birch
#

When I use Input.GetAxis(), it doesnt go 0, -1, 1, it fades. Can I change this?

#

I want it to only equal 0, -1 and 1

light birch
#

Now it just doesnt work

austere grotto
#

define "it doesn't work"

light birch
#

The value of Input.GetAxisRaw() for the horizontal and vertical axis stays at 0

austere grotto
light birch
#
void Update()
    {
        float x_axis_keys = Input.GetAxisRaw("Horizontal");
        float z_axis_keys = Input.GetAxisRaw("Vertical");

        Debug.Log(x_axis_keys);

        Wishdir = tr.forward * z_axis_keys + tr.right * x_axis_keys;
        //Normalize wishdir
        float len = Mathf.Sqrt(Wishdir.x * Wishdir.x + Wishdir.z * Wishdir.z);
        if(len == 0)
        {
            Wishdir = new Vector3(0, 0, 0);
        }
        else
        {
            Wishdir /= len;
        }
        

        tr.position += Wishdir * Time.deltaTime * MoveSpeed;
    }

Just the update method

#

I log the value to the console

#

and

austere grotto
light birch
#

I have no idea what happened, but its suddenly changing

#

So

#

Thanks

merry lotus
#

is there a UI bug in 2023.1.0f1?

merry lotus
#

it might rather be in the inputSystem package 1.6.1

#

just tried the 2022 lts editor and it's the same thing (with the same error)

#

and the inputSystem package 1.5.1 yield the same error (and UI weirdness)

tame oracle
#

Anyone have opinions and experiences on rewired vs input system?

stark notch
#

anyone else have a bug when making a control scheme and selecting the devices the left and right mouse button are switched?

stark notch
#

i have an issue right now with these control schemes it seems like for some reason left and right mouse clicks are switched around

#

I noticed more UI bugs with the inspector too

#

I don't know what they did but a lot of stuff from the UI seems to be changed and it has quite a few bugs still

surreal moth
#

I am having a problem with the input system and analog stick controllers. It stops calling the event if the value didn't change from the previous frame and I don't know why

#

is there something in here I need to change to fix this?

#

The vec2 value is being used to move a mesh but the mesh stutters and freezes constantly, but only when the I keep the analog stick completely still

austere grotto
#

performed will only be called when the value changes and is not 0

#

if you want to do something every frame don't use events, use Update

#

event-based input handling is better for a "button" style input, not for continuous input like movement

#

you can also just save the input value to a variable and keep using it in Update

#

either way you shouldn't be doing the movement itself in the input event handler

surreal moth
#

I used events in another project and this worked fine and since I don't have the option to make this ONE thing not use the invoke unity events bit, Ill try storing the vec2 like you said

surreal moth
#

Does this look right to you? 🤔

austere grotto
austere grotto
# surreal moth

I would just do:

inputDiection = context.ReadValue<Vector2>();``` and delete everything else
#

right now you're ignoring the performed phase

#

which is... most of the events you will get

surreal moth
#

hm okay, I put started/canceled in there because button presses fire when pushed AND when unpushed if you don't, but this isnt a button its an analog stick right 🤔

austere grotto
#

mhmm

#

in all 3 phases (canceled, started, performed) you will get new vector values

#

started is only going to happen when you go from the zero state to a nonzero state

#

and vice versa for canceled

#

performed you will get whenever there is any new value (you tilt the stick to any new nonzero position)

#

overall - you don't care about the phase

#

you really just care about the current direction of the stick

austere grotto
surreal moth
#

That did the trick, thanks for clearing that up!

worldly breach
#

How/where can I register my InputProcessor to be able to use my InputActions on the OnCreate of a System (DOTS)?

#

Seems like systems are created before RuntimeInitializeLoadType.BeforeSceneLoad

quasi dove
#

As of right I am using Gamepad.current to figure out which controller the user is using (EG: Xbox/Playstation/etc) however if I have two controllers plugged into my computer, Gamepad.current will return the first active one? I believe. EG: Using playstation controller to move, however Gamepad.current is returning xbox.

Whats the best way to go about fix this?

quasi dove
#

Also I'm trying to cancel a rebind with the following:

    .WithCancelingThrough("*/{Cancel}");

However, I'd like it to use Custom controls for the cancel, and not the default B button and Esc.

I tried the following:

    .WithCancelingThrough("*/{CancelRebind}");

where I set a rebind, however, that doesn't seem to work.

Thoughts?

glad crypt
#

Menu is bugged for me even after restart.

#

I cannot click any of the menus

rough urchin
#

Hey so i have a little Problem, if i write something with Input.touches it doesnt do it. Anything that has this in it for ex. Debug.log it, it doesnt do it and i didnt find anything about it(for mobile android)

supple crow
#

that is very vague.

#

we'll need to see your code, at the very least

supple crow
#

i remember someone else pointing out a typo in the source that was breaking that menu

upbeat fulcrum
#

I have been with this like 2 hours and still no solution... Two players must be connected with a shared keyboard and have different UIs for navigation. I have tried to subscribe to the move callback of the UIINputModule to handle some logic but the event is received for both players! I have tried tons of other stuff and nothing has still yet worked.. I can't also seem to get how to use the NavigationEvents from the MultiplayerEventSystem

austere grotto
upbeat fulcrum
#
//This event is called when keyboard is pressed and not when the correct player pressed a 
input.move.action.performed += OnMove;
austere grotto
#

you also need to make sure you have multiple control schemes set up

upbeat fulcrum
#

Yes! Totally set up!

#

In fact, the buttons do move separately. The problem is when using the move.action.performed callback

#

That callback is shared

#

But the navigation and the buttons are separated

#

That's the strangest part

#

Would you like some more images so you can see better the problem?

austere grotto
#

you're using the generated C# class

#

I don't know that it supports control schemes that way

quasi dove
upbeat fulcrum
#

I set player input when instantiating the InputSystemUIInputModule

austere grotto
upbeat fulcrum
#

:( But it0s not the actual asset it's the instantiated PlayerInput from when a player joins a game

austere grotto
#

I'm not sure how to use control schemes outside the context of the PlayerInput component

austere grotto
#

how else would you have the names input.move

upbeat fulcrum
#

It's the playerinputUimodule, which has those callbacks

austere grotto
#

why access it through the input module?

#

that's pointing at the asset file

#

not at the instance from the PlayerInput

#

access it through your playerinput

#
myPlayerInput.actions["UI/Move"].performed += OnMove;```
upbeat fulcrum
#

Also it's still strange to me why th InputSystemUIModule class on itself succesfully separates both players but not when using the same callback through code

austere grotto
#

why are you doing that

austere grotto
upbeat fulcrum
#

So a new button is shown correctly

austere grotto
upbeat fulcrum
#

I need to know the direction of the input, basically it's a customization menu where they can select multiple customizables

#

A bit like mario kart vehicle select

austere grotto
#

To do what with? Don't you get that behavior automatically with UI navigation?

upbeat fulcrum
#

Wait, are there scroll menus for that 🤡 ?

upbeat fulcrum
#

I'm dumb AF

#

This was not set, it was the control scheme

#

Not it works as it should

#

OMFG

#

I didn't save it last time

#

And it got lost

lone python
#

Please what are the name of d-pad buttons in the old input system ? Because i don’t understand what it is said on this image

austere grotto
#

you'd have to set up an axis for it in the input manager

lone python
#

But i don’t want to use them for movements, i want for them example that the up button open the menu and that the down button give healph

austere grotto
#

there's nothing forcing you to use the input for any specific purpose

lone python
#

The axis are for movements ?

lone python
#

I need to enter a button name in the imput manager to use them,

austere grotto
#

Pick whatever name you want

lone python
#

No i can’t it desapear if it is not the good name

#

For example on the ps4 controller the x button is named joystick button 1, but i don’t now the name of d-pad buttons

austere grotto
austere grotto
#

refer to the diagram

#

pick the axis

#

that's all

lone python
#

I put nothing in positive button and negative button ?

amber wigeon
#

is there a way to multiply the thumbstick x and y values? for an example: when thumbstick value is 0.5, then i will multiply it by 2x so it will be 1

austere grotto
amber wigeon
austere grotto
#

Or you wouldn't be able to read the data at all

#

Also I guess you could use the Scale processor if you really want the input system to do it for you

#

seems silly though

amber wigeon
#

wow

#

thanks

amber wigeon
austere grotto
#

you should simply have some kind of sensitivity/speed variable in your look/move script

#

show your code

amber wigeon
#

wait a second

amber wigeon
austere grotto
# amber wigeon
  1. You should never multiply mouse input by deltaTime
  2. your mouse sensitivity variable already exists, just set it in the inspector
#

definitely delete the input scale processor

amber wigeon
#

ok

amber wigeon
#

now my mouse is ultra fast (i need to set the sensivity to 0.1 to make it usable) and controller is like 5x times slower than my mouse

austere grotto
#

mouse sensitivity like that is expected especially if you have a high dpi mouse

amber wigeon
#

ok

amber wigeon
#

now my mouse isn't doing anything

austere grotto
#

the first line is overwritten by the second line

amber wigeon
#

should i create 2 scripts? first for mouse, second for controller

austere grotto
#

you probably would want two different sensitivity settings

#

basically you're doing:

int x = 6;
x = 5;``` and then saying "why isn't x 6?"
amber wigeon
#

oh i understand now

#

damn it's kinda difficult

worn willow
#

I'm in the process of creating a category system for my crafting UI but I don't know how to do it so that, for example, when I click on the Weapon category it shows me the recipes that have the Weapon enum selected on their scriptableobject.

austere grotto
worn willow
worn willow
#

asign the recipe to a category

austere grotto
#

the category should be a field on the SO

#

(for the item the recipe produces)

austere grotto
#

ok looks like you already have a category

#

so what's the issue

worn willow
worn willow
austere grotto
#
IEnumerable<RecipeData> weaponRecipes = allRecipes.Where(r => r.category == Category.Weapon);```
austere grotto
#

it's already in the category

worn willow
#

sorry it's the wrong channel

worn willow
austere grotto
#

e..g if (availableRecipes[i].category != currentlySHownCategory) continue;

#

just a simple if statement

#

or better yet

#

get only the correct recipes (as I showed above) and do the loop only on those

austere grotto
#

also it doesn't really look to me like your code editor is configured properly

steel breach
#

I defined a "keydown" action and assigned an "Any Key" binding. Is there a way to read which key was pressed? Should I use a different binding? Is there a way to do it without defining 26 actions for each key? I'd just like to get the pressed letter as a string if it's an alphanumeric for example?

solar orbit
#

is there any way to get vector2 (i guess) values on touchpad?
I can access clicks using this Debug.Log(DualShockGamepad.current.touchpadButton.ReadValue());

livid pelican
#

i can't for the life of me figure out how to use the right stick on my gamepad in the new input system

#

i have a "Move" and "Look" input actions. using "Left Stick [Gamepad]" works fine for Move, but using "Right Stick [Gamepad]" for Look doesn't.
i've tried with both xinput and directinput. neither works.

#

i've found some posts on the unity forums but niether was answered.

livid pelican
#

nevermind! i'm just still getting used to the messaging system, where you only get an update when the input state changes 😅

craggy oar
#

I can Rebind every key on my keyboard but i cant rebind the keys
a,c,r,l im on version 2021.2.14f1
this is the code i use any idea?

torn spoke
#

How can i change the Horizontal and Vertical inputs from player prefrences without making a custom
input axis system

#

in code obv

torn spoke
#

instead of W for forward havew G

austere grotto
# torn spoke instead of W for forward havew G

The legacy Input Manager doesn't support runtime rebinding. You either:

  • Make your own system using KeyCodes or something along those lines
  • Use Unity's new input system which does support runtime rebinding
  • Use a third party input library like Rewired
  • Build your own system from the ground up using Raw OS level input handling.
grim niche
#

Hey, do you by any chance still have that code? I wrote my own interaction script which does just that but it keeps stopping receiving Process calls when the button is held still, here's what I have 👀

public class RepeatWhenHeldInteraction : IInputInteraction
{
    public float repeatInterval = 0.2f;
    
    private double lastRepeatTime;

    public void Process(ref InputInteractionContext context)
    {
        if (context.ControlIsActuated())
        {
            if (!context.isStarted)
            {
                lastRepeatTime = context.time;
                context.PerformedAndStayStarted();
            }
            else if (context.time - lastRepeatTime >= repeatInterval)
            {
                lastRepeatTime += repeatInterval;
                context.PerformedAndStayStarted();
            }
        }
        else
        {
            context.Canceled();
        }
    }

    public void Reset()
    {
        
    }
}
#

I don't actually know if it's a problem with this exact script or some Input System setting that cuts off the updating of the interaction

grim niche
#

oh, I found some code on github and they subscribe to InputSystem.onAfterUpdate, that might solve the problem 🙂

torn spoke
austere grotto
livid pelican
#

still having some issues with the input system. i have a camera object and a player object, both with a Player Input component.

#

i think the issue is having multiple Player Input components?

#

i thought maybe having two action maps would fix it

austere grotto
livid pelican
#

oh yeah. sometimes input just stops working for one object. but reducing the number of objects with the player input component to one, the issue stops.

#

ive just begun porting my own input manager from C++. i like the way the new unity input system abstracts stuff, but its pretty confusing to get working properly. 😦

austere grotto
#

It should be one PlayerInput per person

#

and basically PlayerInput is going to pick one input device/control scheme and claim it

#

so if there's more PlayerInputs than devices matching a control scheme, generally the excess PIs are not going to work

livid pelican
#

i'd like to be able to use my input settings profile with callbacks like OnMove(), without having all the physical player restriction stuff.

austere grotto
#

I guess build a new middle layer that uses SendMessage?

#

IDK why you would want that though, the messaging approach is inflexible

livid pelican
#

less work, i suppose

#

but building a middle layer for that is even more work

#

i'll just use the legacy input system

austere grotto
#

and subscribing your class to it

#

definitely wouldn't recommend the old system

livid pelican
austere grotto
#

the link I gave above actually has a code example of the interface SetCallbacks approach which is what I'm recommending

livid pelican
#

the input manager i wrote for a separate project just has a map of strings to action structs, containing lists of things like keys, mouse buttons, and gamepad inputs that are considered to be part of that action. then you could get inputs either by float or bool with GetFloat()and GetDown()/GetPressed()/GetReleased(). it works nice, but isn't very flexible for more complex games. i might port over the system to unity eventually before i release my game.

pure cave
#

Hello. Anytime I start a new 2D project and create a simple script to move the player left and right along the x axis, once I play the scene the player object automatically moves to the left of the screen. I an barely resist it using the D key. It's doing that in all of my projects. I've tried using transform to move, applying force to 2D rigidbody attached to the player object. I've deleted and reinstalled Unity. I've just started with Unity and I'm losing hope.

golden mica
silver shell
#

When I connect a DUALSHOCK4 controller, two controllers are registered, a DUALSHOCK4 and a XinpurController.
Is this a bug in Unity?
What can I do to resolve this?
The version of Unity I am using is 2022.3.0 and the version of InputSystem is 1.5.1.

native perch
#
    public bool PlayerJumped()
    {
        return playerControls.Player.Jump.triggered;
    }

Always returns false even when pressing the key binded to the action

native perch
#

Okay so didn't get .triggered to work but I simply did

    public float PlayerJumped()
    {
        return playerControls.Player.Jump.ReadValue<float>();
    }
``` and just compare 0-1 (0 being not pressed, 1 being pressed) and got it to work that way
craggy oar
#

how do i check a certain key in the rebind operation progress

#

im doing this but the controlsExcluding is the problem
he also does the first letter ignoring. so how can i add them indicidually

austere grotto
#

To get a bool

austere grotto
#

Jumping has little to do with the input system apart from just reading the button.

supple crow
prime bear
#

Unity: Version 2021.3.4f1
Input System: Version 1.3.0

I've been randomly dealing with this issue in two projects now. Was just wondering if anyone else has a clue about why this is happening. I am using the default action map from Packages/Input System/InputSystem/Plugins/PlayerInput.

The error manifests upon pressing play in the editor as well as any time I turn off and back on the EventSystem game object and/or it's components in the inspector.

Another thing to mention is that is happens upon spawning a prefab with an EventSystem object within it. I've tried both spawning in Awake and Start, assuming Awake was just too early; however, neither changed the outcome of this issue.

I'm not sure if I can just update the Input System package because it is a dependency of the OpenXR Plugin 1.4.2 and I'm not sure if that will just cause me extra problems.

It also seems random when it happens. I can take the code from one project and put it into another and it works as expected.

I have also tried are deleting the library directory and rebuilding it. I have removed the OpenXR package and the input system package and added them back.

All 3 of these errors originate from my instantiation of my player prefab.

(Error messages will be posted in a second message because of the char limit. Sorry)

prime bear
#

Nevermind.. I think I figured it out after stepping through the code a bit deeper. It seems to be caused by an issue with the WaveXR SDK. I'll dig deeper there and I'm sure I'll figure it out. Thanks anyways

prime bear
#

Just going to document what the issue actually was:

I had WaveXR Plugin version 5.3.1-r.2 installed. Apparently HTC/Vive decided to mimic devices such as the wrist tracker even though they weren't in use so when it was parsing the bindings for those devices, they weren't found thus leading to the null references. Reverting to version 5.0.3-r.5 was my solution to this issue. This also explains why this was an issue for my newer projects and not the older ones.

austere grotto
magic jungle
#

I am making a runtime key binder, and I made this code:

    {
        playerControls.Disable();
        keybind.keybindText.text = "press a key";
        rebindingOperation = keybind.action.action.PerformInteractiveRebinding()
            .WithControlsExcluding("Mouse")
            .OnMatchWaitForAnother(.1f)
            .OnComplete(operation => finishRebind(keybind))
            .Start();
    }

    void finishRebind(Keybind keybind)
    {
        playerControls.Enable();
        rebindingOperation.Dispose();
        keybind.keybindText.text = keybind.action.action.GetBindingDisplayString(0);
    }```
The "Keybind" script holds some info like the bind text and the action that is being changed. 

When this is ran, it shows that the binding has been changed by updating the text correctly, but the binding isnt applied. How would I do this?
pure cave
golden mica
ruby rock
#

!code

sonic sageBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

ruby rock
#

do anyone know how to normalize the axis value as i already add the processor but still its giving values in 0.

supple crow
#

show how you have configured the action

ruby rock
austere grotto
ruby rock
#

so where should i use that

#

on the negative and positive?

austere grotto
#

you shouldn't use the normalize proocessor at all

#

what the normalize processor is meant to do is take a range like [-60, 60] and normalize it to the range of [-1, 1] for example

austere grotto
#

If you want to get only -1, 0, or 1, you can do this:

float quantized = inputFloat == 0 ? 0 : Mathf.Sign(inputFloat);```
ruby rock
#

worked like a charm thanks for help @austere grotto

ornate saffron
# pure cave Here's my function (I don't know how to put a check in place): void Fixed...

this should be mostly fine without an extra check, the value should be getting multiplied by zero when there's no input, so presumably either something is registering as input, there's an issue with the axis configuration (or your rigidbody is slightly to the right of the main transform lol - i think want to be using _rb.position not transform.position when calculating the new position!)

austere grotto
still bramble
#

Do you guys know how I can make an equivalent to GetKeyDown() that only fires once you press and not when you release with the new input system?

tepid peak
#

for some reason it jumps when I press s or left button

#

and the groundslam never works

#

I have the right keybinds I think

#

I already removed the s key in the move so that's not it

#

before when I only had jump and no groundslam, character never jumps

#

but I added groundslam and it jumps when the groundslam is called

#

ah nvm all my questions

#

I didn't change the values

sudden cradle
#

I'm trying to get the position of a touch on the screen, I have one main camera, and I've tried to use the viewport and screen position methods to convert the position, however the coordinates are never from 0 to 1 and never from 0 screen height/width. it's between 0 and 200 for some reason and it seems like the positioning is based on some other origin...

my code looks like this:

Vector2 position = touchPositionAction.ReadValue<Vector2>();
Debug.LogFormat("TouchPress ({0}x{1}): world {2}, screen {3}, viewport {4}", Camera.main.pixelWidth, Camera.main.pixelHeight, position, Camera.main.WorldToScreenPoint(position), Camera.main.WorldToViewportPoint(position));

/*
top-left: TouchPress (1080x1920): world (18.46, 1893.85), screen (4084.62, 364578.50, 10.00), viewport (3.78, 189.88, 10.00)
top-right: TouchPress (1080x1920): world (1064.62, 1893.85), screen (204946.20, 364578.50, 10.00), viewport (189.77, 189.88, 10.00)
bottom-right: TouchPress (1080x1920): world (1068.46, 20.77), screen (205684.60, 4947.68, 10.00), viewport (190.45, 2.58, 10.00)
bottom-left: TouchPress (1080x1920): world (456.62, 443.27), screen (88210.50, 86067.75, 10.00), viewport (81.68, 44.83, 10.00)
*/
austere grotto
#

But touch input data is in screen space not world space

#

You should be using ScreenToXxxPoint

sudden cradle
timid dagger
#

You can check its context:
if (context.phase == InputActionPhase.Started)
Or you can check it inside of action:
if (inputActionReference.action.phase == InputActionPhase.Started)
You can also add press interaction setting to that binding (I haven't tested it tho):

kind vault
#

Hi there!
Has anyone here used the Stadia Controller (Bluetooth mode) with the Input System 1.4.4 and Unity 2021.11f1? It detects the input under the input debugger, but it's not listening to events, either in the game or in the input controller setup ...

kind vault
half hemlock
#

Hi. Does anyone know how to use both the keyboard and a joystick at the same time please? I can't manage to make it work without everything just breaking and lagging and I don't know what I doing wrong😅

grim scroll
#

What is the difference between AddCallbacks vs SetCallbacks when using the auto-generated input actions class?

#

It looks like set unregisters any existing callbacks and then adds the new callbacks?

austere grotto
#

That would seem logical. Peek at the code and see?

austere grotto
#

What does the Restart function do

wheat crypt
#

Hi, I'm using the first person controller of the Unity Starter Pack. I have the pproblem that when I move the mouse just a little bit its not detected. Does anyone else had the probkem before?

night root
#

Hi I would like to make the "shooting" part of the InputSystem. The plan is that as long as you press this buttons (Mouse0) the Shoot() will be triggered

#

With Input.GetMouseButton(0) I would achieve exactly that but would need something to make it dynamic for different systems

#

is there an equivalent way in the input system?

wheat crypt
night root
#

I thought about this aswell but solved it currently like this

wheat crypt
#

And its in the Update function?

night root
#

previous solution was with Events if Input.Player.Shoot.performed but this method call seems nicer

#

just have to change the IsShootButtonPressed inputs to the inputsystem then it should be smooth enough xD

night root
# wheat crypt

just realized instead of .performed I could probably add .IsPressed, maybe then you don't need the Hold Interaction

wheat crypt
#

I think both methodes are okey. I just didn't want it to be in Update

night root
#

that's fine. I want to fire while holding the button, how would you do it if not in update

night root
#

oh okay you made an extra Realease method, that sounds cool

thin musk
#

Anyone else had an issue when installing input system and Unity asks if you want to enable it?
it says that it will "RESTART" Unity and "ENABLE" new input system.
It never actually restarts it, it closes the project and I have to manually open it again ;]

wooden halo
#

How do I setup a joystick for mobile that moves the player?

#

or you touch the right side to make the player go to the right and the same goes with left side

#

How'd I do that?

whole tundra
#

Getting "Cannot find action map 'oldActionMapName' in actions 'actionsName'" after renaming the action group (using new input system).
Pretty sure its a unity bug. How I can fix it?

#

It disappears if I create empty oldActionMapName, but I don't want to have one.

austere grotto
#

You have a component or script somewhere using it

#

Maybe your input module perhaps

frail nacelle
#

could someone help me out

gray geyser
#

Help me in adding game controller.
Please.

glass yacht
#

If you're looking to add game controller support to your game then follow a tutorial, there's one for the new input system pinned to ⁠this channel
Using the Input System: https://learn.unity.com/project/using-the-input-system-in-unity
You will have to put in the effort to learn nobody is going to help you if you haven't shown any indication you've tried

chrome walrus
#

Just jumped in. your issue is to use control schemes or what exactly?

zinc knoll
#

Can anyone help me i keep getting a error saying The type name OnFootActions does not exxist in type PlayerInput

chrome walrus
zinc knoll
#

Can anyone help me i keep getting a error saying The type name OnFootActions does not exist in type PlayerInput

chrome walrus
#

Wait, is your visual studio not crying about PlayerInput.OnFootActions? Because you only have OnFoot as far as I can see

#

Did you set it up correctly?

zinc knoll
#

yes i believe so

#

im asking here because im stumped

chrome walrus
#

You should setup your IDE correctly

#

!ide

sonic sageBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

chrome walrus
#

So it shows you whats wrong and suggests what might be right

half hemlock
#

Hi. Does anyone know how could I add processors at runtime please? Like for the player to be able to for example change the axis deadzone at runtime. Thanks

round jacinth
#

Is there a way to get wasPressedThisFrame for actions? I don't want to hardcode Mouse.current.leftButton, and I want to get a true value when the button was pressed, and false the next frame, but if I use performed, I get true when the mouse button is being held too

austere grotto
round jacinth
#

🤦‍♂️ thanks so much, idk why I didn't see it

obtuse linden
#

I keep having this `Unable to find style "ToolbarSearchTextField" in skin 'DarkSkin' Used" error. I tried looking it up but all I found was someone's thread where their post was downvoted and someone said "it's a bug that's already been fixed"

#

I just added the new input system and I've never used it before so Im not sure how to fix this

#

It seems to prevent me from adding my control scheme, whenever I try to add it I can create it but I can't add any devices to it

#

I tried going into the file, tried clearing it, figured it was just some dumb GUI error that shouldn't matter but it's not going away cattired

#

stare okay well apparently to add devices I have to right-click? that's weird but sure-
if anyone knows how to get rid of that error I'd still appreciate it, otherwise I'll just clear it and hope it nevers come up again shrugs

hardy root
#

Hi guys! How to detect if said path is a special character?

tough imp
#

I like the old input system

stark notch
#

In 2021 it is not happening, another bug in 2022 is the inspector breaking randomly like randomly a part of the variables that are normally visible in the inspector are not and you see an error related to this

obtuse linden
#

I'm trying to add a Roll mechanic, on keyboard if a key is double tapped it'll alter the player's position. Is there a way to access something like, "if input value is (the key associated with) Roll X Positive"?

#

Since the player could rebind it, I want it to be "on roll, if the key is Roll X Positive, then add to position.x" instead of "if player double taps D key"

#

Im just not sure how to do the syntax for accessing "the key associated with Roll[X/Y], [Positive/Negative]

tropic tulip
#

how to get angles from new input system?

austere grotto
#

angles of what

#

do you mean the 2D input vectors from your joysticks?

tropic tulip
#

thank u its fine it works now

tropic tulip
#

why is it that it only shoots onces and acts like a button even tho its set to pass through and any in the input actions

solar kite
#

When I use debug my InputHandler shows the proper values when running. But if I don't use debug and I instead make the values visible an alterative way they either don't update or lag behind until I click on the inspector window

#
public class InputHandler : MonoBehaviour, GameInput.IPlayerActions
{
    private GameInput _inputActions;
    [ShowNonSerializedField] private Vector2 _moveAxis;
    public Vector2 MoveAxis => _moveAxis;

private void Awake()
    {
        if (_inputActions != null) return;

        _inputActions = new GameInput();

        _inputActions.Player.Enable();
        _inputActions.Player.SetCallbacks(this);
    }

public void OnMovement(InputAction.CallbackContext context)
    {
        _moveAxis = context.ReadValue<Vector2>();
    }
}
sweet roost
#

hm the input system is driving me crazy...
maybe some one has an advice for this problem:

i have assigned an axis to an action, but when ever i reach -1.0f the InputActionPhase is switching to Canceled, which is probably ok, but the value returned by context.ReadValue is 0.0f!

any idea how to change that ?

#

seemed to work once i divided the axis in a positive and negative combined action, but with a single value type action the axis is not working as expected

#

In InputActionState during Phase change ( to canceled ) the trigger maginutude becomes 0.0 btw, i would expect 1.0 there..

sweet roost
#

only difference i could spot is that the raw memory for that axis becomes 0x 00 00 for -1.0 compared to an xbox controller, which stays at 0x 00 80 for -1.0

#

before the InputActionPhase switches to Canceled:

#

cancel event, even tho the xbox controller never generated any new event:

#

and with disconnected xbox controller, ( axis should be at -1.0 as the other device is still connected ):

sweet roost
#
[InputControl(name = "leftStick", format = "VEC2", layout = "Stick", displayName = "Left Stick", shortDisplayName = "LStick")]
        [InputControl(name = "leftStick/y", format = "USHT", layout = "Axis",
            parameters = "normalize,normalizeMin=0.0,normalizeMax=0.03123522,normalizeZero=0.01561761",
            offset = 0)]
        [InputControl(name = "leftStick/x", format = "USHT", layout = "Axis",
            parameters = "normalize,normalizeMin=0.0,normalizeMax=0.03123522,normalizeZero=0.01561761",
            offset = 2)]
        [InputControl(name = "leftStick/up", format = "USHT",
            parameters = "normalize,normalizeMin=0.0,normalizeMax=0.03123522,normalizeZero=0.01561761,clamp,clampMin=0.01561761,clampMax=0.03123522",
            offset = 2)]
        [InputControl(name = "leftStick/down", format = "USHT",
            parameters = "normalize,normalizeMin=0.0,normalizeMax=0.03123522,normalizeZero=0.01561761,clamp,clampMin=0.0,clampMax=0.01561761,invert",
            offset = 2)]
        [InputControl(name = "leftStick/left", format = "USHT",
            parameters = "normalize,normalizeMin=0.0,normalizeMax=0.03123522,normalizeZero=0.01561761,clamp,clampMin=0.0,clampMax=0.01561761,invert",
            offset = 0)]
        [InputControl(name = "leftStick/right", format = "USHT",
            parameters = "normalize,normalizeMin=0.0,normalizeMax=0.03123522,normalizeZero=0.01561761,clamp,clampMin=0.01561761,clampMax=0.03123522",
            offset = 0)]
        [FieldOffset(8)] public ushort yLeft;
        [FieldOffset(10)] public ushort xLeft;

the layout of the left stick for the custom HID.

obtuse linden
#

I'm trying to add a dash to my game using the new input system. Here's my setup

When I run it, none of these debugs show at all, so clearly it's not even entering onDash() when I hit 'Q'. Enabling "Dashing" while playing does nothing either. This is my first time working with Coroutines so I might be wrong there

#

Besides the coroutine I don't see anything that could be causing me an issue, everything should be set up okay

#

Movement + Sprinting both work as well, I've tried dash while moving, while sprinting, while not moving, enabling Dashing from the inspector, changing the values, etc

#

I'll try plugging in a controller but I cant imagine that'll do anything different if it's not working at all already

sweet roost
#

OnDash != onDash ?

obtuse linden
#

........hahahaha of course

#

thank you

#

I shouldve asked here earlier, that wouldve saved me a good hour lol

sweet roost
#

now lets hope someone can help me 😄

obtuse linden
#

I'm a newbie to game programming but what's your issue? :D

#

(if you are in any channel besides code-beginner or code-general i will be unable to help lol)

sweet roost
#

asked my question here right before your's 😄

obtuse linden
#

......hoo boy

#

I am not of service cattired

sweet roost
#

that problem has eaten already a few days from my sparetime

obtuse linden
#

yeah I can relate _frogsweat

#

Figuring out the input system stuff has taken days from me too SCsadkittyYES

#

and im like, nowhere near your level

sweet roost
#

yeah the package is nice and stuff, but sometimes does too much for my taste 😄

sweet roost
#

ok i think i found out what i am missing:
**defaultState **for the custom HID

#

question is now, what type should it be ?

solid remnant
#

hi, Are there any advantages to using the new Unity Input System? (ignoring the fact that it has an interface)

austere grotto
#

The advantages of using the new input system are that you get to use all of the features of the new input system

solid remnant
#

Maybe I don't know about them but as far as I can see it is only useful if I want to do multiple control mappings depending on what is connected (Joysticks, keyboards, pointers, etc)

austere grotto
#

The input system works even if you only want to use one control scheme

#

It would be really weird if it didn't

solid remnant
#

I already corrected the question, I made a mistake and changed this "it is only useful"

austere grotto
#

Multiple control schemes is only one of the many features of the new input system

glass kestrel
#

Hey, can anyone help me out with a script problem i am having

glass kestrel
#

alright, currently trying to follow a tutorial on making a simpla fps platform. I crated a script for movement and my guide tells me to make a c# script. When i try to open it, it goes to "vierw downloads". If i click it, it opens for a half second then closes

#

not sure why

slate pelican
#

I'm still trying to diagnose an issue with input actions:

  1. In the Event System for UI, the Input System lets me bind mouse click so clicking on UI buttons clicks things on UI.
  2. If I connect an InputActions asset to the Event System, and bind a button to left click, all is fine 👍 .
  3. If I go to the InputActions asset, and add interactions (ie Tap, Slow Tap, Hold), that binding no longer clicks the UI.
    Q: Why? Or how do I get a button with interactions defined to still affect UI.
austere grotto
#

Or better yet - why are you using your own custom input actions asset for the input module

#

What's wrong with the default one

slate pelican
#

I wanted to have multiple bindings for non-mouse inputs, like gamepad button click

#

it just made sense to have it all centralized.

sweet roost
#

is there any best practise for binding axis of various devices ? i seem have trouble with some devices where the axis are non continuous, like the upper part (0-1) is actually the lower one (-1 - 0). so if one moves the axis from low to center to high the value is moving from 0 to 1 flipps to -1 and moves to 0 ...

brazen sorrel
#

Hey, I'm trying to get this "rotate Camera" input to work. I Want to rotate the camera with middle mouse (held down and dragged) to orbit around the characters XY axis. Having some difficulty understanding the setup

#
InvalidOperationException: Cannot read value of type 'Vector2' from control '/Mouse/middleButton' bound to action 'Player/RotateCamera[/Mouse/middleButton]' (control is a 'ButtonControl' with value type 'float')
red widget
#

You're doing .ReadValue<Vector2>() in code where you should be doing .ReadValue<float>(). A button is a single value, and as you have this under a 1D axis binding, it'll ever be 1 or 0 (for mouse button)

brazen sorrel
#

it sounds like i need to change the input type then since its a 0/1 only value?

#

Are you saying to alter the code? This is the cinemachines system not my own

red widget
#

The input type is correct, it's your code that's not right, read the error

#

Trying to read a vector2, when the input type is a float

brazen sorrel
#

i think im following, but also trying to communicate "what should i change and how." Should i change the player input setup or the class itself? If it's the class, then that'd be an issue since it may have features tethered to other things elsewhere. If it's the input, i can change it to a different type

red widget
brazen sorrel
#

so its impossible to use the default system to achieve a "mouse hold and drag to rotate"?

#

this system right here

red widget
#

Ah yeah that script is already provided by Cinemachine so you can't really edit it without breaking other stuff

#

So switch back the Input Actions Asset to what it was before (probably Mouse Delta), and you need to roll your own code for the hold action

#

See if you can extend the CinemachineInputProvider script by inheriting from it, to add your hold button

#

lmao, this becomes a code question again

brazen sorrel
#

yea im trying to avoid code in this instance

#

im fine with it in any other circumstance, just trying to see if the default input can handle it

red widget
#

It doesn't, it seems

brazen sorrel
#

but im getting the impression it wont

#

daym that sucks

misty crown
#

Is anyone else not able to update to 1.6.1?

coarse pivot
#

Im having trouble making unity recognize that i have inputsystem package. can anyone figure out how to fix this

heavy halo
coarse pivot
#

k

heavy halo
#

if that doesnt work uninstall and install

#

the package

#

not unity

coarse pivot
#

tried that like

#

5 times

heavy halo
#

have u tried closing unity and then opening?

coarse pivot
#

yes

heavy halo
#

whats the error code

coarse pivot
heavy halo
coarse pivot
#

removes the 3 unused lines

#

using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;

#

these three

heavy halo
#

show me the script

coarse pivot
#

nothing

#

literally

heavy halo
#

hm thats weird

#

wait your using vscode?

coarse pivot
#

yes

heavy halo
#

vscode is not supported by unity

#

install visual studio

#

not vscode

#

!ide

sonic sageBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

coarse pivot
#

same issue

heavy halo
# coarse pivot same issue

when you downloaded visual studio did you install the unity package? (inside of visual studio installer)

coarse pivot
#

shoot

#

it works

#

thanks alot

cinder zodiac
#

just wanna give a shoutout to the InputSystem developers!
there's been a few rough edges but overall switching to the system has been really pleasant

heavy halo
#

When binding weapon selectors like this is this usable?

#

or do i make a new actionmap for instance (Primary Weapon: 1) (Secondary Weapon: 2) etc.

solemn ravine
#

Hello. I added new action map to unity for menu. Done everything like with my first action map, but now unity keeps giving me 'Object reference not set to an instance of an object error'. It seems to be caused by InputActions(controls) because changing action map does nothing. Here's script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Menu{
public class UniversalMenu : MonoBehaviour
{
    Controls controls;
    //unrelated stuff here
    void Start()
    {
        controls = new Controls();
    //unrelated stuff here
    void OnEnable(){
        //Line that causes problems:
        controls.Menu.Enable();
    }

    void OnDisable(){
        controls.Menu.Disable();
    }  
}}
#

Did I forget about something? Or does using second action map require something different?

heavy halo
#

is the file name called Controls?

solemn ravine
heavy halo
#

oo okay so i can reference if a player clicked on 1, 2, 3 seperately?

solemn ravine
#

Another bidings are for situation, when multiple keys do same thing

heavy halo
#

oo okay

solemn ravine
#

For example arrow on keyboard and arrow on gamepad

#

You need action for every weapon

heavy halo
#

yes okay i fixed it thank you

heavy halo
solemn ravine
#

controls.Menu.Enable();

heavy halo
#

wait actually nvm

#

did you generate a c# class with the input action?

solemn ravine
#

yes

#

it works with first action map

#

not with second (Menu)

heavy halo
#

and that c# class name is Controls?

solemn ravine
#

yes

solemn ravine
heavy halo
#

oo okay

#

that is weird because it should work

solemn ravine
heavy halo
#

have u tried restarting unity?

#

and visual studio

vestal night
#

how would I handle multiple GameObject requiring access to inputs via the c# wrapper? I started with creating an instance of the wrapper for each player object but ran into action conflicts when one player was performing an input and the other player was expecting the same performing input but on another device. I'm trying to avoid the PlayerInput/Manager component and trying to assign devices to players manually but I can't seem to detect multiple inputs happening even on different devices

austere grotto
#

it was made specifically for this use case

vestal night
#

I'll play around with both methods a bit and see which I end up preferring :) thanks for the links! that's very helpful

#

also, should I avoid creating multiple instances of the c# wrapper in different components (multiplayer aside)? just now thinking about UI components that may need access to input actions

austere grotto
vestal night
#

that makes sense! are you accessing that instance directly or using some kind of event subscription system to broadcast actions?

austere grotto
#

I do different things in different projects. One convenient approach is to use the wrapper's generated action map interfaces and SetCallbacks/AddCallbacks functionality

#

In general I try to avoid writing boilerplate code that just duplicates the stuff in the wrapper already

heavy halo
#

So im trying to get input with the left mouse button but its not working for some reason am i doing everything correctly?

austere grotto
#

that should oinly be done in OnEnable or Start or something

#

as for why it's noit working in general you need to show the configuration of the Fire action itself

heavy halo
#

would it work in awake?

austere grotto
#

no because you're noit creating the PlayerControls object until Start right now

heavy halo
#

oh yeah true

#

lemme try to put it in onenable

austere grotto
#

this is brokjen right now

#

move the Start stuff to Awake

#

because your OnEnable is going to run before start currently

#

you SHOULD be seeing a NullReferenceException in your console right now

#

never ignore errors in your console

heavy halo
#

yeah lmao i wondered why this was saying

#

doesnt give me info enough

austere grotto
#

it gives you all the info you need

#

line 20 there's a null reference exception

heavy halo
#

oh yeah i see

#

it says the same thing

heavy halo
austere grotto
heavy halo
#

i did but i moved the event sub to awake method

#

and it worked

#

oh nvm it worked both ways its just unity bugging

#

oh but this is just click

#

i want the player to be able to hold

austere grotto
#

Update

heavy halo
#

lmao

#

wait i still put that in the update method but it only detects clicks

heavy halo
austere grotto
#

no

#

just read if its pressed

kind vault
#

It's not. You are subscribing to the Shoot method in every update.
You should do either in the OnEnable/awake/start

austere grotto
#

dont subscribe to an event

#

Fire.IsPressed()

#

to check

heavy halo
heavy halo
#

nvm im just being dumb

crimson crater
#

is there any reason the event gets called only once?

private void Awake()
    {
        List<object> keys = new();
        InputAction move = new InputAction();
        move.AddCompositeBinding("2DVector")
            .With("Up", Keyboard.current.wKey.path)
            .With("Down", Keyboard.current.sKey.path)
            .With("Left", Keyboard.current.aKey.path)
            .With("Right", Keyboard.current.dKey.path);
        object obj = new Keybind("Move", move);
        keys.Add(obj);
        Keybinds.Init(keys);
        Keybinds.GetKeybind("Move").performed += (ctx) => Debug.Log(ctx.performed);
    }
#

Its from a player component using my custom keybinding system

crimson crater
#

performed

austere grotto
#

only once - period?

#

Or once per keypress

#

or what

crimson crater
#

Once per click

austere grotto
#

how many times would you expect?

crimson crater
#

Normally performed gets called on press and release

austere grotto
#

no

#

normally performed gets calld on press

crimson crater
#

At least it does when i use an InputActionAsset

austere grotto
#

started also called on press

#

and canceled on release

crimson crater
#

Uh

#

Guess i can just rewire the events

austere grotto
#

so (0,0) -> (1,0) will trigger performed
also (1, 0) -> (1, 1)
but not (1, 0) -> (0,0)

#

that will trigger canceled

crimson crater
#

So this should work ?

public class Keybind
{

    public string Name { get; private set; }
    public InputAction Action { get; private set; }

    public Keybind(string name, InputAction action)
    {
        Name = name;
        SetAction(action);
    }
    public void SetAction(InputAction action)
    {
        if(Action != null) 
        {
            Action.started -= OnPerformed;
            Action.canceled -= OnPerformed;
        }
        Action = action;
        Action.Enable();
        Action.started += OnPerformed;
        Action.canceled += OnPerformed;
    }
    public event Action<InputAction.CallbackContext> performed;
    private void OnPerformed(InputAction.CallbackContext ctx)
    {
        performed.Invoke(ctx);
    }
}
#

It does

#

Nvm it didn't update the value correctly with multiple keys input but i fixed it by replacing started with performed

oblique moon
#

Hello guys,
I want to implement a simple Touch (or Click) to make my character move somewhere. Currently, I'm using the performed callback of a simple Action Binding of type Button.
My problem is, if I start clicking somewhere, go really quickly somewhere else far away, then release, the Click is still registered and is done where my mouse currently is after I've moved a lot.
I want to prevent this behavior, I am curious to know if the tools in the New Input System allow me to do that, or do I need to script something to detect all of this?
If I have to script it, I'm pretty sure I know how to do it the old way, but I was curious if the new system provides built-in tools for that.

Thanks a lot!

crimson crater
#

If that's the case just use ctx.performed or ctx.ReadValue() with an if statement

civic garden
#

i wonder in Unity input system, do we really need to seperate InputAction event started and performed because it happend at the same time

        private void OnEnable()
        {
            attack.started += Attack_started;
            attack.performed += Attack_performed;
            attack.canceled += Attack_canceled;
        }
        private void Attack_started(InputAction.CallbackContext obj)
        {
            // code
        }

        private void Attack_performed(InputAction.CallbackContext obj)
        {
            // code
        }
        
        private void Attack_canceled(InputAction.CallbackContext obj)
        {
            // code
        }

I mean we can put the code of started and performed at the same function

        private void OnEnable()
        {
            attack.performed += Attack_performed;
            attack.canceled += Attack_canceled;
        }

        private void Attack_performed(InputAction.CallbackContext obj)
        {
            // code started
            // code performed
        }
        
        private void Attack_canceled(InputAction.CallbackContext obj)
        {
            // code
        }
civic garden
#

Oh i realized if i map the WASD move it will call the started once and when i press other direction it will call performed once

#

Then the above question change to: if i have action that only map to 1 key (attack), do i really need to seperate started event and performed event

solemn ravine
#

controls = new Controls() must be in Awake()

stable plinth
#

Hey people. I have an issue I was hoping one of you might be able to help with. I'm making a spaceship game that works with a joystick. It works great. However; the issue I have is when I have my steering wheel plugged into my PC as well as my joystick the game works with the steering wheel instead of the joystick and the joystick doesnt work at all. If I start the game with only the joystick plugged in it's fine but I'd rather not have to unplug the steering wheel every time I want to play the game. Is there someway to maybe choose what device the game uses if multiple control devices are plugged in?

oblique moon
oblique moon
arctic estuary
#

Hello everyone, maybe someone has encountered this...
After updating from 2021.3.19 to 2021.3.20 there was a bug with jitter touch input, this bug is 100% reproduced after collapsing and expanding the game
I created a bug report and it was confirmed, please vote for it
https://issuetracker.unity3d.com/issues/android-intermittent-touch-input-starts-to-jitter-after-minimizing-and-restoring-the-app-when-built-on-android

Kind Regards

strange badge
#

For some reason whenever i use the left/right stick of a gamepad to change a Vector2 type value it only works when moving them left or right, while moving them up and down they straight up does not work, does anyone know why this is happening?
Keep in mind i face this issue in a build and not in the editor of my game.

austere grotto
strange badge
austere grotto
#

show your code and how you set up your input actions and bindings

strange badge
#

For reference: when using it like this the Y value of the vector2 returned is always 0, however when i change the up and down bindings it returns the correct values

random vortex
#

Using Unity 2022.3.4f1 with the latest "New Input System" version. Trying to make a "platform and device agnostic" way of controlling the cursor, which is represented as a sprite on a game object. For instance, pointers (mouse, touch, pen) track the pointer position whereas Joystick and Keyboard move the cursor object with Vector2 like you would a character controller.

I am testing on my PC (as that's the only system I have). I have the devices stored in a dictionary ranked by priority with gamepad being first in line above all else.

The system works great except that, if the gamepad is plugged in before I hit play, it won't register; but if I remove it and reconnect it, now it suddenly works. This is not ideal. I've made sure to do my calls in Start vs Awake. Has anyone else had a similar issue with the gamepad not registering properly?

Also, my player prefs for setting "user preferred device" aren't being saved between sessions. Here is the code I'm using. I don't think the issue lies in the other scripts associated with it (Cursor_Base, Pointer, NonPointer, and InputActions) as those all seem to be working properly from what I can tell.

marsh gyro
#

I'm using the new input system and I have my EventSystem configured with the "Left Click" set to the Mouse Click action in the UI map. This Mouse Click action is a button with a binding where the Trigger Behavior is set to "Press Only" but when I click something in the UI, it's fired on press and on release. How can I make it so that is fired only on press?

austere grotto
#

also define "it" being fired. What exactly is firing?

marsh gyro
austere grotto
grave idol
#

hello does anyone know how i can make a button for a mobile control when i click on the button that the "E" key should be pressed

austere grotto
#

just make a function that is called both by the button and when you press the e key

grave idol
#

how

austere grotto
#

how what

grave idol
#

how can i do that

austere grotto
#

by making a function

#

and calling it when the player presses the E key

#

and calling it from the button

grave idol
#

on-screen button?

austere grotto
#

e.g.

if (Input.GetKeyDown(KeyCode.E)) {
  MyFunction();
}```
grave idol
#

ahh

#

ty

austere grotto
#
    void Start()
    {
        yourButton.onClick.AddListener(MyFunction);
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            MyFunction();
        }
    }

    void MyFunction() {
        print("Hello!");
    }```
grave idol
#

now it will print hello in my console

austere grotto
#

yes

grave idol
#

im new in coding

#

i started 2 weeks ago

austere grotto
#

ok?

grave idol
#

this input script doesent work

austere grotto
#

in what way does it not work

#

BTW 90% of people in this server are new, it is expected

grave idol
#

ohh okay

grave idol
austere grotto
grave idol
#

this script

austere grotto
#

you have to press E on your keyboard to press E

#

there is no way to press E from a script

grave idol
#

no a button

austere grotto
#

I was explaining how to do what you want without pressing E

grave idol
#

for mobile input

austere grotto
#

there is no way to press E from a button

#

tehre is no need to press E from a button

grave idol
#

und how i can open my door

#

with mobile input

austere grotto
austere grotto
#

open the door in MyFunction

#

the print("Hello") was just an example

#

you can do whatever you want in there

grave idol
#

OK

#

sry caps

#

ty

novel fjord
#

I wanted to ask does anyone know a good way to get the most recent active device using Unity's New Input system?

currently my code looks like this:

        public static InputDevice LastUsedDevice { get; private set; }

        static InputHelper()
        {
            // Set the initial device
            if (Gamepad.current != null)
            {
                LastUsedDevice = Gamepad.current;
            }
            else if (Keyboard.current != null)
            {
                LastUsedDevice = Keyboard.current;
            }
            
            // Listen for device changes
            InputSystem.onDeviceChange += (device, change) =>
            {
                if (change == InputDeviceChange.UsageChanged || change == InputDeviceChange.Added)
                {
                    LastUsedDevice = device;
                }
            };
        }

which works when a device is added etc and getting the inital device but if I have multiple devices connected such as having a contoller and keyboard both it will grab the gamepad and not the keyboard. I want to handle it so it assigns the device based on a button or key press. Is there any good way to accomplish this?

crimson crater
#

inside UnityEngine.InputSystem.Utilities there is InputSystem.onAnyButtonPress which you can use to catch pressed keys

#

The way i use it is InputSystem.onAnyButtonPress.Call(key => GetKey(key)); and GetKey is a method like that static void GetKey(InputControl key) then i can read the path tho i think there is a field specifying the device

#

Yeah key.device should return an InputDevice @novel fjord

novel fjord
#

hmm i'm trying to figure out how to get the call method to work?

#

i'm doing this: InputSystem.onAnyButtonPress.Call(GetKey);

but the issue is I need to subscribe not call it initally I want to set the value anytime it's called

crimson crater
#

Yeah it should just call it everytime you press a key on anything, at least it does in my project

#

Its getting late so i might not answer if you respond

vivid beacon
#

I'm a little confused with more complex input system where other things at the same time should be enabling and disabling some inputs.

I.e. You have player movement input enabled at start.
The input can be disabled by inventory and map.
Then player opens up inventory ui so the ui forces to disabled.
On top of it opens map. There is no change in input since its already disabled.
Then it closes the map. The movement is enabled yet it shouldn't because the inventory is still on.

What I have done is in singleton with
public Dictionary<string, List<Component>> disallowed; string is an action ID.
I add every single component which disallows action. And refer with every steering component this the singleton.
It works yet, It feels like I am doing something wrong. Like I am skipping input system package in some way.
I was trying to search for this information yet everyone shows very basic cases with input system.
What's a good practice for this ?

craggy silo
#

I've been using the workflow suggested by the documentation to create an actions object on every class that needed to work with the input system. It was working fine until more complicated cases emerged - now we are doing control remapping, and that remapping seems to happen on a specific instance of the actions object. This means I will only rebind controls for one instance which of course is not correct, I want the change to propagate to the entire game.

What's the correct approach here? Should I be creating just one actions object for all classes to use? I'm confused.

austere grotto
#

Generally I have one central "InputManager" singleton which manages the instance and access to it

#

The docs are not suggesting that workflow it's just a convenient way to show how the wrapper class works

craggy silo
#

I couldn't find that on the internet which is surprsiing coz it sounds like a very standard problem

austere grotto
#

I just described it

#

I'm on mobile

#

It's pretty simple

#

Just a singleton holding a property for the wrapper

true pulsar
#

Hello, I have a very beginner question. My game only requires a handful of inputs, so I removed a bunch of inputs from the Input Manager I didn't need. Now whenever I start my game, I get tons of error messages that I don't have certain buttons set up. Do I need to keep all the default inputs?

austere grotto
true pulsar
#

The error messages are coming from a script called "BaseInput" but I'm not sure if it is nessesary or not.

austere grotto
#

Yeah that's your input module

#

I don't really see much of a tangible benefit to removing the default axes from the input manager

#

simplest to just restore them

true pulsar
#

Ok got it

#

I'll add them back lol

modern radish
#

Hey guys I'm a beginner to unity and am using control freaks for a mobile game I'm developing. I want to make it so different target axis for my CF2 Button are triggered based on the number of presses from the user. Is there any way I can make this happen? I'm using the Universal Fighting Engine 2 in my project and do not have access to the backend code that handles each button input. I'd really appreciate any sort of help I can get for this.

boreal granite
#

Hi, im trying to make a fighting game and im trying to make local multiplayer but with prefabs that have already been spawned and how would I be able to set which controller is player 1 and player 2? how can I do this? I tried using the player input manager but it only spawns the prefabs.

round spindle
#

Hello,
I am using the legacy input system and I have the problem where I plug an xbox controller and the maping is one, but when I plug a PS5 or other controller model the mappings are all different.

When I use the Input Manager I have to define what each axis does but how can I flexibly adjust so it knows which axis it should be depending on the controller?

I appreciate any help.

warped arch
#

the On-Screen Stick Script doesn't set the pivot correctly

#

it is only correct when the anchor is at the center

#

but anywhere else it seems bugged

#

this is lower left anchor

vague tapir
#

I can't get my movement to work.
I've set the project to the new system
I have a UI component with an onscreen stick component control path as AndroidJoystick. This works when I play (working = it moves with the mouse, and it gives values in the input debugger).

I have a player component, with a move script and player input component.
Move script's FixedUpdate is getting called, but not the Move function.

Player input component is set with a custom action asset that binds move to a vector2d from AndroidJoystick. It is set to invoke unity events.

I have an event system - the Actions asset here is the default one. I suspect the problem might be the two different action assets, but not sure how to fix that. Edit: Even when setting the actions asset in both event manager and player to the same default one, it is not working (move event not being called)

vague tapir
#

I started over completely, it's working now. Only thing I did differently was not create my own action asset from scratch, but used the button to create a new one. Haven't tested actual touch to see if that's working, but for now just going to assume it is

barren smelt
#

I guess this is the right place to ask this. I can't seem to interact with any of my UI elements. I've confirmed that the Event System is indeed present, there's a Player Input Manager, Input System UI Input Module with its actions all assigned and such. Settings are all out-of-the-box.

There's a graphics raycaster and all elements in question are interactable raycast targets... the exact same setup in a different project with the same codebase works fine.

What in the world could I be missing?

plain cosmos
#

Hey, what is the KeyCode for ~ using InputSystem ?

#

Keyboard.current.[what here?]Key;

#

Is it the same as Keyboard.current.backquoteKey; ?

plain cosmos
#

There's no ~ in that documentation though

austere grotto
#

because they are parts of other keys

plain cosmos
stuck aspen
#

is there a way i can still use collaborate instead of plastic scm

austere grotto
stuck aspen
#

even if i switch to an older model of unity?

austere grotto
#

yes

#

unity does not operate the backend service anymore

stuck aspen
#

is there anything else i can use instead of plastic scm then

austere grotto
#

Git

stuck aspen
#

whats the general difference between them both\

austere grotto
warped arch
#

How can I have multitouch on my game?

#

My project is set up so that it has a joystick on the left side to move the player. Swiping anywhere on the screen makes it attack

#

The problem is that it can't detect the swipe while moving ie the joystick being touched

austere grotto
#

how are you detecting the swipe?

warped arch
#

I followed a YouTube video by samyam
https://youtu.be/XUx_QlJpd0M

Detect swipes and it's direction with the new input system in Unity 2020. I also show how to add a trail renderer for a cool swipe effect.

📥 Get the Source Code 📥
https://www.patreon.com/posts/45726030

🔗 Relevant Video Links 🔗
ᐅHow to use Touch with NEW Input System - Unity 2020 Tutorial
https://youtu.be/ERAN5KBy2Gs
ᐅGet Object from Mouse Cl...

▶ Play video
#

I tried using other bindings other than primary touch but either nothing changes or that the swipe stops working even when not moving

warped arch
thin musk
#

Hey, any guides on how to do touchscreen camera drag?

slate pelican
#

idk, but i’d have the camera have a monobehavior, on a tap action callback, look for the coordinates you tapped, and then move the camera accordingly

thin musk
foggy scarab
#

Hello can I get some help over here I am using the StarterAssets with the new Input System however everything seems to be working fine unless I go ahead and add more Actions such as

public bool attack;
public void OnAttack(InputValue value)
{
      Debug.Log("OK");
      AttackInput(value.isPressed);
}


public void AttackInput(bool newAttackState)
{
        attack = newAttackState;
}

I have mapped the left mouse button correctly but OnAttack never gets called am I undetsanding something wrong?

#

This is how it looks

warped arch
#

What's the difference between primary touch and touch #0?

turbid olive
#

I have just started working with new Input System and I don't understand why performed is triggered just after button is pressed
This is my code: https://www.nombin.dev/noagkwrfra

turbid olive
mortal cairn
#

Not sure this is the right place but it's "input" I guess. A volume's colliders are interfering with a raycast. But if I set the volume layer to anything but default, the volume stops working. So I can't mask it. Asked google and it was like "huuuurrr! Use layer masks!" so here I am.

austere grotto
mortal cairn
#

The input is a raycast and colliders. But I guess I can ask there too.

austere grotto
#

That's not input

#

That's physics

mortal cairn
#

... right

craggy iris
#

Hello everyone. Today I upgraded my project to the new input system and am now working on giving the player the option to rebind controls during runtime. Wish me luck 😅

knotty kayak
#

Hi everyone, I've got an issue with touch input and UI Toolkit, (I use the old Input.touchCount and Input.GetTouch(0))
The issue is that when I for example click on a floating UTK button, all of my scripts will still detect that a touch input has happened.
How can I change that ?

little epoch
#

Getting an error out of the blue when trying to build Addressables relating to the Input System. Worked perfectly fine prior to the time of writing. Updated everything in the Package Manager (except Addressables).

Unity 2020.1.15f1
JetBrains Rider package 3.0.24
Input System 1.6.3

austere grotto
little epoch
austere grotto
#

yes

little epoch
little epoch
#

@austere grotto I updated the addressables package and now I'm getting these errors

craggy iris
#

Finally got the rebinding working. Next I need to get the rebinding to override only a specific binding of the same type (keyboard, gamepad, or joystick)

#

My code so far: var rebindOperation = actionToRebind.PerformInteractiveRebinding()
.WithControlsExcluding("Mouse")
.WithExpectedControlType("Button")
.OnMatchWaitForAnother(0.1f)
.Start();

#

Looking at WithTargetBinding() but still trying to figure out how to get it to determine what type of device the user pressed during the intereactive rebind

proven kindle
#

I'm curious, how is IsFirstLayoutBasedOnSecond(string, string) different from if(firstString == secondString) ?
Edit: Ah my debug test printed "XInputControllerWindows is based on Gamepad". I see!

Also, wow. The default name "Mouse&Keyboard" is not recognized as being based on "Keyboard"...
So instead of hardcoding custom strings in my classes, I just renamed the control scheme into "Keyboard" and now it works.
Bit of a dumb hack but hey if it works it works... Edit: Actually that's dumb since it won't work for dualshock etc. Sigh.

modest sigil
#

Hello all! I'm trying to setup my UI to change based on whatever controller the player is using (Keyboard / Gamepad for now) but i'm not getting any event responses from InputUser.onChange

#
private void Awake()
    {
        textDisplay = GetComponent<TextMeshProUGUI>();
    }

    void OnEnable()
    {
        InputUser.onChange += OnDeviceChange;
    }

    void OnDisable()
    {
        InputUser.onChange -= OnDeviceChange;
    }

    private void OnDeviceChange(InputUser user, InputUserChange change, InputDevice device)
    {
        if (change == InputUserChange.ControlSchemeChanged)
        {
            UpdateUIDisplay(user.controlScheme.Value.name);
        }
    }

    private void UpdateUIDisplay(string deviceName)
    {
       
        if (deviceName.Equals("Gamepad"))
        {
            //buttonImage.sprite = controllerImage;
            textDisplay.text = "X";
        }
        else
        {
            //buttonImage.sprite = keyboardImage;
            textDisplay.text = "E";
        }
    }
#

i ran a debug.log to check and OnDeviceChange() is never being called

#

would appreciate some help 🙏

austere grotto
modest sigil
prisma barn
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class AnimationAndMovementController : MonoBehaviour
{

    PlayerInput playerInput;
    CharacterController characterController;

    Vector2 currentMovementInput;
    Vector3 currentMovement;
    bool isMovementPressed;


    void Awake()
    {
        playerInput = new PlayerInput();
        characterController = GetComponent<CharacterController>();

        playerInput.Movement.Move.started += onMovementInput;
        playerInput.Movement.Move.canceled += onMovementInput;
        playerInput.Movement.Move.performed += onMovementInput;
    }

    void onMovementInput (InputAction.CallbackContext context)
    {
        currentMovementInput = context.ReadValue<Vector2>();
        currentMovement.x = currentMovementInput.x;
        currentMovement.z = currentMovementInput.y;
        isMovementPressed = currentMovementInput.x !=0 || currentMovementInput.y !=0;
    }
    // Start is called before the first frame update


    // Update is called once per frame
    void Update()
    {
        characterController.Move(currentMovement * Time.deltaTime);
    }

    void OnEnable()
    {
        playerInput.Movement.Enable();
    }

    void OnDisable()
    {
        playerInput.Movement.Disable();
    }
}

Anybody sees anything wrong here? My player doesnt move at all...

craggy oar
#

so i have a eventsystem with the new inputsystem.
but i dont know why it gives me trouble with the first selected gameobject it doesnt get set
i try so much but i cant get this to work does someone has the solution for me?

austere grotto
#

never worked for me in like 10 years of Unity

#

better off in OnEnable setting the active object

#

EventSystem.current.SetSelectedGameObject

craggy oar
#

how do you mean that?

#

so set selected gameobject needs to be in onenable?

austere grotto
#

that was my suggestion yes..

mellow sedge
#

Someone know how I can do to enable or disable a control scheme ?
Via code

I'm still searching on the docu' but if ya know, ping me ! <3

regal osprey
#

Hello there
is there a way to display controls of an action on screen? like, is there something that's commonly used?

#

or do i have to develop something myself?

regal osprey
#

thanks

mental abyss
#

Has anyone tried to read input on an Ipad from a bluetooth device like a remote shutter trigger, music controller, or something that just has a simple button, not necessarily a game controller? We're making a museum exhibit and we just need one button to work (they can't touch the screen)

proven kindle
#

Err... .WithControlsExcluding("<Keyboard>/anyKey") seems to only affect the Windows key.
...which is also called "Anykey" if I try to map a control to it.
Is this is an inside joke about hitting "any key", or is it a bug of some sort?
leftMeta and leftWindows don't seem to do anything, but this works, I guess?
I would have thought it to affect all keys, going by the name.

uneven mulch
#

can someone help me to fix my update method? specifically this section , It's preventing my enemy from knocking back the player

if (inputVector.magnitude < 0.001f)
        {
            playerRigibody.velocity = Vector2.zero;

            currentState = PlayerState.Idle;
        }
        else
        {
            currentState = PlayerState.Walking;
        }

https://pastebin.com/puvprRZ1

austere grotto
#

how is knockback supposed to work when you are setting velocity to 0 constantly

#

also it's unclear how your player is moving.. is it using an Animator to move?

uneven mulch
#

This

private void FixedUpdate()
    {
        playerRigibody.velocity = new Vector2(inputVector.x, inputVector.y) * speed;
    }
austere grotto
#

seems obvious knockback won't work here

#

Also given that code I don't see why cs if (inputVector.magnitude < 0.001f) { playerRigibody.velocity = Vector2.zero; is necessary as it does exactly the same thing

uneven mulch
#

Yeah , I'm still getting used the the new input system , so is that code just irrelevant?

austere grotto
#

basically if you want knockback you'll have to stop running this code every FixedUpdate

austere grotto
#

this is your game logic

uneven mulch
#

Maybe because I moved the movement into FixedUpdate?

craggy oar
craggy oar
#

So im trying to trigger a event but strangely enough it doesnt trigger.
I do it like the following in the OnEnable.

InputHandler.INPUT_MASTER.Menu.SwitchTab_Left.started += (ctx) => { SwitchTab(1); };
InputHandler.INPUT_MASTER.Menu.SwitchTab_Right.started += (ctx) => { SwitchTab(0); };

In the OnDisable i do

InputHandler.INPUT_MASTER.Menu.SwitchTab_Left.started -= (ctx) => { SwitchTab(1); };
InputHandler.INPUT_MASTER.Menu.SwitchTab_Right.started -= (ctx) => { SwitchTab(0); };
#

my IDE say i have to use cancelled?

InputHandler.INPUT_MASTER.Menu.SwitchTab_Left.cancelled -= (ctx) => { SwitchTab(1); };

but that also doesnt do the trick?

#

I dont get the Debug Messages at all

craggy oar
#

in the input debugger it gives the right input so it should trigger i dont know why not tho

craggy oar
#

it was working like this like a month ago