#🖱️┃input-system

1 messages · Page 23 of 1

summer marten
#

Hi, I'm currently implementing rebinding and want to implement a whitelist for a specified range of keys that are allowed. I am wondering, if there is a way for me to get the "generic" alias of an InputControl?
For example, when I try to rebind to "Start" on my Xbox Gamepad, I receive an InputControl with the path /XInputControllerWindows/start. However I want the generic version, so /Gamepad/start. In the InputAction editor window I found a list of "Derived Bindings" next to the path, which seems like exactly what I want. I attached a screenshot.
I could also only check against "inputControl.name" instead of "path", since it always seems to be "start". However I'm not sure if there are exceptions for other controllers, where the name is not always identical. But I suppose I'm just checking for inputControl.name instead of inputControl.path is the way to go? Thanks!

Edit: .name doesn't cut it, because of composite controls like /device/dpad/left only returning left. I think i need to cut off the first part: private static string GetGenericControlPath(InputControl c) => c.path[c.path.IndexOf('/', 1)..];

limber sky
#

Hi All, I was wondering if anyone knew if their was a way to use a VIVE Controller standalone (without the HMD or any VR for that matter) with the new input system?

I am working on an experiment where we need to take user inputs across a 2D axis, the solution we thought of was to use the VIVE controllers touch pad (since its portable). However I cannot seem to find anything online regarding how to set this up without the headset?

#

(To be clear, I do not care about the motion tracking of the controller, just the touch pad and potentially the triggers)

simple scarab
#

Where does the input system cache the per user bindings of input actions? I added some inputs that work completely fine in editor, but when I make a build only the actions that were originally present seem to have bindings.

#

ah, turns out "use in control scheme" wasn't set -_-

#

ngl, sometimes this package feels really trashy. Why does it work without a control scheme set in editor but not in build? Why do I have to manually enable action maps in builds, but not in editor? If there's going to be issues then I'd rather not have to make a build to experience them

simple scarab
#

nvm, still broken??

thorn falcon
#

Are there any widely known naming conventions for these things? Like PascalCase vs camelCase vs snake_case and so on

verbal remnant
simple scarab
#

I made sure they have the right control scheme and action map

jade violet
#

Hi I am making a VR game and I am using XR toolkit and I want to make it so that when the user points to an object and clicks the A button, some text will show up but I have no idea how to do it and I couldnt figure it out

simple scarab
faint quarry
#

Hi, does anyone know how I can keep the input system from differentiating between different languages for the keyboard? I have some code that prevents duplicate bindings but it does not manage to cope with that. Like my default for dash is shift but since I am on a german Pc, when i bind something else to my shift button it takes the german name "umschalt" and it apparently allows it because it is not the same by name. Also its kinda strange when everything is in english and suddenly german keybindings appear 😅

whole bridge
#

Hello! I'm having a problem with the new unity input systen package. I've recently imported Mirror into my project and I'm currently converting my code over. I'm using the unity standard assets for my FPS controller. Would having the PlayerInput component be initialized after runtime has started cause problems with it detecting input?

I have two PlayerInput components one for player movement and another to handle other inputs for a 'gun'. The one that is initalized when runtime starts works without any issues, but the one that initializes after runtime starts seems to be trying to get input from the controller that does not exisit instead of picking up the input from the mouse and key board. Everything works just fine with a controller.

#

This is from the object that is initialized during runtime.

#

This is the object that is already in the scene when runtime starts.

#

Thank you for any help!

whole bridge
#

Well I finally found a solution.

austere grotto
summer marten
#

I also recently implemented removing duplicates during rebinding like this

InputBinding myBinding = GetBinding().binding;

foreach (var action in checkIn.SelectMany(map => map.actions))
{
    for (int i = 0; i < action.bindings.Count; i++)
    {
        InputBinding binding = action.bindings[i];
        if (binding.id == myBinding.id) continue;
        if (binding.effectivePath == myBinding.effectivePath)
        {
            // button was already bound! Remove it!
            ConLog.Debug("Removing duplicated binding: " + binding.effectivePath, this);

            action.ApplyBindingOverride(i, "");
        }
    }
}``` maybe it helps
faint quarry
#

yeah I implemented it in a similar way

silk ibex
#

Trying to create a 3D game that operates like a 2D game (much like overcooked! and plateup!

the way my character moves right now is fine, however when I stop moving the character automatically rotates back to facing north.

how can I make it keep it's current rotation when the player stops their input?

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    public float speed;
    private Vector2 move;
    public void OnMove(InputAction.CallbackContext context)
    {
        move = context.ReadValue<Vector2>();
    }

    void Update()
    {
        movePlayer();
    }

    public void movePlayer()
    {
        Vector3 movement = new Vector3(move.x, 0f, move.y);

        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.05f);

        transform.Translate(movement * speed * Time.deltaTime, Space.World);
    }
}
austere grotto
silk ibex
austere grotto
#

There's no directional input when the player stops their input, as you said in the question

silk ibex
#

oh sorry i misread what you meant

#

i thought you were saying i HAD no directional input

abstract wave
#

Is it better to use the old input system or the new one u can add through package manager ?(i am just a beginner)

fleet garnet
abstract wave
fleet garnet
verbal remnant
#

Old is worse in all cases. You can use the new system the same way as you could the old. The old system is entirely obsolete.

spare frigate
#

Is there a way to treat scrollwheel as a button? I want to allow players to change weapons with using scrollwheel UP/DOWN, but I also want to allow them to rebind that button later if they want to, but Unity treats the scrollwheel as a Vector2 delta AFAIK, so it wont get listed if the type of button, switching the type to something else will show the scroll delta but then wont allow buttons to be bound to it, is the only alternative to poll the scroll change myself in Update and have some complicated workaround for converting to-and-from delta and button for rebinding?

austere grotto
#

But no you don't have to do anything in Update unless you're using the old input system

#

Pretty sure you can make a binding to just up or down on the scroll wheel in the new system too

spare frigate
# austere grotto But no you don't have to do anything in Update unless you're using the old input...

Ah sorry I should have clarified, I am using the new input system, I guess "convoluted" may have been a better descriptive word, more complicated than simply using the Input Action Asset window to setup the bind, I couldnt figure out how to set something like this up through the new input system, so the first solution that comes to mind is "do it through Update" - how might I handle that binding? Would it have to be a composite?

spare frigate
# austere grotto Pretty sure you can make a binding to just up or down on the scroll wheel in the...

Actually this gave me an idea, after re-reading what you said a few times and trying a few things, it seems I could make a button bind that uses positive/negative (which does list the scroll wheel delta) and use the actions context.action.GetBindingIndexForControl(context.control) to find out if it was "positive" or "negative", which I believe means the player would be binding a composite, though I think this approach may work for my usecase - thanks for the idea

exotic spear
#

I have no idea why but this HandleExitTurret function is being run twice but should only run once.
The code starts with the inputReader:

public class InputReader : ScriptableObject, GameInput.IPlayerActions, GameInput.ITurretActions, GameInput.IUIActions
{
    public InputActionMap currentActionMap;

    public event Action OnExitTurretInput = delegate { };

    void OnEnable()
    {
        if (gameInput == null)
        {
            gameInput = new GameInput();
            gameInput.Player.SetCallbacks(this);
            gameInput.Turret.SetCallbacks(this);
            gameInput.UI.SetCallbacks(this);
        }
    }
    
    private void OnDisable()
    {
        gameInput.Disable();
    }
    
    public void Enable()
    {
        SetActionMap(gameInput.Player);
    }

    private void SetActionMap(InputActionMap actionMap)
    {
        currentActionMap.Disable();
        currentActionMap = actionMap;
        currentActionMap.Enable();
    
        Debug.Log($"Current Action Map: {actionMap}");
    }
    
    public void SetPlayerActionMap()
    {
        SetActionMap(gameInput.Player);
    }
    
    public void SetTurretActionMap()
    {
        SetActionMap(gameInput.Turret);
    }

    public void OnTurret_Exit(InputAction.CallbackContext context)
    {
        if (context.performed)
            OnExitTurretInput?.Invoke();
    }
#

And this is the TurretInteractable:

    protected override void OnEnable()
    {
        base.OnEnable();
        Debug.Log("event should subscribe");
        if (_inputReader == null)
        {
            _inputReader = backupInput;
        }
        _inputReader.OnExitTurretInput += HandleExitTurret;
    }

    protected override void OnDisable()
    {
        base.OnDisable();
        _inputReader.OnExitTurretInput -= HandleExitTurret;
    }

    private void HandleExitTurret()
    {
        _inputReader.SetPlayerActionMap();

        _interactingPlayer.Events.SetMoveState.Invoke(MoveState.defaultState); // This is where the error occurs on the second run of the function
        _interactingPlayer.Events.SetAnimatonBool.Invoke("OnTurret", false); // The _interactingPlayer is made null after it is called the first time
        _vcam.enabled = false;
        _reticleUI.enabled = false;
        _keyPromptPopup.SetVisible(true);

        if (_currentAmmo == 0)
        {
            RefillTask.gameObject.SetActive(true);
        }

        BroadcastOwnerRpc(EMPTY_OWNER);
    }
#

Why is it calling twice, someone please tell me, is it just a bug?

austere grotto
exotic spear
austere grotto
exotic spear
#

and I've tried it in the started phase

exotic spear
exotic spear
#

This is what I'm talking about

#

    public void OnTurret_Exit(InputAction.CallbackContext context)
    {
        if (context.performed)
            OnExitTurret();
    }

    void OnExitTurret()
    {
        Debug.Log("Run Once");
        OnExitTurretInput?.Invoke();
    }```

```c#
 private void HandleExitTurret()
 {
     Debug.Log("Handle Exit Turret");
     _inputReader.SetPlayerActionMap();

     _interactingPlayer.Events.SetMoveState.Invoke(MoveState.defaultState); // This is where the error occurs on the second run of the function
     _interactingPlayer.Events.SetAnimatonBool.Invoke("OnTurret", false); // The _interactingPlayer is made null after it is called the first time
     _vcam.enabled = false;
     _reticleUI.enabled = false;
     _keyPromptPopup.SetVisible(true);

     if (_currentAmmo == 0)
     {
         RefillTask.gameObject.SetActive(true);
     }

     BroadcastOwnerRpc(EMPTY_OWNER);
 }```
austere grotto
exotic spear
austere grotto
austere grotto
exotic spear
exotic spear
austere grotto
#

GetInstanceID()

exotic spear
#

Thanks

#

I'll try that out

#

ok so there are 2 instances running

#

weird

#

there is only a single script on each object so I don't know where this is coming from

austere grotto
#

of the two calls

#

see where it's getting called from

#

because it seems like the "Run Once" thing is only running once

exotic spear
#

The problem is in handle exit turret

#
TurretInteractable.HandleExitTurret () (at Assets/Scripts/Interactables/TurretInteractable.cs:129)
InputReader.OnExitTurret () (at Assets/Scripts/Input/InputReader.cs:146)
InputReader.OnTurret_Exit (UnityEngine.InputSystem.InputAction+CallbackContext context) (at Assets/Scripts/Input/InputReader.cs:140)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/DelegateHelpers.cs:46)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)```
#
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
austere grotto
#

not necessarily. HandleExitTurret is getting called twice. You need to see what's calling it

exotic spear
#

These are the two errors

austere grotto
#

not the errors

#

just the lines that say "Handle Exit Turret"

#

look at those stack traces

exotic spear
austere grotto
#

Yes... I'm suggesting a way to figure it out lol

exotic spear
#

Oh I get what your asking though the stack traces look identical, besides the instance ID's

austere grotto
#

what do they look like

exotic spear
#
UnityEngine.Debug:Log (object)
TurretInteractable:HandleExitTurret () (at Assets/Scripts/Interactables/TurretInteractable.cs:126)
InputReader:OnExitTurret () (at Assets/Scripts/Input/InputReader.cs:146)
InputReader:OnTurret_Exit (UnityEngine.InputSystem.InputAction/CallbackContext) (at Assets/Scripts/Input/InputReader.cs:140)
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
UnityEngine.Debug:Log (object)
TurretInteractable:HandleExitTurret () (at Assets/Scripts/Interactables/TurretInteractable.cs:126)
InputReader:OnExitTurret () (at Assets/Scripts/Input/InputReader.cs:146)
InputReader:OnTurret_Exit (UnityEngine.InputSystem.InputAction/CallbackContext) (at Assets/Scripts/Input/InputReader.cs:140)
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
austere grotto
#

ok so

#

Why is "Run Once" only being printed once

exotic spear
#
UnityEngine.Debug:Log (object)
InputReader:OnExitTurret () (at Assets/Scripts/Input/InputReader.cs:145)
InputReader:OnTurret_Exit (UnityEngine.InputSystem.InputAction/CallbackContext) (at Assets/Scripts/Input/InputReader.cs:140)
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)```
austere grotto
#

if these are both coming from OnExitTurret

#

that again strongly implies a double subscription to the event

exotic spear
#

It seems to be connected to the event but it is only subscribed to in the OnEnable function

#

Every reference to the function is here

austere grotto
#

what's in base.OnEnable();

exotic spear
#

And this is every reference to the event

exotic spear
austere grotto
#

perhaps you're getting an error in OnDisable

#

so it's not unsusbscribing properly

#

so you end up with two subscriptions after a disable/re-enable

exotic spear
#

base

protected virtual void OnDisable()
{
    if (_pingable != null)
    {
        _pingable.OnPing -= OnPing;
    }
}```
turret```c#
protected override void OnDisable()
{
    base.OnDisable();
    _inputReader.OnExitTurretInput -= HandleExitTurret;
}```
#

Ok so I changed something in the prefab and it only seems to be happening once

austere grotto
exotic spear
#

no

#

There is only one Turret Interactable script on the whole prefab

exotic spear
#

ok So I think I've managed to fix the event part but now the _interactingPlayer is coming up as null even after I've removed all lines setting it to null, it's assigned on interact and never unassigned, yet the debugger is detecting it as null in HandleTurretExit

austere grotto
#

Is it "real" null or "destroyed unity object" null

exotic spear
#

nope

exotic spear
#

ok so according to the debugger, _interactingPlayer is null when HandleTurretExit is called but it's not null according to the debug logs in Unity, my brain is officially fried and I'm moving on to another task

dreamy carbon
#

for some really weird reason it doesnt register when i press the left mouse button or the right mouse button but sometimes it does , its really weird , im confused on why it does that

dreamy carbon
#

and i have only one map and in the vid im showing that for some reason the mouse buttons register when i changed a thing in the input action map PlayerControls but after i stop the play mode and start again , it stops registering which is really weird

valid dragon
hasty monolith
#

I'm using unity VR and I've encountered this error. Any idea's what's the issue? I'm trying to run the Meta XR Simulator

dreamy carbon
#

not sure how to fix this

valid dragon
dreamy carbon
valid dragon
dreamy carbon
valid dragon
dreamy carbon
valid dragon
#

I can't say for sure as I haven't used the input system yet, but it probably involved a static field not resetting between play mode sessions.

dreamy carbon
#

THAT MIGHT BE IT TBH

#

oops

#

caps

valid dragon
#

Disabling domain reload implies that static fields need to be reset by you manually

dreamy carbon
#

well thank god i fixed this issue lol

#

thank you

#

how can i check if im i press the left mouse button and when im not pressing the left mouse button?

austere grotto
tame oracle
#
public InputActionProperty leftClickAction;
    public Animator cubeAnimator;
    void Update()
    {
        bool leftClickValue = leftClickAction.action.ReadValue<bool>();
        print("Left Click Value: " + leftClickValue);
    }```
Is this proper for calling things with inputactionproperties? The value doesn't change when I left or right click (Yes I know I set it to right click by acccident in unity)
timid dagger
# tame oracle ```cs public InputActionProperty leftClickAction; public Animator cubeAnimat...

In the case of manual checking, I usually use .WasPressedThisFrame()/.WasPerformedThisFrame() (which works only once per click) or .IsPressed() (which works as long the input is pressed). However usually I register listeners to events, so I don't have to check it in Update (https://docs.unity3d.com/Packages/com.unity.inputsystem@1.9/api/UnityEngine.InputSystem.InputAction.html#events).

When it comes to actions not working, in most cases it's caused by not enabling them or their action maps. Try enabling them if you haven't done that.

tame oracle
#

Good idea I solved it by enabling them xD

#

Oopsies!

dusty falcon
#

how can I get the position where the player clicked or tapped on the screen?

austere grotto
dusty falcon
dusty falcon
#

if it is -1 it will play the sound only in the left speaker

austere grotto
#

I have no idea what you are talking about to be honest

#

what do sounds have to do with a mouse click position

#

if what is -1?

dusty falcon
austere grotto
#

I guess get a world space coordinate that corresponds to your mouse position and either spawn or move an audio source there and play it. Or use AudioSource.PlayClipAtPoint

dusty falcon
austere grotto
dusty falcon
austere grotto
dusty falcon
austere grotto
#

why not

dusty falcon
austere grotto
#

not Input.mousePosition

#

But something like Mouse.current.position.ReadValue() IIRC

dusty falcon
#

for helping

uncut raven
#

Is there a way to change which button is bound on a gamepad if it's a specific brand? For example, I want to use South for jump, unless using a Nintendo controller, in which case I want to use East

austere grotto
hazy tide
#

how can i reblind a control in unity

outer apex
#

Using 6000.0.11f1 and input system 1.8.2, using an input reader scriptable object to subscribe to input events. What's the expected way to use it if we're supposed to Disable() every map?

hazy tide
#

Hello
I have a problem in input when i enter playmode the input names changes but the movement no
but when i change the inputs in the play mode it become fixed
how can i fix that?

unreal smelt
#

I made a Debug.Log check for the brake/reverse input. If the car is stationary or moving backwards, and i hold brake, the car moves backwards and the message keeps getting sent as long as i am holding brake, as expected. but if the car is moving forward and i hold brake, the message is only sent once and the car doesn't brake.

https://gist.github.com/Winter-r/447c521d359129f2586cc6ae923b2dbd

austere grotto
unreal smelt
#

so what should i do

austere grotto
#

what are you trying to do

#

probably start your investigation there

#

I'm not sure I understand how your initial question relates to the braking problem

unreal smelt
#

fixed it, had to do with the slip angle

#

thank you though!

austere grotto
#

right... kinda what I pointed you at

unreal smelt
#

yeah 😅

past river
#

hi! i've installed input system in my project but input system editor is not showing up. when i press the open button on the asset, nothing happens. only the global settings work, but i cannot set up actions. any ideas?

#

i've tried setting active input handling to "both" and input system (new)

austere grotto
#

Can you show screenshots?

past river
#

ah i just closed the project, let me see if i can find a picture

#

i'm talking about the small "open" button in the top right corner of the input settings asset that you have to create to use the input system in a project

#

ah okay wait i think i understand my error now.

#

there's the "input system/settings" asset and then there are "input action" assets...

#

i think i'll be fine now, thanks for checking in!

torpid star
#

My input script is kinda of long. Any improvements that I could make?

#

I want to add inventory buttons (1-9) but it will bloat my script

woeful tusk
#

Is there any elegent simple solution, using the Unity new input system, for zoom in and out using touch screen pinch mechanic?

e.g, when using mouse/wheel you can easy get the Vector2.y and use that value.

Right now, I am using touch1/delta as its good enough, but its obviously inconsistent.

I watched all those ideas on the internet with using two positions and distance magnitutde, but it required too much code and uses corutines.

I want something as simple as mouse wheel up and down.

past river
#

Okay, i'm confused after all.
In the official documentation, for the latest version, it says there is a "default project-wide action asset" or rather that there should exist a button in "Project Settings" under "Input System Package" that would create such an asset for us.

However, such a button does not exist. (there is only a "create settings asset", which is a different thing altogether.)
Also, the proposed way to use said project-wide actions in code, is by typing InputSystem.actions.<something>.
However, auto-completion suggests that InputSystem has no member named actions.

Could it be that the documentation is out-of-date and that the whole notion of default actions was phased out at some point?
Documentation I'm referring to:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.10/manual/ProjectWideActions.html

#

wait, I just saw that I only have Input System 1.7 installed. i assumed the package manager would automatically provide me the latest version. is it because my unity editor is version 2022.3.38f1 ?

austere grotto
past river
#

thx!

next vine
#

Hi all. I have a Vector2 value action where I have a binding with modifiers. I would intuitively expect this action's press boolean to be true when the modifier keys are down, but it is only true when the Vector2 value != 0,0. Is there some way I can make the action 'pressed' when the modifier keys are down but value = default? Thx

(I know I can split the action into two, where one is a button and the other is a V2 value, but if it is possible to avoid this I would rather)

EDIT: solved

I ended up creating a subclass of TwoModifiersComposite that overrides EvaluateMagnitude to return 1 or 0 only depending on whether or not the modifier keys are down.

sinful cedar
#

hey guys, I randomly started getting spammed with these errors when trying to bind a joystick to an input map, has anybody seen something like this?

#
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)```
#
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)```
#

I removed the joystick binding but the errors still remain :Y

idle monolith
#

Hello, I'm using the new input system and I have it so holding the up button has the player hide in a hiding spot, and another use where when you hold the up button you search a spot for scrap, and for some reason these two things have stopped working properly, when you hold the up button for half a second (0.5f) the button stops registering, they remain hidden.

#

        if (upHold == 1)
        {
            upPress = true;
        }
        else if (upHold == 0)
        {
            upPress = false;
        }```
#

upPress fails after 0.5 seconds and I don't know why

austere grotto
idle monolith
#

I don't have interactions or processors on it

#

The above code runs in update

#

here is where I use it

#
            {
                area = col.gameObject.GetComponent<SearchArea>();

                searchProgress = area.searchProgress;

                if (upPress)
                {
                    if (area.searched == false)
                    {
                        if (area.searchProgress < 3)
                        {
                            searching = true;
                            area.searchProgress += Time.deltaTime;
                            searchProgress = area.searchProgress;

                            if (area.sr.sprite != area.sprites[1])
                            {
                                area.sr.sprite = area.sprites[1];
                            }

                            //make dumpster open sound

                            searchBar.SetActive(true);
                            searchBarFill.transform.localScale = new Vector2(area.searchProgress / 3, 1);
                        }
                        else
                        {
                            area.searched = true;

                            scrap += area.scrapAmount;

                            searching = false;

                            StartCoroutine(DumpsterExit());
                        }
                    }
                }
                else
                {
                    if (searching)
                    {
                        area.searchProgress = 0;

                        searching = false;

                        StartCoroutine(DumpsterExit());
                    }
                }
            }```
austere grotto
#

where is this?

#

It would be easier if you just shared the whole script

idle monolith
#

in collisionstay2d

austere grotto
#

Use Debug.Log

idle monolith
#

why would it

austere grotto
idle monolith
#

how do you make it not do that

idle monolith
#

I have never ever heard of this before, so how do I make it not sleep during these interactions, because I think you're right

#

so during the search, make it awake?

austere grotto
#

set it to never sleep of course

idle monolith
#

is never sleep expensive

#

it worked immediately, thank you so much

#

but is it expensive

austere grotto
#

in thjej future use Debug.Log to test your assumptions

#

You assumed the input system was causing your problem which it wasn't

#

so you got stuck

idle monolith
#

I didn't even imagine what it could be so I was grasping at straws

#

I'd never heard of sleep mode before

austere grotto
idle monolith
#

i was using debug.logs but I didn't know what I should be debugging

austere grotto
#

well you thought the input wasn't working properly

#

so that would be a good start

idle monolith
#

I would have never thought it was the rigidBody

austere grotto
#

if you follow basic debugging steps you would get there eventually

#

you would realize OnCollisionStay wasn't running as expected

lime heron
#

is there a way to specifically register left mouse down with the input system? i can only find just left mouse in general

austere grotto
#

basically the short answer to your question is - no and there's no need to do so.

lime heron
#

so basically theres no way to have OnClick trigger only on mouse down

austere grotto
lime heron
#

an action

austere grotto
#

no

#

Click is your action

#

OnClick sounds like some code

lime heron
#

sorry, misspoke

austere grotto
#

and when the code runs is highly dependent on how you choose to hook your code up to the input system

#

for example if you subscribe only to the performed callback of the input action, then it will only run on mouse down

lime heron
#

wait, so is it possible to make this mouse down only? sorry, im pretty new to unity

austere grotto
#

This is just a random function

#

As I mentioned, you would have to explain how you hooked this up to the input system

#

by the nature of your questions, I'm going to venture to guess that you're probably using the PlayerInput component in SendMessages mode?

lime heron
#

yeah

austere grotto
#

that particular combo is much less flexible than others. The short answer is you would need to either:

  • Add an InputValue parameter to your function and check if (myInputValue.Get<float>() != 0)
  • Switch to another approach
lime heron
#

okay, ill look into other approaches

austere grotto
#

if you switch to UnityEvent mode then you will get a InputAction.CallbackContext parameter and you can do if (ctx.performed)

lime heron
#

alr thank you

hazy tide
#

hello
i have this problem when using input system and making a reblinding menu using this

tulip tartan
tulip tartan
hazy tide
#

by the way i have two players and two rebind menu

#

and two inputs

tulip tartan
#

Ok, so everything that is shown in these screenshots is for Player2, but the component is targeting Player/junp
Player has a jump action with the W binding as well, right? jump being lowecase?

hazy tide
#

i think it will be the fifth day

tulip tartan
#

This is super convoluted I don't use that component.
Have you debugged the text coming in and checked it against actual binding names for spelling and capitalization errors?

That is all I can guess.
Praetor or someone more knowledgeable will hopefully be around on a few hours when it is their morning

valid arch
#

Hey everyone, i have a gamepad connected and it works fine when i click any button on it, it gets connect and added to InputSystem.devices, but when i launch the game and i dont click anything, my devices list is empty. Do you know any way to force devices to be added to the list? i tried:

InputSystem.Update();
InputSystem.GetDevice<Gamepad>(new InternedString("Player1"));
InputSystem.FindControls("<Gamepad>");
Gamepad.current

Everything gave no results, all is null or empty lists.

I need it to show correct hints since gamepad is connected, thanks in advance 🙂

solid pagoda
#

why does spacebar triggers my input action even though it isn't binded to the action ?

solid pagoda
austere grotto
#

and yes, your code may very well affect things

#

depending on how you are judging an action being triggered

solid pagoda
#

Place is getting called by LMB and also spacebar

austere grotto
austere grotto
#

also is there a log in that code or something?

solid pagoda
austere grotto
#

so is it possible there's any other code or event hooked up to this function, or to a similar function that would lead you to believe this function is running instead?

#

I would have a Debug.Log as the first line there and you could even check which action and which binding were used to call it from that ctx object

#
Debug.Log($"Called with action: {ctx.action}, control: {ctx.control}");```
solid pagoda
#

I just reassigned the binding it now works fine. weird.

lime rose
#

Hey, is there a way to use splitscreen with the new input system and cinemachine or is there none?

austere grotto
#

the new input system has local multiplayer features, and cinemachine can handle multiple cameras

lime rose
#

Because the documentation mention that it doesn't and I indeed have issues when I try

austere grotto
#

PlayerInput has nothing to do with splitscreen

#

it's part of the input system

#

it doesn't care about screens

austere grotto
#

PlayerInput split-screen support
What does this even mean?

#

Is that some newfeature in the new version of the input system

#

The input system is for input, and generally has nothing to do with rendering

lime rose
#

This thing

#

The split screen checkbox

austere grotto
#

you can do it yourself

#

that's a new thing too

lime rose
#

What do I need to change for that? Because it looks like it would work in theory but doesn't

#

at the end both screens how the same camera

austere grotto
#

set the viewport for each camera differently

lime rose
#

it's already the case

austere grotto
#

they're not both showing the same camera

#

what's probably happening is both your virtual cameras are going to the same place

#

or rather

#

both cinemachine brains are following the same virtual camera

#

the way to fix that depends on which cinemachine version you're using

#

check the cinemachine package documentation for your version and look for "multiple unity cameras"

lime rose
#

I'll check that thanks

fickle geode
#

hey need some help with the new input system

when a button is pressed, the unity event that is supposed to be invoked is triggered 3 times.
how can i fix this? thanks for your time

austere grotto
#

check the phase in the callback context

#

e.g.

if (ctx.performed) {
  DoSomething();
}```
#

Also see:

Debug.Log($"Context phase is {ctx.phase}");```
fickle geode
#

ive seen this online too
from what ive seen this variable is of InputAction.CallbackContext and is passed as a param in the c# method. When i add it as a parameter, the method stops appearing in the editor when i try to add it to the action

austere grotto
#

it should appear just fine

#

as you said, this is done all the time

#

show screenshots

fickle geode
#

one second

#

ill get some now

#

sorry i should have also mentioned i was adding in an additional parameter. If there is no additional parameter, the method appears fine.

austere grotto
#

and the additional parameter doesn't make sense

#

remember, the input system is going to be calling this function for you

#

it would not have any idea how to add an additional parameter or what value to use for it.

fickle geode
#

alright
This code was for enabling and disabling sprinting upon button press and release. Would you recommend I separate this into two different events (that are called by the input system) that then call the ToggleSprint() method with true and false as required?

austere grotto
#

not sure what the "other event" would be

#

all this needs to do is set isSprinting to true or false

#

your other code can say:

float speed = isSprinting ? 2f : 1f;```
#

for example

fickle geode
#

interesting. What ive done so far right now is set up a setter on isSprinting and within the setter entered Movement_Speed = _isSprinting ? 2f : 1f;.

therefore my event is

    private bool _isSprinting = false;
    public bool IsSprinting
    {
        get { return _isSprinting; }
        set {
            _isSprinting = value;
            Movement_Speed = _isSprinting ? 2.0f : 1.0f;
        }
    }
    private void ToggleSprint(InputAction.CallbackContext context)
    {
        if (!context.performed) return;
        
        IsSprinting = !IsSprinting;
    }```
is that a sensible solution?
fickle geode
#

alright thanks :). I appreciate the help man

#

new to this input system and such. everyone starts somewhere ;)

slow shell
#

Hey, I'm trying to figure out whether it's possible to respond to all OnMove events globally, outside of the currently selected GameObject. This is so that if a user clicks or the EventSystem's currently selected Selectable becomes null, when I get any directional input on the controller or cursor keys, I can re-focus the last focused Selectable, which I'm keeping track of in a singleton

#

Or, you know, if anyone has any other better ways to go about that

slow shell
#

Follow up question, since I can't seem to be able to determine if the OnMove thing is worth pursuing, I'm just defining all navigation events (controller D pad, left stick, and arrow keys) in my InputActions, then I'm just going to respond to those events instead of going for a catch-all via OnMove or similar...:

If I put all of my actions in the same global control scheme, is there anything inherently bad about that?

My understanding is just that all of the input actions will be "on" all the time, so I could control my game with a keyboard and controller simultaneously, however, I wouldn't be able to disable/enable a specific subset of them because, well, I would need to separate those actions into different control schemes, then switch to one of them or the other

Am I understanding all of this correctly?

fresh galleon
#

AFAIK you still have to set a specific class instance to respond to the input callbacks. You could create a singleton instance of the generated c# input class, and create separate public Action<context> variables (unless you can do that directly to the generated actions not sure here) for each of the action. Any script wanting to act on it would just subscribe to the singleton Action on Awake() or Start().

A better way I think would be to logically separate the actions you want into several action maps, that the correct script with the correct Interface implementation subscribes to and acts on. So Movement, UI, Minimap navigation etc. each separate. One of the "superpowers" of this new system is being able to do that dynamically and easily

wind hawk
#

Question: If you made two characters and you swap between them with different movement systems for each(EX: You swap between a cat and a fish with two different movements, so walking vs swimming.), would you need to make two different Unity Input Systems for each character? Even if they're both under the same player.

#

Mainly I'm planning to make a 'character' character and a spaceship character which the player can control them both by swapping between them in an instance.

#

However since the 'character' character is more limited by gravity, while the ship character's affected on 3D space, would I need 2 Input systems?

austere grotto
amber wigeon
#

when i'm trying to generate a C# class out of my Input Action Asset, it throws this error:
Assets\Input\Input.cs(18,30): error CS0738: 'Input' does not implement interface member 'IInputActionCollection.devices'. 'Input.devices' cannot implement 'IInputActionCollection.devices' because it does not have the matching return type of 'ReadOnlyArray<InputDevice>?'.. It's the first time I'm seeing this error because it didn't happen before. How do i fix it? I'm using Unity Editor 2022.3.26f1, and the Input System package version is 1.7.0. here's how the generated C# class looks: https://pastebin.com/cc1cMb1b

the only thing that i tried yet is to remove and install the Input System package again, which didn't fix this error.

amber wigeon
austere grotto
#

It might have been generated with an older version and not regenerated

amber prism
#

How do I set up my action map so that I can use the same input for two different actions? For example, clicking to move but also clicking to interact with a UI button?

#

I'm having some trouble figuring it out

austere grotto
#

Is there a good reason you want to override that behavior?

amber prism
#

this thing?

austere grotto
#

If you are trying to get the behavior where clicking to move is blocked by UI then you will get that for free if you implement your click to move through the event system

austere grotto
#

that's not usually necessary

amber prism
austere grotto
#

you also assigned it to a different actions asset

amber prism
#

Yep

#

yeah I don't know what I'm doing

austere grotto
#

Implement the click to move through the event system - I.E. IPointerClickHandler

amber prism
#

I just want to click to move, but if I click on a ui then I shouldn't move

#

that's all I'm going for

austere grotto
#

You will get that for free if you follow my advice

amber prism
#

alright let me see here

austere grotto
#

Two options for this:

  • If you have some kind of "gameplay surface" i.e. your terrain or something, you can put the IPointerClickHandler script on that
#
  • Or you can implement a custom Raycaster to use Plane.Raycast with the event system
amber prism
#

so a new script with something like this?

austere grotto
austere grotto
amber prism
#

I guess not cause I think I fixed it

austere grotto
#

IPointerClickHandler though

#

you're meant to implement it on your script for things that are clickable

#

You could also use the EventTrigger component if you want

amber prism
#

well until I did public interface IPointerClickHandler it couldn't be implemented

austere grotto
#

it's already defined

#

you don't need to define/declare it yourself

amber prism
#

yeah that's what I thought!

#

but that's what it's telling me

austere grotto
#

what does the error say

amber prism
#

the class can't implement the interface member

austere grotto
#

if you take the IDE's auto suggestikon for that it will give you the stub implementation

#

and you can fill it in

#

I'm using Rider

#

but VS has something similar

#

do that and it will give you the method stub

austere grotto
austere grotto
#
Vector3 clickedPosition = pointerEventData.pointerPressRaycast.worldPosition;
Debug.Log($"Clicked at position {clickedPosition});``` would be a good start
#

and you'll want to attach this code to your terrain or whatever

amber prism
#

the pointerEventData doesn't have context

#

what do I do?

austere grotto
amber prism
austere grotto
#

oh that';s just because you named your parameter differently

#

you named it eventData

amber prism
#

OOOHHH

#

oops

#

fixed

#

ok that's working

#

so I'd put my desired movement code in there

#

and get rid of this?

austere grotto
#

of course you will have to communicate between this script and your player object somehow

#

That's hopefully not too much of a challenge

amber prism
#

probably not

#

hopefully not

#

You've been a huge help! thanks for your time! I know I'm not the easiest to instruct so I appreciate the patience

austere grotto
#

you were quite pleasant to instruct

#

have a good day

amber prism
#

you as well!

amber wigeon
#

I tried to generate this class in another project with exact same configuration and package version and it didn’t throw errors, but when I imported this class to my current project, then it threw error as if there was something badly configured in my current project?

amber wigeon
winter basin
#

Is there an api, a method to unsubscribe and remove all listeners for input actions?

#

I want to remove all listeners when unloading the current scene

verbal remnant
winter basin
#

In my mind, when a scene is unloaded, all input action events should be unsubscribed

verbal remnant
#

Also you aren't telling the subscriber that it was unsubscribed so it may be still waiting for callbacks.

#

if you unsubscribe the listener in the publisher, you encode and couple domain knowledge of the lifetime of your entire collection of systems into a single sub-system

tame oracle
#

What this one does? I thought it gets the latest touch position but it stops when first touch stops. I think it gets primary touch? Then why is it seperated?
I want multi touch binding in input actions. There is no reason to not use EnchancedTouch API but i believe it should be possible in input actions too.
I believe this is a bug. They removed the "touch *" from the list but the functionality still works (see OnScreenStick.cs line 96). They may tried to switch to that way.

winter basin
#

There are n scripts. They listen to some input action events. These scripts should listen forever until the scene is unloaded. It is mind blowing why I should unsubscribe them when unloading the scene.
It is obvious it should be unsubscribed when the scene does not exist because it is unloaded

#

My way was to automate it. I mean using for example reflection, in one place, unsubscribe all input action events when the scene is unloaded.
It is not related to publisher

austere grotto
#

The Gamepad class is for the new system and KeyCode is for the old system

#

so which system are you using?

exotic night
#

I'm trying to stun the player and cancel their movements, but have them stop moving when stunned, and when the stun ends if they were holding a direction they will start moving again without having to reinput movement.
My code currently looks like this:
private void OnMovement(InputValue inputValue){ //rb.velocity = inputValue.Get<Vector2>(); if (controllable == true) { rb.velocity = inputValue.Get<Vector2>() * _speed; } else { Debug.Log("Stunned."); } }

austere grotto
#

then you can reapply it as soon as you're un-stunned

#

In fact I would probably just recommend against using event based input handling in general for "continuous" input like a joystick

#

But something like this will work:

Vector2 moveInput;

private void OnMovement(InputValue inputValue) {
    moveInput = inputValue.Get<Vector2>();
}

void FixedUpdate() {
    if (controllable) {
        rb.velocity = moveInput * _speed;
    }   
    else { Debug.Log("Stunned.");  }
}```
exotic night
#

would i be putting the fixedUpdate code in the void Update or would I be calling FixedUpdate in void Update?

austere grotto
#

They are not called "voids" btw, they are called "methods" or "functions"

exotic night
#

I see, thank you for the help. this solution works for me

amber prism
#

I've got this code here that I've converted to work with the input system

   {
       // Uses a reference from the 'PauseMenu' script
       if (Input.GetMouseButtonDown(0) && !PauseMenu.isPaused)
       {
           Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
           RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);

           if (hit.collider != null && hit.collider.CompareTag("Enemy"))
           {
               if (hit.collider.gameObject != currentEnemy)
               {
                   ShowOverlaySprite(hit.collider.gameObject);
               }
           }
       }
   }```
#

into

    {
        // Uses a reference from the 'PauseMenu' script
        if (!PauseMenu.isPaused)
        {
            Vector2 clickPosition = Camera.main.ScreenToWorldPoint(eventData.position);
            RaycastHit2D hit = Physics2D.Raycast(clickPosition, Vector2.zero);

            if (hit.collider != null && hit.collider.CompareTag("Enemy"))
            {
                if (hit.collider.gameObject != currentEnemy)
                {
                    ShowOverlaySprite(hit.collider.gameObject);
                }
            }
        }
    }```
#

the problem is that I need this called from a scene manager object, and not from anything individually

austere grotto
#

(using the singleton pattern)

#

Also just FYI, this code doesn't make a lot of sense to me

#

first off

#

this has nothing to do with the new input system

#

you've switched from reading the mouse position via the old input system to using the Event System

#

(which is not the input system)

amber prism
#

OH

#

I got them confused

#

please excuse me

austere grotto
#

old to new input system conversion would have been:

Input.GetMouseButtonDown(0)``` turns into ```cs
Mouse.current.leftButton.wasPressedThisFrame```
#

And:
Input.mousePosition -> Mouse.current.position.ReadValue()

#

you've done something completely different here

#

That being said - I do recommend using the event system, but the way you've done it is a bit roundabout / wrong

amber prism
#

I may have gotten ahead of myself in trying to change the script

#

I don't think I need to do anything to it

austere grotto
#

If you want to use the event system this script would go on the enemy objects themselves, and call out to the Scene Manager in some way, for example through the singleton pattern, or with events.

amber prism
#

I was in the middle of updating other things and got carried away with this one

#

this script runs fine for what I need it for I think

#

I apologize

tulip tartan
#
  1. this channel is for the input system
  2. we cannot discuss modding in this server
tulip tartan
#

Do you have a question related to the input system?

valid gate
#

Looking for advice. I have two UI action maps, one for general UI and another for character setup/selection UI screen. When I enable the character selection screen I switch action map to the "UI Character Setup" action map, which disables the "UI" action map.

My buttons stopped working, the only thing that works are the buttons I use to change character/etc. I cannot click on any buttons on the UI menu anymore until I switch back to "UI" action map.

Trying to find possible solution, any ideas?
Image 1: input analyzer, showing the UI action map being disabled and UI Character Setup is active.
Image 2: This is what the Input System UI Input Module looks like, it has references to the UI action map. Maybe here's the problem?

#

here's the action maps

austere grotto
#

are you using PlayerInput? How did you hook your actions up to your code?

valid gate
#
  1. I've added gamepad inputs to my own actions asset that the default don't use
  2. I'm calling a script that's on the player that holds a reference to the PlayerInput component, supplying a string of the name of the new action map: public void SwitchActionMap (string _actionMap) => playerInput.SwitchCurrentActionMap(_actionMap);
  3. I'm invoking Unity Events on the PlayerInput component which I've setup to call a function in my PlayerInputHandler:
  switch (_context.phase) {
    case InputActionPhase.Performed:
      IsReady = !IsReady;
      Ready.Invoke(IsReady);

      break;
  }
}```
austere grotto
#

you don't want to do that if your asset is being used for UI input that still needs to work

#

Two options:

  • Forgoe using SwitchActionMap and enable/disable action maps manually e.g. via myPlayerInput.actions.FindActionMap("MyMapName").Enable()/Disable()
  • Put the UI stuff that is used in the input module in a separate asset altogether.
valid gate
#

Thank you, I'll try it out 🙂

timid dagger
#

[legacy Input / Rewired]
I'm working on a project where we're using Rewired to handle inputs, but I've noticed issues on mobile platforms. For example, when I test my Dualsense gamepad on iOS, it fails to detect some inputs properly. For example, Rewired treats Options buttons as Button 8, but so it does Share button. When I tested XBox gamepad, the scenario was the same, both Start and Back buttons were treated as Button 8. It makes it impossible to distinguish those buttons. I also can't detect Dualsense pressing Touchpad button at all. I've compared it to the legacy Unity's Input, and scenario looks more or less the same - Touchpad button can't be detected, Share/Back button is treated as Joystick1Button0 (4 or 5 times, for some reason), Start/Options button is treated as both Joystick1Button0 and Joystick1Button16 (which 2 buttons are treated as the same button), and also Dualsense can't detect Tochpad button. On the other hand, on Desktop versions everything works like a charm.

So the question is: are there any ways of fixing it manually, or do I have to change input system in the entire project?

finite hollow
#

Anyone have a working Input Action Asset for Unity 6 for OpenXR? It doesn't work anymore and I am unable to map it

amber prism
#

I'm making a build for android but it throws up this error when I have my input settings set to "Both"

#

so I switch it to just the "New" one and then I get a million errors on play. My input also doesn't work after this point.

#

I'm not sure what to do about this. Does anyone have any ideas?

austere grotto
#

you need to convert your code to use the new system of course.

amber prism
#

that's what I was afraid it was saying

#

I was really hoping there was an easier solution

austere grotto
#

I mean it seems pretty obvious

#

also it's very easy

austere grotto
#

what you are afraid of here, though, is learning

amber prism
#

my issue is the work to convert

austere grotto
#

Once you know how the new input system works, it's very little work

amber prism
#

I just want the game to run already 😔

austere grotto
#

then just stick with the old

amber prism
#

the old wasn't working with android

austere grotto
#

why did you switch to the new system if you want to use the old one?

amber prism
#

that's why I switched

austere grotto
#

what specifically wasn't working?

#

The old system works fine with Android in general

amber prism
#

@austere grotto then using the new system is what I'll do (I didn't want to split the conversation too much)

#

@austere grotto do you have a guide that explains the conversion process?

austere grotto
#

Have you checked the docs? The docs have such a thing. but it's best to just learn the new system from scratch and then apply it as you need

amber prism
#

yeah that's what I was looking for

#

thank you

austere grotto
#

This is the best advice:

If you're new to the Input System package and have landed on this page looking for documentation, it's best to read the QuickStart Guide, and the Concepts and Workflows pages from the introduction section of the documentation, so that you can make sure you're choosing the best workflow for your project's input requirements.

This is because there are a number of different ways to read input using the Input System, and many of the directly corresponding API methods on this page might give you the quickest but least flexible solution, and may not be suitable for a project with more complex requirements.

verbal remnant
hoary whale
#

Why isn't this working? Some context: I'm using the new Input System and invoking unity events to the Player Input component
What I want is this:

if (JumpPressed && IsGrounded()) 
{
}
// Jump was pressed ONCE; even if you hold jump, you wouldn’t jump again    
if (JumpPressedThisFrame && IsGrounded())   
{
}
// Jump ONCE on release; not really something I'd use, but yea
if (JumpReleasedThisFrame && IsGrounded())   
{
}```

Right now, JumpPressed works as intended, JumpPressedThisFrame behaves like JumpPressed, and JumpReleasedThisFrame is acting weird, it works like JumpPressed, but continues jumping on its own once I release
.
#

.
Here’s the relevant code. I’m quite new, so I’m probably doing this the wrong way or missing something very simple

PlayerInputHandler.cs

{
    public bool JumpPressed { get; private set; }
    public bool JumpPressedThisFrame { get; private set; }
    public bool JumpReleasedThisFrame { get; private set; }

    public void OnJumpInput(InputAction.CallbackContext context)
    {
        JumpPressed = context.action.IsPressed();
        JumpPressedThisFrame = context.action.WasPressedThisFrame();
        JumpReleasedThisFrame = context.action.WasReleasedThisFrame();
    }
}```

PlayerState.cs
```public abstract class PlayerState
{
    protected Player Player { get; private set; }
    public bool JumpPressed { get; private set; }
    public bool JumpPressedThisFrame { get; private set; }
    public bool JumpReleasedThisFrame { get; private set; }

    public virtual void UpdateLogic()
    {
        UpdateInputs();
    }
    private void UpdateInputs()
    {
        JumpPressed = Player.InputHandler.JumpPressed;
        JumpPressedThisFrame = Player.InputHandler.JumpPressedThisFrame;
        JumpReleasedThisFrame = Player.InputHandler.JumpReleasedThisFrame;
    }
}```

PlayerIdleState.cs
```public class PlayerIdleState : PlayerState
{
    public override void UpdateLogic()
    {
        base.UpdateLogic();

        if (JumpPressedThisFrame && IsGrounded())
        {
            StateMachine.ChangeState(Player.JumpState);
        }
    }
}```
austere grotto
#

Because the OnJumpInput function is only going to run at the exact moment you press or release the button

#

So these:

        JumpPressedThisFrame = context.action.WasPressedThisFrame();
        JumpReleasedThisFrame = context.action.WasReleasedThisFrame();```
Will become stale after one frame
#

Really it doesn't make a lot of sense to use event-based input handling to set state-based input data

#

You should pick one or the other

#

either read your inputs in Update, or use events

#

don't use events to set data that you then read in Update, it makes things weird.

hoary whale
#

Okay, so I ditched the player input component and generated the class instead

I'm doing this now in my handler, and it works. I'm still not sure if this is the best way

    {
        MoveInput = Actions.Player.Move.ReadValue<Vector2>();

        JumpPressed = Actions.Player.Jump.IsPressed();
        JumpPressedThisFrame = Actions.Player.Jump.WasPressedThisFrame();
        JumpReleasedThisFrame = Actions.Player.Jump.WasReleasedThisFrame();
    }```
Also, I'll be honest, I missed one if in my fall state. But yeah, my previous approach was definitely not working anyway according to the debug logs, so it doesn't really matter
austere grotto
#

In fact you could ditch this middleman class and directly reference the actions instance

#

Or just expose the actions instance instead of individual variables/properties

devout tinsel
#

hello! I wanted to download a newer input system version manually. does anyone know if its safe to install the latest one (10.0) or do I install 9.0?

hoary whale
# austere grotto You could just make these properties and ditch Update altogether

Wait that's actually cool
so like this?
in PlayerState

    public float InputY => Player.InputHandler.Actions.Player.Move.ReadValue<Vector2>().y;
    public bool JumpPressed => Player.InputHandler.Actions.Player.Jump.IsPressed();
    public bool JumpPressedThisFrame => Player.InputHandler.Actions.Player.Jump.WasPressedThisFrame();
    public bool JumpReleasedThisFrame => Player.InputHandler.Actions.Player.Jump.WasReleasedThisFrame();```
and in InputHandler I'd just have this, and I could and probably will move this into Player instead, we'll see
```    public PlayerIA Actions;
    private void Awake() => Actions = new PlayerIA();
    private void OnEnable() => Actions.Enable();
    private void OnDisable() => Actions.Disable();```
gusty acorn
#

Hello Hello!

I am pretty new to Unity but running into something I just can't seem to figure out.
I want to track when I press the jump button, but outside of my OnJump function, jumpButtonDown always comes up as false. I beleive it has something to do with the fac tthat OnJump is called 3 times, started, performed, and cancelled, and after an instant started is false, but I can't think of a way to have a jumpButtonDown variable that I can use throughout the rest of my code

        jumpAction = context.ReadValue<float>();
        jumpButtonDown = context.started;
        if (context.started && (touchingDirections.IsGrounded || jumpsRemaining != 0 && !IsWallJumping && !IsWallSliding)) {
            rb.velocity = new Vector2(rb.velocity.x, jumpsRemaining != maxJumps ? doubleJumpeImpulse : jumpImpulse);

            jumpsRemaining--;
        }
        if (context.canceled && rb.velocity.y > 0 && !IsWallJumping && !IsWallSliding) {
            rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
        }
    }

    private void WallJump() {
       if (jumpButtonDown && wallJumpingCounter > 0f) {
            IsWallJumping = true;
            rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);
            wallJumpingCounter = 0f;

            Invoke(nameof(StopWallJumping), wallJumpingDuration);
        }
    }

    private void Update() {
        horizontal = moveInput.x;

        WallSlide();
        WallJump();
        if (jumpButtonDown) {
            Debug.Log("jumpButtonDown in Update");
        }

        if (touchingDirections.IsGrounded && !(jumpAction > 0)) {
            jumpsRemaining = maxJumps;
        }
        if (!touchingDirections.IsGrounded && jumpsRemaining > (maxJumps - 2)) {
            jumpsRemaining = maxJumps - 1;
        }
    }

So in both Update and WallJump jumpButtonDown never registers as true, though it does in OnJump

austere grotto
#

And yes it's because of the second line in your function

#

It's clearly going to set it false

gusty acorn
austere grotto
#

It's unclear to me why you need to check for the input in Update

#

Your code is already handling the jump in OnJump

gusty acorn
#

I am looking for a way of tracking when the button is pressed outside of the OnJump

austere grotto
#

Make a bool for whatever you want but you need to have a well defined place to make it false again

#

Because your current logic doesn't make sense

#

You're setting it to false on the performed and canceled input phases

#

You shouldn't do anything for those

gusty acorn
#

This makes sense

gusty acorn
austere grotto
#

Use an if statement

#
if (context.performed) {
  myBool = true;
}```
gusty acorn
#

Sorry, I think I am a little bit lost on what I should be calling for this if statement.

I think I am just not sure what ctx.performed means and where in the code I would want this if statment.

Sorry for these super basic questions

austere grotto
#

context

#

I'm talking about code that would go in OnJump

#

Instead of what you have now which doesn't make sense

gusty acorn
#

so something like this?

austere grotto
#

Your parameter is called context

#

Not ctx

#

And jumpButtonDown isn't a good name for that variable really

#

It depends what you're trying to do with it

gusty acorn
#

so wouldn't this always be true as long as i am holding the jump button?

austere grotto
#

No it will become true when you first press the button and then never change

#

Until you have some other code change it

#

If you have code in Update that uses it you would set it false after you use it

#

But again, you could just avoid all this and do everything in OnJump in the first place

gusty acorn
#

Ahhh so move my WallJump code into OnJump?

#

okay that makes the most sense I think

#

rather than having WallJump as a seperate function, just have WallJump work inside of my OnJump function

#

I didn't think about that

#

but makes sense

sullen pebble
austere grotto
#

But depending on the type of difference you want, it can be done with processors

sullen pebble
#

thats what I want to do but how

sullen pebble
#

true but how do I get the scheme from the input control

austere grotto
#

why do you need the scheme

#

check if it's a keyboard key or a controller button

#

Maybe you could back up here and explain what exactly you want to do differently in each case and why you feel you need this.

sullen pebble
#

well

#

when the player presses the shoot button on mouse then it will shoot towards the mouse

#

when the player presses it on controller it should use the right stick

#

to aim

austere grotto
#

that doesn't sound like anything that should be handled in the button handling part

#

mouse aiming and joystick aiming are quite different

#

you can/should just have two separate actions for those

#

and those determine the aim

sullen pebble
#

alright

austere grotto
#

the firing part is simple

#

just shoot wherever you're aiming

sullen pebble
#

ur right

exotic night
#

I have code that's makes it so that when the player controls are removed, their movement stops right at that moment, then movement continues again the moment theyre allowed to move again without having to repress movement buttons, but it's stuffing the jumps.
if (controllable) { rb.velocity = moveInput * _speed; } else { rb.velocity = rb.velocity * 0; }
the jump code is:
rb.AddForce(Vector3.up * JumpAbility, ForceMode.Impulse); rb.velocity = new Vector3(rb.velocity.x, 0, 0);

quasi chasm
#

if it does, it immediately overrides all changes you do in the jump code

#

what you should do, is have two functions, ControlLost and ControlRegained
and in ControlLost take the velocity and store it in a separate variable, then set the velocity to zero
and in ControlRegained, take that velocity stored in a separate variable, and set the velocity to it
orrrr you could just use OnKey instead of OnKeyDown (or equivalent in new input system if you're using that) and not bother with that at all

exotic night
#

yeah the first line of code is in void Update, and the jump code is linked to the input system, sorry should of clarified that.
So would I be putting control lost and control regain in the update function then?

sullen pebble
#

whats the best way to check whether the player is using a mouse or a controller

#

I just need to switch aiming modes depending

#

and hide the aiming reticle

spare frigate
sullen pebble
#

I found it

#

callbackcontext.control.device is Gamepad

exotic night
# quasi chasm what you should do, is have two functions, ControlLost and ControlRegained and i...

took awhile for me to figure out how to do this but I just got it working and replaced every call to make controllable false with ctrl lost and vice versa, and then had two variables to read the direction input for rb.velocity, and had rb.velocity set to zero while control was lost, then set rb.velocity to that variable and timed it by speed when controls were regained.
my appreciate for the help.

iron flicker
#

Hello

#

How to make a 3 sec hold button?
with a radiant progress bar

austere grotto
#

Or a Coroutine plus those events

iron flicker
#

no, i use new input

tulip tartan
#

So same difference. Start the timer in performed (or .started), stop in canceled.
If started, add time in update or using a coroutine

iron flicker
#

Are you sure you need a coroutine?

tulip tartan
#

You can use Update, as we both mentioned

#

Or tasks

iron flicker
#

okay ,ty

verbal remnant
sinful cedar
#

hey guys, just have a quick question about changing input maps at runtime - I have two control schemes that I need to swap between and a few keys/mouse inputs that do something different depending on the control scheme

#

my input actions are currently set up to call events like this

#

so if I change the action asset I'm thinking it'd probably reset the event maps, right? Is there a way around this?

timid dagger
# sinful cedar hey guys, just have a quick question about changing input maps at runtime - I ha...

I think inputs in the Input System were supposed to have their maps permanent. Instead of changing their maps in runtime, you can simply create 2 different references to Input Actions, and attach different events to different references. E.g. if you created Input Action "Navigation" in map "Gameplay" and "UI", then you could assign Gameplay's Navigation to the character controller and UI's Navigation to some UI elements. Then you enable/disable particular maps depending on what kind of utility you want to use right now. No events will be reset that way.

If you want to juggle Input Actions without losing their data during the process, I would suggest switching to InputActionReference, as it will refer to one shared instance of it. That way all listeners will be added to the same event and nothing will be lost during swapping the references. However you will need to remember to clean up the listeners when the script will no longer need to listen to the Input (so usually in OnDisable or OnDestroy).

sinful cedar
# timid dagger I think inputs in the Input System were supposed to have their maps permanent. I...

hey, thanks for this tip - the former is kind of what how I approached it in the end, there are two control schemes that I'm trying to swap between that aren't just different input types but different control concepts, one is a joystick and one is a 'pointer', but they control the same entity who has a Player Input component with the input action asset mapped. What I've done is I've added the 'pointer' scheme to another game object referencing the player and then have some if statements in the player component that checks what control scheme is active

rotund rose
#

I have a niche question/problem:
I'm currently trying to implement steamdeck accessibility to my game.
But I am unable to invoke the SteamDeck keyboard via iSteamUtils GamepadTextInput but it doesn't seem to be working. Despite having it coded--correctly.

Note: Yes, the Steamworks.NET lib is imported and works as expected.
Referenced documentation: https://partner.steamgames.com/doc/api/ISteamUtils#ShowGamepadTextInput

I'd like to know if someone can help with this?

vale harbor
#

guys i need some help i have an action which takes mouse delta and uses it to rotate a camera for third person now i want to implement this on a phone in which if u move ur finger around the screen the camera moves like those fps mobile game. How this should be done

spare fable
#

hello, i am on my first Unity Project which is about Handtracking with Ultraleap. I do it as my final project at university.
Since Ultraleap made his Server "read only" i am missing a fast source for help.
Now i got problems with the ultraleap plugin due to the new update and even using the older version doesnt fix my errors anymore...

is someone here who can help me and has some experience with Ultraleap and its plugin?

#

short summary:

had an error and couldnt go run time so i updated from 6.15.0 to 7.0.0 but then i got typ and namespace errors and all of my interaction cubes and prefabs were missing.

so i removed it and installed 6.15.0 again. Cubes and prefabs are back but now i still got this errors again, which i didnt hat the last time i used this verson:

Assets\Samples\Ultraleap Tracking\7.0.0\XR Examples\Example Assets\Physical Hands\Scripts\PhysicalHandsChangeColoursOnHandEvents.cs(96,31): error CS0246: The type or namespace name 'ContactHand' could not be found (are you missing a using directive or an assembly reference?)

split epoch
#

hi, i have a really basic question because i'm new to InputSystem (and Unity)

i'd like to have controls trigger events in different objects. for example, some controls to move the player, and other controls to cause changes in the environment

I tried using PlayerInput components for each object, but it only seems to want to use one of them at a time, so I assume it's the recommended method to only have one

How do I recieve InputSystem events on non-player objects?

#

I can think of a few ways it could be done by relaying the information, but I want my player to strictly handle player code and my environment to handle environment code. I'm also concerned about latency if I add too much between the input and the result

sage lake
#

I am a little bit confused. I set up the default input system for my controller and the only part that seems to work is my left stick? the right stick or buttons just don't end up working. Any idea why?

split epoch
#

idk about that but are you confusing joystick with thumbstick?

sage lake
#

I doubt it because these are the inputs afaik

#

it doesn't let you input anything that isn't valid

austere grotto
sage lake
#

OH TRUE

#

well that explains Right stick

#

not the buttons though

#

actually it still doesn't work

#

so uh...

#

and replacing that broke the left stick too...

#

I think my controller is just being weird and that is why my left stick works?

#

maybe its just being read as a keyboard which would suck :)

#

that seems to be the reason :/

#

I also added duplicates for controller input

#

I didn't notice they where originally there

split epoch
# split epoch hi, i have a really basic question because i'm new to InputSystem (and Unity) i...

I feel like i'm just not understanding how the whole InputSystem is supposed to work. reading the docs more and it looks to me like:

  1. each Player Input Component is supposed to represent exactly one player
  2. a Player Manager Component is used to handle multiplayer

therefore i should only have one Player Input Component, anywhere in my project because it is singleplayer, and no Player Manager Component

  1. Schemes are for different devices
  2. Action Maps are for different binding layouts on those devices
  3. Project-Wide Actions are supposed to be actions that are always used, regardless of what scenes are loaded. for example, UI menu controls

therefore my player actions should not be project wide actions

... so how do i have one user (one Player Input Component, zero project-wide actions) trigger events on multiple in-game objects?

#

I could make an object thats like a "Player Input Handler" which has the singular component, but then i'll have to manually recreate all of the built-in events in order to trigger them for other objects.
this is 1. not seeming like the intended use, 2. a lot of work, and 3, seems like it would increase latency

austere grotto
#

And no "latency" is not a major concern

#

But as noted the PlayerInput/PlayerInputManager combo is primarily intended for local multiplayer

split epoch
tribal sable
#

how do i add a 2d vector composite?

#

this is what appears in the tutorial i'm following

#

positive/negative binding just created a 1d one

#

nvm i got it to work

austere grotto
quaint flax
#

Does anyone know how to manually set inputs to specific users, I have two control schemes in my game and It's not allowing me to switch between controller and mouse and keyboard because it thinks it's two different players
If I set the control scheme to Controller the controller works, but if it's set to all only the keyboard does which is user 0

austere grotto
bold mica
#

Hi, I'm trying to make this input script i saw on a tutorial and i copied exactly as it was on the video and it gives me an error, i'm new to all this game-making stuff so i don't really know how to see what's wrong

#

this error

austere grotto
#

Before you do anything else you need to fix that

#

!ide

sonic sageBOT
bold mica
#

like this?

#

oh, it fixed itself lol

#

thanks haha

torpid ember
#

How do you change action maps?
I've been having a hard time understanding how write the code to change it
I've been trying to write code to switch from the current action map named "Player" to one named "UI" and I can't seem to get it to work

#

I tried doing this from a video I saw but I keep getting the error "MenuPause.cs(23,25): error CS1061: 'PlayerInput' does not contain a definition for 'actions' and no accessible extension method 'actions' accepting a first argument of type 'PlayerInput' could be found (are you missing a using directive or an assembly reference?)"

#

wait I think I may have figured out what I've been doing wrong

austere grotto
#

In your case though it's a naming problem

#

You named your asset PlayerInput so the generated class name is hiding the built in PlayerInput component

sage lake
#

I set up the Unity Input system to do this to just read the button value out of it. but for some reason it reads the value 2x when I press the button which is weird. I get a total of 3 inputs which messes up my checks. How would I fix this?

austere grotto
#

Then you'll see what's happening

sage lake
#

I assume its press, hold and release

#

makes sense though

#

found out how to fix it either way so we good 👍

austere grotto
proven marlin
#

When using the 'new' Input System through C# events (generating the C# class, etc.), the best approach for clean code and performance is to directly call that generated C# class in other scripts, instead of using something like a manager in the scene? Bc I did this, but now I think it might be kind of dumb
https://gdl.space/axajosaguc.cs
https://gdl.space/basebosaxo.cs

sonic sageBOT
sinful cedar
#

hey guys, have a bit of an elemetary question about the escape key being used for two different input actions

#

I have a pause menu which contains an additional submenu

#

so I'd like for the escape button to exit the submenu > exit pause menu

#

what I've done is this: ``` public void OnPause(InputAction.CallbackContext context)
{
if (context.action.phase == InputActionPhase.Performed && !GameManager.PauseController.inOptions)
{
print("not in options");
GameManager.Instance.Pause();
}
}

public void OnBack(InputAction.CallbackContext context)
{
    if (context.action.phase == InputActionPhase.Performed && GameManager.PauseController.inOptions)
    {
        print("pause back");            
        GameManager.PauseController.ChangeSelection();
        GameManager.PauseController.inOptions = false;
    }
}```
#

however, pressing the escape key when I'm in the submenu calls both functions

#

I've made both actions buttons, but no luck

#

anybody have any ideas?

austere grotto
sinful cedar
#

I'd like escape to return to the main pause menu from the sub menu, then you press escape again to completely exit the pause menu and return to the game

hot gale
#

Hey guys! I have a smart screen issue I can't quite wrap my head around. In my game, I want to allow multitouch so that the user can use the joystick UI on one side of the screen and a button UI on the other side of the screen. They need to always be able to use both those UI elements. However there is also a panning/zooming feature. I want to ignore that while using the joystick.

My issue is that when a second finger comes down on the screen, the input seems to consider the new input location to be off the joystick and ignores my joystick check all together. Any ideas on how I might fix this?

violet niche
#

Hello! I have an XBOX controller conected to my PC and on Unity i set up this binding which i expect not to trigger with the XBOX controller as there is a separate XBOX A/B/X/Y.
Should i disable Gamepad myself or is unity in charge? Im getting the input triggered with the XBOX controller

austere grotto
#

Gamepad bindings work for all gamepads including Xbox controllers

#

It's hard to understand what you expect or want here. You want it to work for all gamepads except Xbox for some reason?

violet niche
lethal isle
#

Hi guys. I m following some tutorial regarding Camera follow but they are using old input mechanisms. I m moving it to the new input system but I ve a question: If I'm doing something like cinemachineCamera.Lens.FieldOfView = myValue , can I keep it in my function or should be in the FixedUpdate()or Update() method? thanks

austere grotto
lethal isle
# austere grotto Keep it in what function? You would do it wherever it makes sense to do it based...

thanks for your feedback. Here is the code I have (I've remove some no usefull part)

using Unity.Cinemachine;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.EnhancedTouch;

public class CameraSystem : MonoBehaviour
{
    [SerializeField] private CinemachineCamera cinemachineCamera;

    [SerializeField] private float zoomSpeed = 10f;

    [Header("Field Of View")]
    [SerializeField] private float fieldOfViewMin = 10;
    [SerializeField] private float fieldOfViewMax = 50;
    

    private TouchControls cameraControlActions;
    private float fieldOfView;

    private void Awake() {
        // Enable enhanced touch support if not already
        if (!EnhancedTouchSupport.enabled)
            EnhancedTouchSupport.Enable();

        fieldOfView = cinemachineCamera.Lens.FieldOfView;

        cameraControlActions = new TouchControls();
        cameraControlActions.Camera.Enable();
        cameraControlActions.Camera.Pinch.performed += HandleCameraZoom_FieldOfView;
    }

    private void FixedUpdate() 
    {
        cinemachineCamera.Lens.FieldOfView = fieldOfView; 
    }


    private void HandleCameraZoom_FieldOfView(InputAction.CallbackContext context)
    {
        float yDelta = cameraControlActions.Camera.Pinch.ReadValue<Vector2>().y;

        if (yDelta > 0 ) {
            targetFieldOfView -= 5;
        }

        if (yDelta < 0 ) {
            targetFieldOfView += 5;
        }

        targetFieldOfView = Mathf.Clamp(targetFieldOfView, fieldOfViewMin, fieldOfViewMax);

        fieldOfView = Mathf.Lerp(cinemachineCamera.Lens.FieldOfView, targetFieldOfView, Time.deltaTime * zoomSpeed);
    }


}

On this case, instead having a FixedUpdate() method can do on HandleCameraZoom_FieldOfView:

cinemachineCamera.Lens.FieldOfView = Mathf.Lerp(cinemachineCamera.Lens.FieldOfView, targetFieldOfView, Time.deltaTime * zoomSpeed);
``` or it can cause some strange effect ?
azure gyro
#

Hi does new input system run on the MainThread or its running on the a different thread? If its on the mainthread theres any easy way to make it run on adifferent thread without using dots?

austere grotto
azure gyro
#

Because its blocking the sending of websockets and I needed to send IRL the information (this when using a stylus)

austere grotto
austere grotto
#

What does the input system have to do with your websockets stuff

azure gyro
#

It gets the input and then needs to send the x,y position by ws

austere grotto
#

This isn't an input system question really

#

As with anything you do with networking, it needs to be done on a separate thread

#

If necessary you can communicate between your threads via something like a ConcurrentQueue

azure gyro
#

Yes I was doing that but the thing is the input is blocking the firing of the other thread

lethal isle
azure gyro
#

Like its adding everything to the queue and then only sending it after it stops receiving the input but maybe its a skill issue in my end on the queue system and threading thank you either way

austere grotto
austere grotto
lethal isle
analog junco
#

Hi
I read the documentation of Unity on the system input and I don't really understand what change between the differents action type. Can someone explain me the difference with some examples if it's possible ?

tropic sorrel
#

I'm using new input system. When detecting a click, it goes for "value change" on the buttons I'm checking. It seems to give me like two actions per trigger clicked, one for pressing down, and one for releasing.
I just want one action. I've been trying the different "Action types" in combination with "Initial state check", but can't seem to get it sorted.

Using the recommended method using gui links and:
public void OnChangeWeapon(InputAction.CallbackContext context)

austere grotto
#

if (context.performed)

#

To be understand better what's happening here you can do Debug.Log($"Phase is {context.phase}");

tropic sorrel
#

I can only find one instance of the Player Input

#
    {
        if (context.performed) {
            Debug.Log("Attack just pressed once?");
        }
        if (ControlPlayer != null ) {
    //        ControlPlayer.Shoot();
        }
    }

    public void OnChangeWeapon(InputAction.CallbackContext context)
    {
        if (context.performed) {
            Debug.Log("SWitch weapon pressed once?");
        }
        if (ControlPlayer != null ) {
    //        ControlPlayer.EquipWeapon();
        }
    }```
tropic sorrel
#

This might be the ugliest code I've ever written:

    {
        if (alreadypressed) {
            alreadypressed = false;
        } else {
            if (ControlPlayer != null ) {
                ControlPlayer.Shoot();
            }
            alreadypressed = true;
        }

    }```
tropic sorrel
austere grotto
#

There's no need for you workaround and ugly code here

#

Set up a simple Button action and remove ALL interactions and processors, and you can do it with just the single performed check

tropic sorrel
#

Not using any interactions or processors, just events between the "Player Input" and my input controller

austere grotto
#

You need the if statement as I mentioned

tropic sorrel
#

Something is really strange with my implementation I think

#

Should it be possible to have two active Action Maps at the same time?

austere grotto
#

Yes it's possible and normal

tropic sorrel
#

Hmm I deleted all my Input System stuff, and added it again, and now it works just as expected

livid kiln
#

With the new input system the Submit & Cancel buttons work using my custom input actions but with navigation (WASD) it doesn't trigger the event (pic 1) but it works normally for button navigation. How do I make "Navigate" trigger it's event?

austere grotto
#

The PlayerInput component generally only enables one action map at a time though

#

So that might be your issue

livid kiln
livid kiln
austere grotto
#

But also, that's a completely separate input action asset isn't it? You're using the generated c# class there

#

That wouldn't be related to your PlayerInput

livid kiln
wild harness
#

Hey folks, odd problem here. I want to click on an object and have the camera follow that object around in a unity 2D environment. It works, but when the camera relocates, the mouse cursor is no longer over the object as the screen has shifted. This causes the next Update() call to execute Input.GetMouseButton(0) again on that new location, and immediately de-select the object. I've confirmed that Input.GetMouseButton(0) only executes once when clicking or tapping without the camera being shifted. As this will be a performance heavy mobile game I cannot use the new Input system to warp the mouse over to the new location. Everything I've read is the performance is not production-worthy yet. Any ideas how I might work around this?

austere grotto
tulip tartan
wild harness
#

As with most things, perhaps its better now. But with my limited resources I'd rather focus on other things for the time being.

wild harness
#

I didn't save any links to the forum posts and bug reports I was browsing through 😦

austere grotto
#

(again this is academic because your problem is code related anyway)

wild harness
#

If I have time I'll go browsing through them again.

#

I'm not convinced the mouse warp is a total solution anyways.

wild harness
# austere grotto (again this is academic because your problem is code related anyway)

Don't get me wrong, time and resources allowing I'll usually go and benchmark/profile specific things for myself. I spent the morning just browsing through discussions and bug reports and it felt like the new Input system is considerably more powerful, but like most things all those layers make it more suitable for higher end targets. Better to KISS while still learning. I take it you have observed comparable or better performance out of it compared to the legacy system?

tulip tartan
wild harness
#

Could you perhaps link me to that discussion?

tulip tartan
#

I heard it directly from unity employees, so no

wild harness
#

Performance topics sadly tend to be a bit like religion. I see the URP vs BiRP argument crop up often and it is always interesting seeing the sides taken and the different opinion posited by Unity themselves on it. Mobile platforms are damn finicky too which doesn't help.

#

This isn't exactly what I formed my opinion on from earlier, but just a few minutes here trying to retrace my steps:
Here is a report from 5 days ago reporting slow performance on Switch: https://discussions.unity.com/t/new-input-system-is-slow/1506150/2

This is a lengthy back and forth over the last 2 years with a game studio involved discussing the poor performance. It seemed most abandoned it in favor of other approaches: https://discussions.unity.com/t/why-is-the-new-input-system-so-slow/873099/16

Another performance related issue: https://discussions.unity.com/t/new-input-system-performance/864595/13 the final post has an improvement by 2ms still isn't acceptable?

Discussion from earlier this year on it: https://www.reddit.com/r/Unity3D/comments/18w28ao/3_years_later_how_do_yall_feel_about_the_new/ my takeaway is most enjoy the added capability, but find it difficult to setup and has performance drawbacks still

Bug report about input lag on the new system: https://issuetracker.unity3d.com/issues/new-input-system-experiences-1-2-frames-of-input-delay-when-compared-to-the-legacy-input-manager

Deep dive from April on input lag with Android on the new system in Unity 2021 vs 2020 : https://discussions.unity.com/t/input-stutters-android/927902

Reddit

Explore this post and more from the Unity3D community

#

I certainly have no testing on my own to form an opinion with. Just thought I'd take a look and, seeing some complaints, thought it best to avoid it for now given the type of game I'm working on is all.

#

Hope that makes sense!

glossy grove
austere grotto
#

That doesn't mean it's not there

#

Just that I've never noticed it

wild harness
tired bough
#

Can someone tell me what I’m doing wrong?
I made input fields to fill out information for something.
I want that information to be sent per email, so I added a button that opens the mobile mail app and the custom inputs are supposed to transfer into a template.
The body doesn’t work, it prints everything like the second picture

austere grotto
#

Why are you using GameObject fields

tired bough
#

i want the things in the "" to be the template and the gameobjects to be custom inputs

austere grotto
#

You know when you do GameObject.ToString what you get is something like that right?

#

Shouldn't you be reading the text from your text input fields?

tired bough
#

no i dont know, thats why i'm asking? 🤨

austere grotto
#

GameObject references aren't useful here

#

You want to reference the InputField or TMP_InputField s that you are using

#

And read their .text property

tired bough
#

sry that i dont know where to post a question in all these channels, I'm working with input fields, so i assumed i ask in the input channel

austere grotto
#

Understandable confusion, but this is about the systems that handle input from hardware like keyboard, nice, gamepads etc

cloud notch
#

i have a trouble with input system

#

i dont know why my scripts dont detect OnMouseEnter OnMouseExit or OnPointerEnter OnPointerExit i dont know what i am doing wrong

tulip tartan
#

You could try setting the input you use to "both"

cloud notch
austere grotto
cloud notch
#

how to setup UI events to make this?

austere grotto
#

What does "I have a Raycast right know in the scene" mean

cloud notch
#

mi camera have a one

austere grotto
#

The camera would get a physics raycaster

cloud notch
#

i fix it but nothing changes,

#

any message in the console from debug code :I

#

i'm trying creating a MouseMoveEvent

#

to fix this problem

#

works perfectly fine

austere grotto
leaden pivot
#

Hello, I'm running into a really basic setup issue with InputActions. I've created an InputAction object like so: (and let's just focus on move_n for now)

#

with my listener class like so:

#

but neither of these breakpoints are never hit when I press w or 8 (and num lock is on ofc), and I've verified that the SetCallbacks gets called and correctly attaches the callbacks (with my debugger)

#

at this point I'm sort of suspecting that I'm missing something in the input action object, but I don't see anything that I'm missing in the inspector (there really aren't that many options in the first place)

#

does anybody know what I might be missing?

austere grotto
#

Is this script even running? Is the subscription in Start running?

leaden pivot
#

yes, otherwise the breakpoint would not get hit in setcallbacks

austere grotto
#

Is that method part of the interface?

leaden pivot
#

yes, that is the format for the auto-generated interface

#

SetCallbacks is what calls AddCallbacks, where the actions are actually registered with your custom class that implements the interface defined by your action

#

like this

leaden pivot
#

I came back after a break and it's because I didn't call Enable on the InputAction object 😭

remote jackal
#

always call Enable on the InputAction object!

leaden pivot
#

evidently oooooooooooooooooooooooooooohhh

#

at least that answers how I could handle having a different input object between UI and gameplay

remote jackal
leaden pivot
#

ah I see, I haven't looked into those too much but I noticed it in the UI

remote jackal
#

I guess that's the kinda more OG input system way where input is detected inside functions..

leaden pivot
#

I noticed the examples were using the scheme to differentiate hardware

#

like gamepad vs keyboard

remote jackal
#

funny, I've never noticed these 😆 But that's great

#

I was talking about this thing here

leaden pivot
#

ohhh I see

#

what is stopping Player from still listening when you want to switch to UI?

remote jackal
#

some bool, pretty sure 😛

#

hopefully a List<bool>

leaden pivot
#

I was sort of thinking of having 2 different action maps and disable the one that isn't currently being used

#

and yeah if there were more than two I'd use a loop

remote jackal
#

ah, thought u were considering 2 different input systems

leaden pivot
#

my terminology is probably a bit rough at this point

#

it's all sort of a blur

thick verge
#

how do i read the input of the right stick of the controller? and should i use the new system over the old one?

austere grotto
thick verge
#

guess ill look up the differences between the 2 systems first

austere grotto
#

If you're brand new to Unity you should probably just stick with the old system

steady walrus
#

has anyone actually noticed any slow down from using both input systems on android?

quaint flax
#

This is going to be a super vague question because I haven't been able to debug effectively, but does anyone know some potential causes for a mouse immediately jump to the bottom left of the screen on play? I am using a Virtual mouse for my gamepad controls and it's the only thing I can think of as a potential cause. because the code is setup to disable or enable the physical or virtual mouse depending on what input is currently active. The mouse is anchored to the center of the screen so it's not a matter of the gameobject being off center or improperly anchored

acoustic meadow
#

I'm using the Input System package, I've found the select button isn't detected on MacOS using an Xbox one gamepad

quartz ledge
#

is this the correct way to check if a key is being held?
i feel like its not as its 1000x easier in the old input system

austere grotto
#

There are multiple correct ways

timid dagger
# quartz ledge is this the correct way to check if a key is being held? i feel like its not as ...

The main advantage of the new Input System is its flexibility (which is especially handy if you want to support multiple different controllers, add some layout, custom binding, input postprocessing, accessibility settings, custom inputs (such as 3D ones) etc.).
If you want to check if it's pressed, then something like if (yourAction.phase == InputActionPhase.Performed) should work. Alternatively, you can use .ReadValue.
I recommend serializing InputActionReference instead of finding Action every time.

quartz ledge
timid dagger
quartz ledge
timid dagger
# quartz ledge alright so i should just replace the `.perfomed` and `.canceled` with `ReadValue...

.performed and .canceled are used when you want a method to listen to your input and be always called whenever the condition is met. It's especially good when you want to avoid checking it every frame. .phase is used mostly when inside of some method you need to check if the input is pressed (e.g. when you want to create multiselection with the [Shift] button). .ReadValue is similar to .phase, but is used mostly for analogue values (e.g. if a gamepad stick has a deadzone 0.25f, then it will be performed as long the absolute value is greater than 0.25f, but you might still want to know how big the value is).

ReadValue casts the input value to any format you want. I think it could work with a bool, but it's used mostly for floats and Vector2s.

quartz ledge
analog zenith
#

I'm struggling to get MultiplayerEventSystem to work with UI. It just won't send UI input events. I'm not using PlayerInputManager, I'm handling things like gamepad assignment on my own. But even with just one player joined, I can't interact with the UI at all

#

nvm it just suddenly started working, I did nothing

cloud notch
#

exits a way to call perfomed action everyframe is pressed?

#

without using update or FixedUpdate

timid dagger
cloud notch
timid dagger
# cloud notch i do it but its only called the first time is pressed not continuous

Just tested it out, turns out I'm mistaken. Looks like the difference between .start and .performed lies in input's configuration and .performed might be delayed by interactions (e.g. hold interaction).

When I look at the documentation, I don't see any callback that is being called for the whole duration. 🤔 I suppose you could create a coroutine or something similar during the .start and remove it after receiving the .canceled call.

cloud notch
turbid olive
turbid olive
sage lake
#

for some reason when I do
m_PlayerInput.Player.Move.performed += i => m_Input = i.ReadValue<Vector2>();
the value doesn't change to 0 when I let go of my buttons. Any way I can fix that?

#

like obviously it isn't performed when I don't press anything, but idk how to fix it

#

or what else to use

austere grotto
#

I think you're probably better off just reading this in Update instead of using events though

#

It will be much simpler

#

E.g. in Update just do:

m_Input = m_PlayerInput.Player.Move.ReadValue<Vector2>();

sage lake
#

oh cool, if that works that is also fine

#

I'd still like to know for when I want to shoot my projectile later

austere grotto
#

Event based input handling is an option in the new system, it's not a requirement

sage lake
#

but I guess performed would work better there

sage lake
light pawn
#

potentially very wacky question, does anyone know if there is a way to like lock out a button from being triggered for a certain time after its triggered

#

I have an issue where my pause menu has this armor to turn the pages on the menu but the button being pressed on my controller is triggering it multiple times

austere grotto
#

Set it to interactive= false

fervent tulip
#

Hi,i am working in VR using XR interaction toolkit i have made the script to move using sensors for normal object...but where should i attach the script in (XR Orgin) so my inputs woks same as controllers???

velvet flower
#

hello is it normal for screentoworld point of mouse position to detect mouse in scene

vague ocean
#

Looking for some advice on an asset store package I am developing:

My demo scene uses the input system but its not a strict dependency for the asset to work. I use it to make my demo scene camera controller mobile/touch friendly and handle long-presses easily

The issue is, when someone first imports the asset into a blank project, and installs the input system, then the demo scene appears to not work until the editor is restarted. What can I do about this? I don't want to give new users a frustrating first-experience

austere grotto
#

Instead of forcing your user to install one, especially for a demo

vague ocean
#

understood, I was just hoping there was a way to make the first install a little more seamless for my demo scene

Reimplementing these features in the old system will be a pain but its probably the best thing to do for users

austere grotto
#

Forcing the install itself is already a bad user experience, IMO

blissful lodge
#

Use two mice to drag objects at the same time --- whats the best way to approach this?

Its for an art installation and not meant to be distributed.
Im on a mac, and I may use a mac or windows machine for presentation.
For reference: using unityeditor 2021.3 atm and a script ("drag object") for single mouse config. But of course I am open to any other setup that works.

I googled around quite a bit and most info I find is quite old and also says its hard to do. Is this implemented to be done natively in Unity now?

austere grotto
#

actually i take that back - multiple cursors will definitely not happen out of the box

blissful lodge
#

cool, thanks a lot, Ill read up on this. Just a random thought before I go: could it be possible to have Unity/the OS think that the mice are hand controllers of some sort (like VR hand controllers etc), or 2 analog sticks of a game pad? And then give these inputs one cursor each. Even a hardware hack will do for me in this specific situation.

prime salmon
#

Hey, I think I might be having an input system issue if anyone can help

#
{
    [SerializeField] private InputActionAsset PlayerControls;
    public InputAction interactAction;
    public InputAction moveAction;
    public InputAction jumpAction;
    public InputAction sprintAction;
    public InputAction lookAction;
    public InputAction lockedinAction;

    private void Awake()
    {
        PlayerControls = this.GetComponent<PlayerInput>().actions;
        interactAction = PlayerControls.FindActionMap("Movement").FindAction("Interact");
        moveAction = PlayerControls.FindActionMap("Movement").FindAction("Move");
        jumpAction = PlayerControls.FindActionMap("Movement").FindAction("Jump");
        sprintAction = PlayerControls.FindActionMap("Movement").FindAction("Sprint");
        lookAction = PlayerControls.FindActionMap("Movement").FindAction("Look");
        lockedinAction = PlayerControls.FindActionMap("Movement").FindAction("LockedIn");
    }
    private void OnEnable()
    {
        interactAction.Enable();
        moveAction.Enable();
        jumpAction.Enable();
        sprintAction.Enable();
        lookAction.Enable();
        lockedinAction.Enable();
    }
    private void OnDisable()
    {
        interactAction.Disable();
        moveAction.Disable();
        jumpAction.Disable();
        sprintAction.Disable();
        lookAction.Disable();
        lockedinAction.Disable();
    }
}
#
{
    public CharacterController cc;
    public float speed, sprintSpeed, crouchSpeed, SlidingSpeed, OG_SlideSpeed, mouseSens;
    public float gravity = -9.81f;
    public float jumpHeight;

    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    public bool isGrounded;

    public GameObject player;
    private InputManager inputManager;

    Vector2 moveInput;
    Vector3 currentMovement;

    private void Awake()
    {
        this.transform.position = new Vector3(95.6f, 3f, 109f);
        this.inputManager = GetComponent<InputManager>();

        OG_SlideSpeed = SlidingSpeed;

        this.inputManager.moveAction.performed += context => moveInput = context.ReadValue<Vector2>();
        this.inputManager.moveAction.canceled += context => moveInput = Vector2.zero;
    }

    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
        BaseMovement();
    }
   

    void BaseMovement()
    {
        float speedMultiplier = this.inputManager.sprintAction.ReadValue<float>() > 0 ? sprintSpeed : speed;

        float verticalSpeed = this.moveInput.y * speed * speedMultiplier;
        float horizontalSpeed = this.moveInput.x * speed * speedMultiplier;

        Vector3 horizontalMovemenet = new Vector3(horizontalSpeed, 0, verticalSpeed);
        horizontalMovemenet = this.transform.rotation * horizontalMovemenet;

        JumpAndGravity();

        this.currentMovement.x = horizontalMovemenet.x;
        this.currentMovement.z = horizontalMovemenet.z;

        cc.Move(this.currentMovement * Time.deltaTime);
    }

    void JumpAndGravity()
    {
        if(cc.isGrounded)
        {
            if(this.inputManager.jumpAction.triggered)
            {
                this.currentMovement.y = jumpHeight;
            }
        }
        else
        {
            this.currentMovement.y -= gravity * Time.deltaTime;```
#

I've all 3 scripts because I believe its having to coorelate with all of them, my issue is i cannot find where.

#

Player 1 is pulling the camera from player 2 but is still able to move without being able to look around, while player 2 is showing the correct camera and can look around but cannot move.

austere grotto
#

What do you mean by "Player 1 is pulling the camera from player 2"?

prime salmon
#

in the video I sent, the player one (the left side of the screen), whenever player 2, uses player 2's camera, but whenever i check it out in the hierarcy it says its still using the correct camera

austere grotto
#

Also:

    [SerializeField] private Quaternion lastCameraRotation; // To store camera rotation when lock-on is active

transform.Rotate(lastCameraRotation.x, lastCameraRotation.y, lastCameraRotation.z);```
#

This is NOT how quaternions work

#

at all

#

Oh i didn't notice there was a video

prime salmon
#

You're good

prime salmon
austere grotto
#

It's also odd that one of the player objects seems to be in the scene to start with, and another one is a clone

prime salmon
#

I have one in the beginning to just have. its in the scene, where as the other one is not

#

The other one is created by pressing a button or a key on another keyboard

austere grotto
#

That could be part of the issue though - since the playerinputmanager isn't creating the first one

prime salmon
#

It's cloning the player prefab game object

austere grotto
prime salmon
prime salmon
prime salmon
austere grotto
#

so the PlayerInputManager can properly group devices to players.

prime salmon
#

Just fixed the control schemes

#

Now just having the camera and movement issue

#

When its just single player, player one cannot move either, just look around

austere grotto
#

I would do some standard debugging techniques

#

add logs in your code and make sure the input is being read properly

#

and go from there

prime salmon
#

Already have been, thats how I narrowed it down to the input system issue

#

Im back to doing that again to see if I can try to figure out the issue

#

I appreciate the help though

prime salmon
#

Sadly I have not figured it out yet, if anyone would be willing to try helping that'd be great!

#

Did a debug for the moveInput and its not being recorded, did a debug to make sure the moveAction was correctly assigned and it stated it was

#

New video:

chrome walrus
# prime salmon

I am wondering, how you are moving the camera. Like the input is coming from one mouse, right?

#

Like, you have your inputactions and somehow the lookaction is triggered, but where do you separate the input for player 1 and 2?

arctic estuary
#

when i'm editing the input actions and save them, a script gets created with the same name. due to this my project instantly gives tons of errors due to 'the bindings already existing' however none of the new inputs work, the old ones are fine, but i added a new arrow keys movement and it doesn't use that.

for my main input at the moment im using a midi input device with the MINIS plugin from keijiro and the drywetmidi asset from the asset store.

does anybody know what causes this and how i can solve it?

chrome walrus
#

I guess you did, because Unity will then create a new cs script with the same name and therefore you going to have two versions of the same input action class giving you this error I assume

arctic estuary
#

i'll have to check that out, i keep deleting the script, but if it already exists then i need to find it. one sec

arctic estuary
#

testing rn

arctic estuary
#

flawless

prime salmon
#

Also, just woke up sorry about the late response

prime salmon
chrome walrus
prime salmon
#

Already fixed it.

#

It was a executing issue

chrome walrus
#

ah, good to know

prime salmon
#

The input manager's awake functiom was being called after the player movment and the player look causing the player look and mkvment to not hold any value for any of thr inputs connected to the input manager

still garnet
#

I need some help with animators. I have a character set it up like this for a multiplayer game. The mesh is inside the astronaut002. And i put the animator inside the astronaut002, and the rig inside of it. The animation playes correctly, but the character goes up whenever i press play, did i do something worng ?

#

And just the mesh goes up, everything else stays on the correct place

austere grotto
still garnet
#

But how can i change that, if i set up the animator in the astronaut.test, where the character controler is, it works perfectly

austere grotto
#

Well the main way would be to fix the animations to not be in the air.
But otherwise you can move the child objects around so that the place the animator puts the model is on the ground

#

i.e. by adding another object between the animator and the model that is offset downwards

still garnet
#

I downloaded the animation through mixamo, gonna download another one and see if it changes something

#

I created another empty object and set the offset downards and it works now, thanks man

open imp
#

How do i make a player tap a button rather than hold it down or at least add a delay to the action? I have a fire event to use an item, but right now the player presses the button and it uses all 3 at once, making it useless

#

This is the code i have right now

#

which is invoked on the method that needs the input

austere grotto
open imp
#

Is there a tool to do that with the input sytem

austere grotto
#

no

open imp
#

Ah

austere grotto
#

the input system can't disambiguate this for you

#

not currently at least

#

You could proably write a custom interaction to do this - but it's not built in.

open imp
#

What do the interactions do?

#

I tried using the tap one which you think would work but it does nothing

austere grotto
#

they customize how and when the started/canceled/performed events happen

#

well it will work to detect taps

#

it won't work to exclude other things from happening as well

open imp
#

Oh i see

#

How do i exclude the other things from happenign then?

#

I'd rather use that than write a state machine if i could

austere grotto
#

Writing the state machine is the way to exclude things.

You can obviously write it in a less formal way, but it's going to amount to a state machine

open imp
#

Think i've bodged a solution

austere grotto
#

Don't be intimidated. "State machine" in this context just means Update and a bunch of bools and if statements.

open imp
open imp