#🖱️┃input-system

1 messages · Page 12 of 1

austere grotto
#

and what happens?

#

Does it print?

glad mirage
#

im compiling it rn

#

running

#

debug does send

austere grotto
#

ok

#

keep going

#

add more logs and see where it stops

#

e.g. add one inside the raycast if statement next

glad mirage
#

yeah i just did that

#

compiling and running

austere grotto
#

Also make sure you're not getting any errors in console. (maybe you have errors hidden for example?)

glad mirage
austere grotto
#

ok now you know where to look next - figure out what's going wrong with the raycast.

glad mirage
#

OK, so what I did was made the raycast thing its own void, and get this
it responds there, but not with the input thing...

austere grotto
#

Inspect / debug all the parameters

glad mirage
#

same code, put the void in the update but now it responds, when I remove the void and make it so that it runs off of the input event, it doesnt respond

glad mirage
austere grotto
#

also it could be running on a different object

#

with different data

glad mirage
austere grotto
#

dofferent instance of the script is possible

#

I can't see your project so I don't really know what's going on overall

#

but same script doesn't guarantee anything

#

you need to do more debugging

austere grotto
glad mirage
verbal stratus
#

how would I set up the new input system to detect both mouse clicks and touch screen presses to make a nav mesh agent be able to traverse the navmesh by pressing a target location?

#

if I use Mouse.current.position will it also work on touchscreens?

austere grotto
slender vapor
supple crow
#

you really need to explain what is wrong

#

"it doesn't work" is borderline meaningless

slender vapor
# supple crow you really need to explain **what** is wrong

it was mainly for PraetorBlue when they got back, since they were helping me earlier, but i realized now i put anyone again sorry, but the menu is still not showing up and the jump is super finicky cause it does not work after the first few play tests and then completely stops working even though i redid the scene

stiff turret
#

Hi guys, does anyone have a good source of information on how I can send an output report to my custom HID device? I've searched online but it's all partially explained solutions and the docs only has a paragraph that doesn't say much

stable sinew
tame oracle
#

Do i understand correctly that "Use Physical Keys"in the old input system just means: I give it whatever key i want it to be on my current keyboard and unity will know if someone has a different layout and change the keys accordingly?

umbral hemlock
#

does anyone know how to transfer this code to the new input system

private void MyInput()
{
if (allowButtonHold)
{
shooting = Input.GetButton("Fire1");
}
else
{
shooting = Input.GetButtonDown("Fire1");
}

    if (Input.GetButtonDown("Fire2"))
    {
        aiming = true;
    }
    else
    {
        aiming = false;
    }

    if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !reloading)
    {
        Reload();
    }

    //shoot
    if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
    {
        bulletsShot = bulletsPerTap;
        gunShot.Play();
        Shoot();
    }
    else if (shooting && !reloading && bulletsLeft <= 0)
    {
        gunEmpty.Play();
    }
}
nova quartz
#

hey i need help with my input system

#

i have it so my input controles look like this

#

one object will take Rotaion , fire , and Acellerate

#

and the other will take Rotation 1 fire 1 acelerate one

#

it works when there is one player object

#

but when there are 2 player objects

#

only one of them works

#

i can send the project files if needed

zinc nest
#
    private void Awake()
    {
        playerInputAction = new PlayerInputAction();
    }
    private void OnEnable()
    {
        playerInputAction.Enable();
        playerInputAction.UI.Cancel.performed += OnCancelPerformed;
    }

    private void OnDisable()
    {
        playerInputAction.Disable();
        playerInputAction.UI.Cancel.performed -= OnCancelPerformed;
    }

    private void OnCancelPerformed(InputAction.CallbackContext ctx)
    {
        Debug.Log(gameObject.name + "is cancelling");
    }

Hi, Ive currently got this code. It works, except if I hold the cancel button, it will call this event every frame. Even if I only listen to playerInputAction.UI.Cancel.started it will call the method EVERY frame. Is there a way to stop this? I just want to receive the event once when the button is pushed

#

Wait I realised something

#

The cancel event will basically enable/disable other gameobjects for UI functionality, and it seems that if an object is enabled, it will also receive the event

half pebble
#

Why is my button not registering a click despite following this tutorial to the letter?

https://pastebin.com/UYb5n1uu

Tutorial:
https://www.youtube.com/watch?v=IqpgJlhtmoo

(Video with my settings)

In this video I have shown how you can create a Type Writing effect in Unity using TextMesh Pro. TextMesh pro is the ultimate solution for texts in Unity. You can make different kinds of animation using TMPro's classes. I have shown one example here.

TextMesh Pro Documentation : https://docs.unity3d.com/Packages/com.unity.textmeshpro@1.3/api/...

▶ Play video
rough cave
#

so i have an issue with my code (below) where context.started is running twice and causing context.started to not be registered as an input

            inputs["AimingButtonDown"] = context.started; Debug.Log("AimingButtonDown: " + inputs["AimingButtonDown"]);
            inputs["AimingButtonUp"] = context.canceled;
}```
#

anyone know the solution to this problem

supple crow
#

what do you mean "context.started is running twice"?

#

context.started is a bool...

austere grotto
indigo zodiac
#

should I use unity events or C# events?

nova quartz
#

Unity

#

@indigo zodiac

indigo zodiac
nova quartz
#

ok so

#

I personaly use unity events because i think they are easier and i can make my own events using c# scripts with callback functions

#

it also utlilses unitys input system well

indigo zodiac
#

alr thanks i'll check it out

lost void
#

Hello, using the new input system, how could I manually change my device during runtime?

supple crow
#

Similar to Invoke Unity Events, except that the events are plain C# events available on the PlayerInput API. You cannot configure these from the Inspector. Instead, you have to register callbacks for the events in your scripts.

The following events are available:

onActionTriggered (collective event for all actions on the player)
onDeviceLost
onDeviceRegained

long escarp
#

hey

#

is it possible to create a 'Zoom Toggle' option that has two inputs:
The left shoulder gamepad button for zoom in (start zooming in when action is performed, end zooming in when action is canceled)

#

the right shoulder gamepad button for the same but with zooming out

#

or do I need two actions 'Zoom in toggle' and 'Zoom out toggle'

#

I tried using a 1d axis and then binding the positive axis to the left shoulder and the negative to the right shoulder

#

that works fine for triggering (i can read -1 or 1 and know if the ZoomToggle was triggered by zooming in or out)

#

but on action cancel the values from both the left and right shoulder read 0, so i can no longer distinguish between the two

#

even with normalization they still return 0 on cancel

supple crow
#

if you want to use a 1D axis, then you'll need to remember which way it was being held

#

If you need to perform special actions when releasing the shoulder buttons, then I'd say they should be separate actions.

#

i.e. if letting go of 'zoom in' feels different from letting go of 'zoom out'

high yew
#

hello. i am creating a go kart game. I started out with just controlling gokart and got this problem. I want to brake rear wheels using S key. I dont know if i am doing it right. ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GoKartController : MonoBehaviour
{
public float speed = 10f;
public float turnSpeed = 10f;
public float brakingPower = 500f; // braking power for the rear wheels

public WheelCollider frontLeftWheel;
public WheelCollider frontRightWheel;
public WheelCollider rearLeftWheel;
public WheelCollider rearRightWheel;
public float maxSteeringAngle = 30f;

public Transform centerOfMass;

public Transform frontLeftWheelModel;
public Transform frontRightWheelModel;
public Transform rearLeftWheelModel;
public Transform rearRightWheelModel;

// Start is called before the first frame update
void Start()
{
    Rigidbody rb = GetComponent<Rigidbody>();
    rb.centerOfMass = centerOfMass.localPosition;
}

// Update is called once per frame
void Update()
{
    float vertical = Input.GetAxisRaw("Vertical");
    float horizontal = Input.GetAxis("Horizontal");

    float motorTorque = vertical * speed;
    float steeringAngle = horizontal * maxSteeringAngle;

    frontLeftWheel.steerAngle = steeringAngle;
    frontRightWheel.steerAngle = steeringAngle;

    rearLeftWheel.motorTorque = motorTorque;
    rearRightWheel.motorTorque = motorTorque;

    // apply brake torque to the rear wheels when the S key is pressed
    float brakeTorque = -Input.GetAxisRaw("Vertical") * brakingPower;
    rearLeftWheel.brakeTorque = brakeTorque;
    rearRightWheel.brakeTorque = brakeTorque;
}

}

supple crow
#

!code

sonic sageBOT
#
Posting code

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

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

supple crow
#

please use a paste site for large blocks of code

high yew
supple crow
#

it sounds reasonable, although you should probably check that the resulting torque is greater than zero

#

otherwise, you'll get negative braking power when holding W

high yew
#

when i press W brake torque is negative value resulting that the gokart is not moving. But pressing S brakepower is positive value resulting in braking

#

i would like to know how to make the gokart actually move forward

supple crow
#

i'd just clamp the brake torque

#

torque = Mathf.Max(0, torque);

#

something like that

high yew
#

where in code? // apply brake torque to the rear wheels when the S key is pressed float brakeTorque = -Input.GetAxisRaw("Vertical") * brakingPower; rearLeftWheel.brakeTorque = brakeTorque; rearRightWheel.brakeTorque = brakeTorque;

supple crow
#

after you calculate the torque...

#

and before you use it

high yew
#

thank you, it works

#

but now how do i go backwards?

supple crow
#

I guess you should only apply brakes if the car is moving forward

#

so, set torque to zero if the car's velocity isn't positive

#

and then, equivalently, holding W should apply brakes if you're going backwards

frail sedge
#

hi all
I'm successfully spawning player prefabs into my game scene after a character select screen (local multiplayer) but currently when the prefabs are spawned, every character is being controller by every controller, i.e. controls aren't linked to the correct contrroller. I'm using the new input system. Do i need to make multiple Input System's for each player, oir is there quick wasy to do this in code?

austere grotto
frail sedge
#

My character select screens works with Player Input Manager and Player Input. The characters are selected correctly with multiple controllers and the character choice is saved to PlayerPrefs. The game scene is then loaded and the prefabs and spawned, but then the prefabs are not necessarily being controlled by the correct player

I.e., player1 choose prefabA, but when game scene loads, player1 is controlling prefabB and player2 is controlling prefabA

bleak hound
#

Hi there, I need a basic tip about the new input system.

I'm using the SendMessage behaviour but since it only fires when a button is pressed I cannot detect when that button is released to eventually turn that control's bool to false. Is there a way to fix this problem that is not creating using an opposite control event that is made only on Release?

#

This is the current workaround I found

#

Hope there is a better alternative

austere grotto
#
public void MyCallback(InputAction.CallbackContext ctx) {
  if (ctx.started) {

  }
  else if (ctx.performed) {

  }
  else if (ctx.canceled) {

  }
}```
bleak hound
austere grotto
#

unity events do the same thing

#

just assign the callbacks to the input manager instance on the same prefab

bleak hound
#

ok I'll try, maybe I mistaken it with the invoke c# events behaviour

austere grotto
#

all three of them will allow you to do what you want

#

most people misunderstand what the C# events mode actually does though

#

I would just ignore that one.

bleak hound
# austere grotto if you use Unity Events instead of SendMessage then you can check the CallbackCo...

I've tried switching to Events, so far I've almost replicated everything but on vector2 inputs I get an issue on turning the value off after the button is pressed, here's the code:

    {
        if (ctx.started)
        {
            Vector2 direction = ctx.ReadValue<Vector2>();

            arrow_left = direction.x < -0.1f ? true : false;
            arrow_right = direction.x > 0.1f ? true : false;
            arrow_down = direction.y < -0.1f ? true : false;
            arrow_up = direction.y > 0.1f ? true : false;
        }
        else if (ctx.performed)
        {
            //
        }
        else if (ctx.canceled)
        {
            arrow_left = false;
            arrow_right = false;
            arrow_down = false;
            arrow_up = false;
        }
    }```
#

In this case I have a vertical menu and when I press on the bottom arrow it goes straight to the bottom one

misty mist
#

hey can someone help me with my input system? I just started to get it to work but now im getting an error

#

Here is my current code `using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

public class PlayerMovement : MonoBehaviour
{
private PlayerControls controls;
private Vector2 moveVector = Vector2.zero;
private Rigidbody2D rb = null;
public float moveSpeed = 10f;
private Animator animator;

public int maxHealth = 100;
public int currentHealth;

public HealthBar healthBar;

void Start()
{
    currentHealth = maxHealth;
    healthBar.SetMaxHealth(maxHealth);
}

public void TakeDamage(int damage)
{
    currentHealth -= damage;

    healthBar.SetHealth(currentHealth);
}

private void Awake()
{
    controls = new PlayerControls();
    rb = GetComponent<Rigidbody2D>();
    animator = GetComponent<Animator>();
}

private void OnEnable()
{
    controls.Enable();
    controls.Player.Movement.performed += OnMovementPerformed;
    controls.Player.Movement.canceled += OnMovementCancelled;
}

private void OnDisable()
{
    controls.Disable();
    controls.Player.Movement.performed -= OnMovementPerformed;
    controls.Player.Movement.canceled -= OnMovementCancelled;
}

private void FixedUpdate()
{
    rb.velocity = moveVector * moveSpeed;
}

private void UpdateAnimator()
{
    animator.SetFloat("Horizontal", moveVector.x);
    animator.SetFloat("Vertical", moveVector.y);
    animator.SetFloat("Speed", moveVector.sqrMagnitude);
}

private void OnMovementPerformed(InputAction.CallbackContext value)
{
    moveVector = value.ReadValue<Vector2>();
    UpdateAnimator();
}

private void OnMovementCancelled(InputAction.CallbackContext value)
{
    moveVector = Vector2.zero;
    UpdateAnimator();
}

}
`

#

I dont think its my code tho, I think I setup something wrong

tame oracle
#

I'm not fully certain, but i did find someone with the same issue and error message on stackoverflow for whom the issue was in the compiling order of unity. Perhaps this can help you: https://stackoverflow.com/questions/57680427/c-sharp-cant-find-a-unity-auto-generated-class

The bottom answer is the solution the OP found for the issue.

misty mist
#

now I can go back to fixing the original error I was having

#

jeez

tame oracle
#

haha i mean that happens and it always makes me feel dumb xD but at the end of the day i'd rather have my problem be a one click fix than a full blow refactor lol

misty mist
#

I was honestly thinking about just starting from scratch

#

now I cant figure this one out

#

why is it saying mouse position I dont even have that in my code

tame oracle
#

@misty mist

misty mist
#

Oh I wasnt on both I was on new input system

#

Bruh I kept messing with it and now I have like 20 more errors im just gonna call it a day

#

I tried to add in the mouse pointer position to fix it from saying I was using the old inout system but I couldnt get it to work

tame oracle
#

Ive never tried combining the two. so far i tend to preffer the old system (probably inexperience) so I cant say i know exactly what youre going through rn lol. But google is awesome

unkempt goblet
#

I have two InputActions that are binded to the same button. First is simple press action, second needs to be held for 2 seconds. I need both actions to be active at the same time, but press action is always performed before hold action. How can i solve that, so player can hold button without calling press action?

tame oracle
#

you probably want to check if it is pressed, save that in like a variable. then when the key is nolonger being pressed you can check if it previously was and then do the desired actions.

#

so for example

if (keybeingpressed) {
     presstimer += Time.deltaTime;
}
else if (presstimer > 0.0f)
{
   presstimer = 0;
   //  run your key actions
}
austere grotto
#

You have to upgrade the input module on it

misty mist
#

you guys are freaking beast

tame oracle
#

tbh i just google everything

#

why go to oxford when google stole their textbooks

misty mist
#

omg Im getting a new type of error, cant add script

#

ima google this one, bc its not code related

misty mist
#

I couldnt figure it out, i just bypassed it by adding a new script and copying and pasting

#

also its doing the thing again wtf

tame oracle
#

what error did adding the script give? I had that happen when the script file name and the class name were not the same (Typo)

bleak hound
#

How can I detect if a controller input gets unplugged? I tried this but its not working

bleak hound
austere grotto
#

Subscribe to it like any other event in C#

bleak hound
#

so I guess I should use OnEnable and OnDisable

#

nvm thats another thing

bleak hound
#

mhhh...any help?

supple crow
#

OnEnable and OnDisable are exactly where you'd subscribe to and unsubscribe from an e vent

#

or is the problem that onPlayerLeft is not appropriate?

bleak hound
#

So either something is wrong here or I need to find an alternative to get the PlayerInput that disconnected

mint abyss
#

I'm trying to make an interaction that continuously fires performed on the 2nd tap.

I've been trying to modify a copy of the existing MultiTapInteraction, but I keep crashing unity when I hold the 2nd tap. It's also not firing performed repeatedly, only once

Could anyone point me in the right direction?

austere grotto
mint abyss
#

Repeatedly for as long as it is held down

austere grotto
#

you mean... once per second?
Once per frame?

#

Once per year?

mint abyss
#

each fixed update would be fine

#

each frame would also work

austere grotto
#

If you want to do things once per second you can use Update or a coroutine
If you want to do things once per fixedupdate you can use FixedUpdate or a coroutine

#
Coroutine c;

IEnumerator MyCoroutine() {
  while (true) {
    DoSomething();
    yield return new WaitForFixedUpdate();
  }
}

public void OnMyAction(InputAction.CallbackContext ctx) {
  if (ctx.performed) {
    c = StartCoroutine(MyCoroutine());
  }
  else if(ctx.canceled) {
    StopCoroutine(c);
  }
}```
Quick example with a coroutine^
mint abyss
#

I have that part handled, it's getting the interaction to fire performed in the first place correctly that I'm struggling with

austere grotto
#

You said you had it firing the performed event

#

but you wanted to make it repeat

#

If you're having trouble making it perform in the first place that's a separate issue

mint abyss
#

https://github.com/Unity-Technologies/InputSystem/blob/develop/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/MultiTapInteraction.cs

I can use the existing multitap with minor tweaks to fire a performed on the 2nd tap without an issue, that's how it already works. But the interaction won't keep firing performed if I hold it.

In Process() I flipped how the context phases are being handled in the switch so that its doing PerformedAndStayPerformed while held. The issue is it won't re-fire performed

From what you said it sounds like I need to add an OnUpdate and handle firing performed inside there.

austere grotto
mint abyss
#

I am currently implementing my own custom interaciton

#

Sorry if I hadn't made that cleaerer

austere grotto
#

Yeah but there's a whole timer situation in there that you'd have to change too

mint abyss
#

I have

austere grotto
#

I guess there's a bug in your implementation

austere grotto
mint abyss
#

Ok, thanks

#

Do you happen to know how to have the action not continue with the next interaction assigned to it?

Right now once I release it will suddenly fire the two press interaction events that were held up.

misty mist
#

This is my action map

#

This is my empty game object

errant plaza
#

The pixel perfect camera component makes my screen one solid color when testing it, but without it my tilesets become very jittery. Any ideas how to fix?

errant plaza
#

and I wasn't using that extension but I probably should

full rose
#

guys how to make hot key?

#

nvm found out

lean topaz
#

how do I make an object obey WASD and mouse delta inputs?

#

the 3D core example is incredibly cryptic, i can't understand what's it doing

austere grotto
#

Depends how you want it to react to those inputs

#

But basically - make an input action with both of those bindings and use it

cosmic crane
#

Is there a way to check whether my Player Input has any binding overrides?

#

I have a function to save any binding overrides but I want to check to make sure that it has any before actually loading it in the first place

austere grotto
#

Check if the file exists, no?

cosmic crane
#

i am setting the string to null on a "New Game", however when my player loads the scene again (after a new game has already been created once) it loads in the keybinds from a different save file.

#
        public void SaveData(ref GameData data)
        {
                data.keyBinds = playerInput.actions.SaveBindingOverridesAsJson();
        }

        public void LoadData(GameData data)
        {
                if(string.IsNullOrEmpty(data.keyBinds)) { return;}

                playerInput.actions.LoadBindingOverridesFromJson(data.keyBinds);
        }
austere grotto
#

so it looks like you already have a solution to what you asked

heavy sphinx
#

sorry just placed in the wrong place

grave rivet
#

How can I properly check if a player is scrolling using the new input system?

verbal remnant
grave rivet
oblique idol
#

I'm in the process of refactoring my code to use the new input system, however I'm a bit confused about something: in each script that uses the input actions asset, do I create a new instance like this?

private GameControls _controls;
private void Awake()
{
    _controls = new();
}

Or should there only be one instance of GameControls that all scripts should share?

#

I'm asking this because I have a truck in my game and you can switch to a laptop with a different set of input actions. The truck controls all work fine, but in the laptop script none of the callbacks/actions seem to be triggered

#

So I'm wondering if I should be sharing the GameControls instance?

austere grotto
austere grotto
oblique idol
#

Inside the truck script, I can enable the laptop controls and disable the truck controls and toggle the laptop screen on, however performing the same action again, the laptop script doesn’t seem to call the toggle laptop action

austere grotto
#

you'd have to show your code

oblique idol
#

I’m on mobile let me get to my laptop one sec

#
public class CarInputs : MonoBehaviour
{
    public static GameControls _controls;
    
    private void Awake()
    {
        _controls = new();
    }

    private void OnEnable()
    {
        _controls.Vehicle.Handbrake.started += ApplyHandbrake;
        _controls.Vehicle.Handbrake.canceled += ReleaseHandbrake;
        _controls.Vehicle.Laptop.performed += OpenLaptop;
        _controls.Vehicle.Enable();
    }
    
    private void OnDisable()
    {
        _controls.Vehicle.Handbrake.started -= ApplyHandbrake;
        _controls.Vehicle.Handbrake.canceled -= ReleaseHandbrake;
        _controls.Vehicle.Disable();
    }

    private void OpenLaptop(InputAction.CallbackContext obj)
    {
        _controls.Vehicle.Disable();
        _controls.Laptop.Enable();
        TTXMissionUtil.Instance.ToggleLaptop(obj);
    }    
}
#
public class TTXMissionUtil : MonoBehaviour
{
    public static TTXMissionUtil Instance;
    
    private void Awake()
    {
        Instance = this;
    }

    private void OnEnable()
    {
        CarInputs._controls.Laptop.ToggleLaptop.performed += ToggleLaptop;
        CarInputs._controls.Laptop.NextScreen.performed += PageRight;
    }

    private void OnDisable()
    {
        CarInputs._controls.Laptop.ToggleLaptop.performed -= ToggleLaptop;
        CarInputs._controls.Laptop.NextScreen.performed -= PageRight;
    }
    
    public void ToggleLaptop(InputAction.CallbackContext obj)
    {
        Debug.Log("ToggleLaptop called");

        if (_state == TTXState.DISABLED)
        {
            // Configure other scripts
            // ...
        }
        else if (_state != TTXState.DISABLED)
        {
            CarInputs._controls.Laptop.Disable();
            CarInputs._controls.Vehicle.Enable();
            
            // Reset other scripts
            ...
        }
    }
}
#

Those are stripped-down versions of the code

#

I thought that's what the second-last line in OpenLaptop() does?

austere grotto
#

Uh - sure it is - is that ever running though?

Another potential problem:

    private void OnEnable()
    {
        CarInputs._controls.Laptop.ToggleLaptop.performed += ToggleLaptop;
        CarInputs._controls.Laptop.NextScreen.performed += PageRight;
    }```
You have no guarantee that's going to run before this:
```cs
    private void Awake()
    {
        _controls = new();
    }```
#

(and if it doesn't you should be seeing a NullReferenceException in your console)

oblique idol
#

Ah yes I'm getting a NullReferenceException on CarInputs._controls.Laptop.ToggleLaptop.performed += ToggleLaptop;

austere grotto
#

yep - you have a script execution order issue

oblique idol
#

Is there a best practice for ensuring scripts execute in a certain order, or ensuring one script is Awake before accessing fields from it?

#

Even if I create my own instance of _controls it still isn't executed

austere grotto
oblique idol
#

No more NullReferenceException, but nothing happens when I press toggle

#

Do I need to call SetCallbacks()?

austere grotto
#

no

oblique idol
#

I'm not sure what's going wrong now, here is my new code:

#
public class CarInputs : MonoBehaviour
{
    public static GameControls _controls;
    
    private void Awake()
    {
        _controls = new();
    }

    private void OnEnable()
    {
        _controls.Vehicle.Handbrake.started += ApplyHandbrake;
        _controls.Vehicle.Handbrake.canceled += ReleaseHandbrake;
        _controls.Vehicle.Enable();
    }
    
    private void OnDisable()
    {
        _controls.Vehicle.Handbrake.started -= ApplyHandbrake;
        _controls.Vehicle.Handbrake.canceled -= ReleaseHandbrake;
        _controls.Vehicle.Disable();
    }    
}
#
public class TTXMissionUtil : MonoBehaviour
{
    public static TTXMissionUtil Instance;
    public static GameControls _controls;
    
    private void Awake()
    {
        Instance = this;
        _controls = new();
    }

    private void OnEnable()
    {
        CarInputs._controls.Laptop.ToggleLaptop.performed += ToggleLaptop;
        CarInputs._controls.Laptop.NextScreen.performed += PageRight;
        _controls.Vehicle.Laptop.performed += ToggleLaptop;
    }

    private void OnDisable()
    {
        CarInputs._controls.Laptop.ToggleLaptop.performed -= ToggleLaptop;
        CarInputs._controls.Laptop.NextScreen.performed -= PageRight;
        _controls.Vehicle.Laptop.performed -= ToggleLaptop;
    }
    
    public void ToggleLaptop(InputAction.CallbackContext obj)
    {
        Debug.Log("ToggleLaptop called");

        if (_state == TTXState.DISABLED)
        {
            // Configure other scripts
            // ...
        }
        else if (_state != TTXState.DISABLED)
        {
            CarInputs._controls.Laptop.Disable();
            CarInputs._controls.Vehicle.Enable();
            
            // Reset other scripts
            ...
        }
    }
}
austere grotto
oblique idol
#

Whoops I'm not doing that, sorry I copy and pasted my sections of code wrong

austere grotto
#

and anything you do to CarInputs (e.g. enable/disable action maps) won['t affect your instance

oblique idol
#

Dumb question here… if a game object is already enabled, is OnEnable called when the game first loads?

austere grotto
#

yes

#

It's called when the object is created and initialized, which happens when the scene loads

oblique idol
#

Hmm in that case I don’t understand why the subscribed events aren’t being called

austere grotto
#

you'd have to show the current code

oblique idol
#
 private void Awake()
    {
        Instance = this;
        _controls = new();
    }

    private void OnEnable()
    {
        
        _controls.Laptop.ToggleLaptop.performed += ToggleLaptop;
        _controls.Laptop.NextScreen.performed += PageRight;
        _controls.Vehicle.Laptop.performed += ToggleLaptop;

    }

 public void ToggleLaptop(InputAction.CallbackContext obj)
    {
        Debug.Log("ToggleLaptop called");
        ...
     }
austere grotto
oblique idol
#

Oh, I haven't enabled laptop controls 🤦‍♂️

#

Sorry I'm being stupid

#

Okay it all makes sense now, my mental model of how it works is updated, I think I’ll create an input handler so I don’t have to juggle multiple instances

winged chasm
#

any1 got a script for a playerobject (with cameral already attached) that i can use to run / jump and steer the carackter but like the fov changes when sprinting?

#

how is that possible

austere grotto
#

Work on them one at a time

#

!code

sonic sageBOT
#
Posting code

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

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

winged chasm
#

oh thanks

#

!code

sonic sageBOT
#
Posting code

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

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

cobalt tree
#

Can someone help me💀

#

I don’t know how to solve it, I just want to make my character controller work

austere grotto
#

You have to update the code to use the new one or switch the project back

cobalt tree
#

how can I update the code for using it

polar cosmos
#

nvm im stupid

nova quartz
steady fable
#

asking here because maybe input system people know better
Hi, I have a TMP_InputField and I am trying to listen to changes on it ```cs
_searchBar.InputField.onValueChanged.AddListener(delegate { listener(); });

and it gets called whenever I type characters except when I delete the last one.  Why wouldn't it be sending `onValueChanged` when it goes to blank?  It does have a placeholder text.
lean topaz
#

If I have two input functions that rely on the same key, can I make a customizable input system that involves changing the same key that serves those functions?

lean topaz
#

for instance, Player Action "Fire" will shoot when tapping Mouse Key 1, while it also will charge a weapon when Hold in Player Action "Charge Attack"

lost void
#

Hello! With the new input system, is there a way to make sure the device the current player is using stays the same even when a scene switches?

compact acorn
#

with the new input system, is there a way to check when a key is released?

austere grotto
#

Of course

#

Several ways, depending on how you're handling input currently

compact acorn
#

do i just have a variable set that checks if it was pressed and then the if its not = to that value then i know its been released? Thats what i have been doing but it seems like a really roundabout way to do it

austere grotto
#

not typically, no

#

again it depends what you're trying to do exactly and it depends how you're currently handling input

#

If you're using a PlayerInput component in SendMessages mode - that's kinda what you're stuck with, which is why I wouldn't recommend using a PlayerInput in SendMessages mode.

compact acorn
#

im trying to do this if (playerInputActions.Player.SwitchItems.WasReleasedThisFrame) but was relesesed this frame is a method so that doesnt work

austere grotto
#

if (playerInputActions.Player.SwitchItems.WasReleasedThisFrame())

compact acorn
#

oh yeah right

#

im so stupid

#

sorry to trouble you

#

for some reason i thought u couldnt call methods in if statments

#

thanks for the help

austere grotto
compact acorn
#

oh yeah right

#

mb

#

thanks for the help though

lost void
#

Hello, how would I be able to MANUALLY SAVE the input device to give it to another PLAYER INPUT component?

finite shale
#

Hi, how I can remove this input events? I try "inputActionSprint.performed -= ctx => isSprint = true;", but this doesn't work

spiral galleon
#

you can't remove an anonymous function because it's anonymous. But if you bind a function instead you can remove that function instance.
action.performed += Myfunc
action.performed -= Myfunc

finite shale
#

Thanks 😉

verbal remnant
supple crow
#

is there a specific way to reference an input action map?

#

I can just do this:

#
InputActionReference whatever;

// ...

whatever.action.map.Enable();
#

it's probably fine

#

i don't expect to have any action maps with 0 actions in them

red snow
austere grotto
#

Those are two different instances of the input asset

#

sounds like you're only rebinding the PlayerInput's copy

red snow
#

oh i see

austere grotto
#

in your code you're using the C# generated class

#

which will be a totally different input action asset instance

#

unrelated to the PlayerInput component

red snow
#

thank you that makes sense. i should be able to figure it out

high osprey
#

Does the input system read the left mouse button differently than the right mouse button? I have 2 bools I set for the right mouse button for WasPressedThisFrame and IsPressed, and 1 bool for the left mouse button for WasPressedThisFrame. The right one works fine, but the left one is telling me I can't use a bool for it because its a float?

austere grotto
high osprey
supple crow
#

i'm having a minor crisis: when the heck should i be reading input?

I'm having problems with a juddery-looking camera right now. I'm using the Kinematic Character Controller for movement, which acts on FixedUpdate and then interpolates in each LateUpdate.

My "driver" component reads user input in Update and uses that to update the player's desired velocity and rotation. The character controller then uses these in FixedUpdate to tell the KCC motor what to do.

Perhaps I should be handling user input in FixedUpdate instead? The game definitely looks better when I do that -- if the frame rate is below 50, I get some really nasty jerks when handling it in Update, presumably because Update doesn't run at all in between those two fixed updates

#

Even when the framerate isn't suffering -- let's say it's a rock-solid 60 -- this still seems weird

#

Update runs 1.16 times for every FixedUpdate, so sometimes you get two Updates before FixedUpdate runs

#

which means you get twice as much movement

#

I thought I had a good handle on all of this, but now that I'm looking at it more closely, all of my assumptions seem bogus

#

I guess it's only an issue now that I'm doing movement in FixedUpdate; with the vanilla Character Controller, I would always do movement in Update

#

i'm having a midlife crisis over a joystick

supple crow
#

Which makes sense. The camera needs to rotate every frame.

#

it feels great now

tawdry wasp
#

I haev this in my Action map to move my camera with where my mouse goes but nothing happens, i'm sure i'm missing a step but unsure what it is i'm doing wrong

supple crow
#

well, just having an action doesn't do anything

#

how are you using the LookMovement action?

tawdry wasp
#

I guess in that case i'm not, I set it up once before and I think i've forgot a step along the way

supple crow
#

You can use the PlayerInput component to call methods on your components, or you can directly read values from the actions using an InputActionReference

#

PlayerInput makes things pretty easy

tawdry wasp
#

So in the project I set up with it I know I forgot something, but i'm certain there was no coding involved with mouse look

#

so maybe I was using InputActionReference?

supple crow
#

you might have been using Cinemachine

#

the Cinemachine POV aim component can directly read input

tawdry wasp
#

I was using cinemachine now you mention it

#

yes that was it thankyou

#

it still doesn't work but I think I might be able to sort it out with that info

supple crow
#

once you have a POV camera, it should have a little info box saying that there's no input provider attached

tawdry wasp
#

ah got it

mint root
#

I have an input action map that won't read any inputs from mouse or keyboard. The buttons always return false. But my inputs work fine in the Input Debugger. And I do have calls to the input class, and I have called activate on the control map im using.

#

each input always returns false

austere grotto
heavy cipher
#

recommended way to set a flag to ignore all inputs until the input is pressed again (value input)

#

for example

  • hold h (input is now 1)
  • set flag (still holding h) (input is now 0)
  • release h (still 0)
  • press h again (now 1)
#

maybe have a bool and ignore the input if true? then how would i detect a rising edge (started pressing) to turn the bool off

#

say a Vector2 value input

#

in a

public void OnInput(InputValue inputValue)
{
    print(inputValue.Get<Vector2>())
}
#

or maybe i should have a field tracking the last time OnInput was triggered?

#

also any way to use the Send Messages behaviour with a InputAction.CallbackContext argument? or do i have to use Invoke Unity Events

full rose
#

guys how do i get rid of input override the others?

#

i have 2 this

lean topaz
#

In the input system what's the difference between Button With Two Modifiers and Two Modifiers?

lean topaz
#

Also what does Override Modifier Need do?

tawdry wasp
#

When I enter my ship (change cinemachine camera and use my interact button) I get a new error of:

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

does anyone have experience with this error? I've never seen it before and even google was not so helpful
full cradle
#

Hi. Is there a way to make a "virtual" device? So my problem is that I want to have full control when some action is fired, for example some action is fired when the mouse clicked, but I want to make some more logic to this. I can't modify the source code of the the action it self, so I need to work around this, and that is my idea but I dont know how to do it.

tame oracle
#

maybe it's me but I don't quite understand what you are trying to do.

#

You want there to happen multiple things when someone clicks a button?

gleaming socket
#

my mouse position is not accurate, im using the new input system and the pixel perfect extension on the cinemachine vcam, anyone know how to fix it?

tame oracle
#

if it works it work 😋

full rose
lean topaz
#

I'm not sure if I understand (since I didn't play tarkov)

full rose
#

if you have 2 scope
and that button will switch between 2 scope view

#

also i keep change aim state when hit right click tho

full rose
# lean topaz I'm not sure if I understand (since I didn't play tarkov)

In This Video You Will Learn How to Switch Sights in Escape from Tarkov ‏‏‎ ‎

GET AMAZING FREE Tools For Your Youtube Channel To Get More Views:
Tubebuddy (For GROWTH on Youtube):
https://www.tubebuddy.com/MARCUSYOUTUBE

Copy.ai (Amazing tool for descriptions and Youtube titles):
https://www.copy.ai?via=marek

Snappa Graphic Program For Thumbn...

▶ Play video
full rose
lean topaz
#

I still don't get it
I was asking what's the difference between "Button with Two Modifiers" and "Two Modifiers" in Unity

full rose
#

ah

#

idk too

full rose
lean topaz
#

So does Two Modifiers

full rose
#

1 binding?

lean topaz
#

This is why I am confused since I didn't see a difference between them

lean topaz
full rose
#

oh

#

saw it

tough compass
#

trying to figure out how to make a sprinting script

#

holding down a button should make the character faster

tough compass
#

managed get it working but on the character is now always running after when i pressed once

tough compass
#

when i pressed the button

glad kiln
#
    void Update()
    {
        if(Input.GetButtonDown(SprintButton))
            Speed = SprintSpeed;
        else if(Input.GetButtonUp(SprintButton))
            Speed = DefaultSpeed;
    }
bright cypress
#

alright guys whats going on with this

#

I dragged my player script in, but its missing these... parantheses?

#

so bizarre

#

now i cant access the method corresponding to the input

full rose
#

i dont know how to avoid 2 inputs at the same time

#

i found this but dont know how to do it

#

i need help

#

please

oblique marten
#

Does anyone happen to know why my right stick isn't rotating my orbital cinemachine camera? it's using Vector2 in the New Input System same as my mouse and that works fine with the Cinemachine Input Provider component, but the stick doesn't for some reason, even though i've referenced the appropriate action map in the component (not sure if this is Input issue or Cinemachine issue so will post in both)

austere grotto
graceful hemlock
#

I've created a WebGL build using the Starter Assets Third Person Controller. For some reason the mouse input to rotate the camera ends when the mouse pointer hits the border of the screen. In desktop builds, this seems infinite. How can I change that in WebGL?

prisma quarry
#

Good evening. I'm absolutely lost with the new Unity InputSystem. (I'm using version 1.5.0)
I'm performing interactive rebinding, and manually apply a binding override just after it. The override seems to be registered, but the controls doesn't change. (Initial is "Q", but even after changing the binding to "M", it keeps opening with "Q", and "M" does nothing)
It's been a couple of days since I started searching the reason of this problem, so any help would be greatly appreciated!

Here are a few lines of code, but I don't think this could help.

PerformInteractiveRebind(action, bindingIndex, allCompositeParts);
action.ApplyBindingOverride(bindingIndex, operation.selectedControl.path);

Thanks! 🙏🏽

prisma quarry
#

(please mention me along with your response)

graceful hemlock
full rose
#

anyone know how to do this?

#

i think my shortcut support is turned off

manic dirge
#

How can I find if an InputDevice is a gamepad?

Gamepad GetGamepad()
{
   foreach (InputDevice device in plrInput.devices)
   {
      if (device /*is a gamepad*/)
      {
         return /* the gamepad */
      }
   }

   return null;
}```
tame oracle
#

InputSystem.FindControls("<Gamepad>"); may help

austere grotto
lime ibex
#

What is leftshift's name in input manager?
'leftshift' doesnt work

full rose
manic dirge
fossil drift
#

Hi guys! 🙂 I want to do a WASD composite that allows me to get the last button pressed, exactly as it is done here: https://forum.unity.com/threads/using-last-key-pressed-in-a-composite-2d-vector.1109609/ the problem is that, with my custom Composite I get the right value but my action callbacks don't get called, so my code never gets notified of the new values...any clue?

simple tendon
#

I'm trying to switch action maps, and while I disable and enable them correctly, the newly enabled action map doesn't seem to be working. i.e the actions are not sent to the class that implements it's interface.

austere grotto
simple tendon
austere grotto
#

and possibly the least important part.

#

show the full script

simple tendon
#

it's the part I know is working

austere grotto
#

_controls < where this is defined, assigned, listened to and managed is what we need to know

#

show the full script and, if you are using the PlayerInput component, the inspector of that as well

simple tendon
#
{
    public InputMaster _controls;
...
 public void OnEnable()
    {
        if (_controls == null)
        {
            _controls = new InputMaster();
            _controls.Player.SetCallbacks(this);
        }

        _controls.Player.Enable();
        _currentScene = SceneManager.GetActiveScene();
    }```
austere grotto
simple tendon
#

it's not using the PlayerInput, someone else set it up initially, now I'm trying to fix it

#

public class PlayerUiManager : MonoBehaviour, InputMaster.IUIActions

austere grotto
#

that's not setting the callbacks, that's just a class definition for a class which imple,ents the interface

#

See this?
_controls.Player.SetCallbacks(this);

#

this actually tells the input system to use your class as the listener for the input events

simple tendon
#

ah

#

that was what I was missing

#

thanks

austere grotto
#

you would need to do _controls.UI.SetCallbacks(somePlayerUiManagerInstance);

simple tendon
#

so next question, Should I name my map something other then UI cause I don't want to override all the default Ui actions, but if I remove them from the action map then my EventSystem looks like this:

#

And while that doesn't seem to be effecting how the game functions, it feels... wrong? lol

austere grotto
#

it looks like you've changed it to use your custom one

#

the name(s) of the action maps don't matter at all really

#

but you do need to assign your custom actions to the input module if you want it to work

simple tendon
#

so it's fine to leave it on the default if I don't want to override those?

austere grotto
#

sure except if you want to be able to enable/disable that map you will need to reference it properly. The UI map from your generated C# class is not the same

simple tendon
#

I mean basically, the guy who set it up bound the left mouse click to basic attack, to avoid the player attacking while clicking in the inventory we put this in:

    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            //Debug.Log("pointer over game object");
            return;
        }```

but that results in it being a frame behind which generates a warning and even worse causes visual lags. 

All I'm trying to do by switching to a new action map is get rid of that `IsPointerOverGameObject()` check.
austere grotto
#

e.g. use IPointerClickHandler on the map or a big invisible UI element behind everything else to run this code

fossil drift
silk perch
#

Guys, I am having this error and can't find a solution anywhere. Just found some people with the same problem but never answered. This error has no solution?

Could not find active control after binding resolution UnityEngine.InputSystem.OnScreen.OnScreenControl:OnEnable

austere grotto
fossil drift
fossil drift
austere grotto
#

As far as I understand - you will get a performed callback any time the magnitude changes to a new greater-than-0 value

#

since the magnitude is going to stay at 1 with this implementation, you don't get a performed callback

#

that being said I think it's kind of counterproductive / overcomplicated to use event-based handling for continuous "joystick" style input anyway

#

just poll the value in Update.

#

What's simpler?

void Update() {
  Vector2 moveInput = myMovementAction.ReadValue<Vector2>();
  transform.Translate(moveInput * Time.deltaTime * speed);
}

or:

Vector2 moveInput;
void Update() {
  transform.Translate(moveInput * Time.deltaTime * speed);
}

void OnMove(InputAction.CallbackContext ctx) {
  moveInput = ctx.ReadValue<Vector2>();
}```
#

btw:

It is just the method I sent in the original question hooked up to the unity event of the input action
You didn't send a method, just a link to the "original" implementation

fossil drift
red linden
#

I am using a touch screen on a Windows PC and using the Input.touches - however the fingerId does not change. Only between multiple touches (finger 1 always has fingerId 0, finger 2 id 1 etc). I am expecting the fingerId to change, and increment and be unique for each new touch. I am using LTS 2021.3 - Bug or Feature?

tame oracle
tame oracle
#

Well I guess I "fixed it"/worked around by when opening the inventory the drop/dropsingle actions are set to disabled and then when picking up an item it disables picking up actions and enables dropping actions 😄

austere grotto
#

E.g.
IPointerClickHandler
IDragHandler
IPointerDownHandler, etc....

grizzled helm
# austere grotto E.g. IPointerClickHandler IDragHandler IPointerDownHandler, etc....

Hello....speaking of which, I'm trying to switch over from my (outdated) use of OnMouseDown to the IPointerClickHandler. So I previously I had a GameManager with an OnMouseDown() method that instantiated a house where I clicked the mouse (on a grass background). Now I'm trying to use IPointerClickHandler so it will work for touchscreens too. But it seems in order for OnPointerClick to work, the script needs to be moved onto the grass object (or wherever I'm clicking), and can't be on a GameManager object anymore, correct?

#

Is there a way to keep IPointerClickHandler on the Game Manager object script?

potent ridge
#

i type touch into the new input binding search, theres so many things that all look the same, is there like a chart or something for bindings?

sly oak
#

Hello,

I have been working with unity's new input system since few days and have managed to wrap my head around it. It is easy add controls for gamepad and keyboard but Im confused about touch controls. The OnScreenButton and OnScreenJoystick are useful stuff but are feasible only when your touch control count/types matches the count of physical device. i.e. two joystick and 16 buttons. My on-screen layout is similar to type mobile MOBA game where atk buttons are hybrid of button and sticks.

I'm also tracking the device from which last input was sent so I can update UI accordingly via InputSystem.onActionChange. OnScreenControls, as they emulate the input of the path they are assigned, shows the set device instead of reporting it as touchScreen control. I.e Gamepad if OnScreenControl points to gamepad and keyboard if it points to keyboard.

So I decided to make a custom input device which maps the controls according to my need.
which takes input from a custom made 'Joystick' which is placed on UI Canvas. This allows me to have any number of joysticks and also easily lets me identify as only touch controls are mapped to this device and everything works great.I have attached code if anyone have any suggestions there I would love to know.

Questions:

  1. Is this the right way ? Is there any other way to handle custom layouts ?
  2. The custom joystick listens via IPointerDownHandler,IPointerDragHandler and IPointerUpHandler. and the ThreeAxisJoystick access them via singleton 'GameplayView' and reads their value in 'OnUpdate' and Queues the state. This feels hacky since in sample the 'keyboard' low level api class. There is also a TouchScreenClass but Im unable to make sense out of it so if there is any way I can use that it would be great.
  3. If in entirety any other better solution or premade solution is present which covers all usecases Im happy to hear.

Thanks and Regards.

austere grotto
#

IPointerDownHandler (not ClickHandler) is the equivalent, and is a bit more flexible

#

it has to be on the object being clicked. You can put it on an invisible background ui object or on an invisible plane object. You can also make a custom raycaster and use Plane.Raycast to have a completely GameObject-free experience.

grizzled helm
river sapphire
#

If with pressed key (wasd for example) switch focus from unity to other element in browser(webgl), then the key will be pressed if it is physically released by user. How to fi this or is there any workarounds for this problem ?

lean topaz
#

there are USB controllers that uses the Playstation layout and some that uses the XBOX layout right?
how does the Input System differentiate that?

austere grotto
lean topaz
#

so if I mapped my Input Controls with an XBOX patterned controller (where the left joy is on top of the D-pad) for say directional movement, if somebody used a PS patterned controller (D-pad over left joy) Unity will automatically guess the D-Pad input as the left joy and perform directional movements?

#

or the player will still need to use the left joy on PS controller?

sly oak
lean topaz
#

ah

#

so i don't have to do anything specific then

#

thanks

supple crow
#

I'm using the new input system. I'm not getting D-pad input in the UI on my Steam Deck. My EventSystem is using the default input action asset.

#

maybe I should try explicitly adding a d-pad action for my gameplay action asset and seeing if that shows up...

austere grotto
supple crow
#

Difficult part: this is strictly on my steam deck

austere grotto
#

ahhh I see

supple crow
#

I did check that d-pad input is working in game

#

tl;dr unity is not respecting my navigation settings

#

i don't think i'm getting errored out while setting up that navigation (these menus are procedurally generated)

#

i checked that it also happens with keyboard input

#

i wonder if there is any relation

#

oh you know what

#

man this is weird

#

when using the d-pad, I think the selection is somehow moving to a menu that shouldn't even be active

#

i start with the "Scene Select" menu button highlighted; if I hit down on the d-pad seven times (corresponding to six scenes), my selection moves down by one

#

but only when using the d-pad, and only on my steam deck

#

🫠

#

the top-level menu uses automatic navigation

#

maybe i'll try connecting my xbox controller to the steam deck...

#

oh my god

#

so with the xbox controller, the d-pad navigates as expected

#

but it still navigates wrongly as described in that link above

#

I guess that's reasonable, actually, since THAT issue happens with the joystick too

#

Steam must be doing something funny with the d-pad input.

supple crow
#

god this is weird

austere grotto
supple crow
#

i'm wondering if it's trying to be clever

#

the input config says it's just a "Standard D-pad"

#

the input visualizer does show normal-looking behavior there

austere grotto
#

weird

supple crow
#

maybe I'll try rebuilding the D-pad out of a 2D composite instead of just being a d-pad

#

that'd be so bloody weird if that did anything

#

it IS the only one that's not a 2D composite.....

#

Same problem.

#

gonna see if it behaves the same with the Windows build under Proton

#

I did make sure that it's not just moving the mouse cursor around

#

Works fine!

supple crow
#

well

#

in the meantime

#

i think i'm just going to say "don't use the d-pad"

simple tendon
#

I feel like I've missed something, when you set up a binding in the Inputmaster and then go to where the interface is, all it passes in is the InputAction.CallbackContext, but say that it the binding was for Shift + LeftClick, how am I supposed to know what GameObject was actually clicked on?

burnt oasis
#

I have 2 players in the scene both with PlayerInput component attached to them and a separate InputActionAsset

I want each player to be able to use a side of the same keyboard or a keyboard with a controller
the controller is fine, but the keyboard, only one player is receiving an input, the other is not

how to make both players receive input from the same keyboard?

wet osprey
#

Hello. To display the binding of the button, I use _bindingText.text = _inputAction.GetBindingDisplayString(); If I have a non-English keyboard layout, then my text displays in a different language. How to display text always in English?

austere grotto
wet osprey
echo relic
topaz sapphire
#

I'm having trouble. I have Pause set as an action, and I have it set up the exact same way as the Interact action, in my code, but for some reason, it never fires the PauseButtonPressed function, but it still fires the InteractButtonPressed function. Can anyone here help?

https://pastebin.com/WJiLQjKK

topaz sapphire
#

Nevermind, I figured it out. Adding the callback in code didn't work, and Unity wouldn't let me assign a callback in the Input Action Asset, and eventually, I discovered (rediscovered) that the Player Input component has its OWN dropdown menu for adding Callbacks to input actions...

burnt oasis
spice pecan
#

Hi, when I rebind controls with rebindOperation.WithCancelingThrough("<Keyboard>/escape");, when assigning to an action that expects a keyboard input, the input gets suppressed (pressing escape only cancels the rebind, but doesn't drop you out of the control remap screen). However, when I assign to an action that expects a gamepad input, "escape" doesn't get suppressed, it cancels the rebind operation, but it also lets escape through, dropping you out of the control remap screen. Thoughts?

spice pecan
#

solved by disabling all of the enabled actions when the rebind operation is running

austere grotto
grave lion
#

Hey uh, that's probably a really common question, but I didn't find much that corresponded to my problem when browsing here, so here I am
How do you manage whether an event is targeting a UI element, or the game itself ?
In my case, I use left click to select a tile on a map. I've got buttons at the top of the screen, and clicking on them doesn't prevent the event from propagating to the rest of the scene. So my click will select the tile that's behind the button

austere grotto
#

If you're doing your own manual raycasting, all bets are off

topaz sapphire
lean topaz
#

What happens if I hook a Hotas to the PC and use input system?

#

Do I need specific setups for it?

grave lion
# austere grotto If you use the event system for everything, UI elements will block clicks on stu...

Well it doesn't, and I'm not raycasting anything thonk
I use Unity events, and my own input action map. Whenever a user event occurs, it gets routed to a class that then dispatchs the event, and that's about it
Is the UI also supposed to block unity events from being triggered ? Currently it doesn't, and I don't know if I misconfigured something, or if I'm supposed to check by myself if the event should be propagated to the scene, and not only the UI u_u

grave lion
#

Changing the behaviour to Send message doesn't seem to have any effect :v

#

And apparently, using isPointerOverGameObject() isn't a good idea in this case :

grave lion
#

Welp, it works

reef gazelle
#

Hey, can someone tell me how I check if the pressed key was a .GetKeyDOWN event? I dont want it to register "held" buttons
private void OnGUI() { //Get what button was pressed and save it Event e = Event.current; if (!e.isKey) return; KeyCode pressedButton = e.keyCode; }

#

found it, its
if(e.type == EventType.KeyDown)

austere grotto
#

When I say the event system I'm talking about things like IPointerClickHandler, IPointerEnterHandler etc

Or the Event Trigger component

#

What you have right now is input handling code which is separate

austere grotto
vagrant knoll
#

Assets\Scripts\GameManager.cs(12,12): error CS0122: 'InputManager' is inaccessible due to its protection level

How to fix this annoying error pls

violet hazel
vagrant knoll
#

ok wait a 1s

#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using EZCameraShake;

public class GameManager : MonoBehaviour
{
    public static GameManager Instance;

    public InputManager inputManager;
    public GameObject playerPrefabB;
    public GameObject playerA;
    public GameObject playerB;
    public Transform spawnPointA;
    public Transform spawnPointB;
    public bool waitingForPlayers = true;

    // ...existing code...

    void Awake()
    {
        if (Instance == null)
            Instance = this;
        else
            Destroy(gameObject);
    }

    void OnPlayerJoined(PlayerInput input)
    {
        if (!inputManager.joiningEnabled)
            return;

        if (playerA == null)
        {
            playerA = input.gameObject;
            inputManager.playerPrefab = playerPrefabB;

            playerA.transform.position = spawnPointA.position;
        }
        else
        {
            playerB = input.gameObject;

            playerB.transform.position = spawnPointB.position;

            inputManager.DisableJoining();
            waitingForPlayers = false;
            waitingForPlayersUI.SetTrigger("Stop");

            AudioManager.instance.Play("Ready");
        }
    }

    // ...existing code...
}
violet hazel
#

UnityEngine.InputSystem.InputManager is internal, not public. Your code is trying to use that. Are you sure it's not supposed to be PlayerInputManager?

vagrant knoll
#

Its player input manager

violet hazel
vagrant knoll
#

Fixed

worn willow
#

how do you get the value of the z key from an action input to play an animation and the value of the s key to play another animation in a code?

austere grotto
spare gorge
#

I'm using a smol bit of code to try to register a callback to an event. Though the value is just being printed as zero and I'm not entirely sure why it doesn't change from zero. I don't think I have the control setup right, but I have it setup as a regular button in the input manager, as they do in the example where I found this bit of context.duration code (the unity docs where they talk about .CallbackContext) but it doesn't seem to work. any thoughts?

        private void OnEnable()
        {
            shootRef.action.canceled += context =>
            {
                shootPower = context.duration * 10.0f;
                Debug.Log(shootPower);
            };
        }
#

I also tried shootRef.action.perfomed but it seems to call when you hit the button, rather then when you release it.

distant crescent
#

Hey! I'm trying to deploy a WebGL game but my PlayerInput module on the title screen isn't receiving input from my controller. Anybody have a problem with this?

distant crescent
#

There are other points in the game where the module is working fine, just not on the title screen when the game first loads.

worn willow
austere grotto
#

You don't

#

It's done in your input actions asset

#

These are the basics of the input system

worn willow
austere grotto
#

It does whatever your code tells it to do

worn willow
austere grotto
#

That's just a binding

#

You need to worry more about the input value

#

Hard to say without seeing your code

#

But usually something like:
if(input.y < 0)

worn willow
# austere grotto But usually something like: `if(input.y < 0)`
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;

public class PlayerController : MonoBehaviour
{
    [SerializeField] private PlayerInput PlayerInput;
    Animator animator;
    private PlayerControlls PlayerInputActions;
    private InputActionMap _currentMap;
    private InputAction _moveAction;
    private InputAction _runAction;

    public Vector2 Move {get; private set;}
    public bool Run {get; private set;}

    private void Awake()
    {
        PlayerInputActions = new PlayerControlls();
        _currentMap = PlayerInput.currentActionMap;
        _moveAction = _currentMap.FindAction("Move");
        _runAction  = _currentMap.FindAction("Run");

        _moveAction.performed += onMove;
        _runAction.performed += onRun;

        _moveAction.canceled += onMoveCanceled;
        _runAction.canceled += onRunCanceled;
    }

    private void OnEnable()
    {
        _currentMap.Enable();
        _moveAction = PlayerInputActions.Player.Move;
    }

    private void OnDisable()
    {
        _currentMap.Disable();
    }

    void Start()
    {
        animator = GetComponent<Animator>();
    }

    private void onMove(InputAction.CallbackContext context)
    {
        Move = context.ReadValue<Vector2>();
        animator.SetBool("isWalking", true);
    }

    private void onMoveCanceled(InputAction.CallbackContext context)
    {
        Move = Vector2.zero;
        animator.SetBool("isWalking", false);
    }

    private void onRun(InputAction.CallbackContext context)
    {
        Run = context.ReadValueAsButton();
        animator.SetBool("isRunning", true);
    }

    private void onRunCanceled(InputAction.CallbackContext context)
    {
        Run = false;
        animator.SetBool("isRunning", false);
    }
}```
austere grotto
#

Yeah just if (Move.y < 0) then you know it's going backwards

worn willow
austere grotto
#

Right and left are the x component

worn willow
#

ok

worn willow
# austere grotto Down is -1

i do that but just the isWalking works

private void onMove(InputAction.CallbackContext context)
    {
        Move = context.ReadValue<Vector2>();
        if(Move.y > 0)
        {
            animator.SetBool("isWalking", true);
        }
        if(Move.y > -1)
        {
            animator.SetBool("isWalkingBack", true);
        }
    }```
austere grotto
#

Read your code

#

It doesn't make sense

austere grotto
worn willow
austere grotto
#

I am not privy to that information since you haven't shared it 🤷‍♂️

snow kraken
#

code:

using BepInEx;
using System;
using Technie.PhysicsCreator;
using UnityEngine;
using UnityEngine.InputSystem;
using Utilla;

namespace GorillaFPV
{
    /// <summary>
    /// This is your mod's main class.
    /// </summary>

    /* This attribute tells Utilla to look for [ModdedGameJoin] and [ModdedGameLeave] */
    [ModdedGamemode]
    [BepInDependency("org.legoandmars.gorillatag.utilla", "1.5.0")]
    [BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
    public class Plugin : BaseUnityPlugin
    {
        Vector3 resetPosition;
        float mouseMovementY;

        GameObject cube;
        void Setup()
        {
            GameObject placeHolderCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            placeHolderCube.transform.localScale = Vector3.one * 0.08f;

            cube = Instantiate(placeHolderCube);
            cube.GetComponent<Collider>().enabled = false;
        }
        void Start() { Utilla.Events.GameInitialized += OnGameInitialized; }

        void OnEnable()
        {
            HarmonyPatches.ApplyHarmonyPatches();
        }

        void OnDisable()
        {
            HarmonyPatches.RemoveHarmonyPatches();
        }

        void OnGameInitialized(object sender, EventArgs e)
        {
            Setup();
            cube.transform.position = GorillaLocomotion.Player.Instance.rightHandFollower.position;
        }

        void FixedUpdate()
        {
            mouseMovementY = Mouse.current.position.ReadValue().y;
            cube.transform.position = Vector3.up * mouseMovementY;
            Debug.Log($"[gorillaRPV] PositionDebug[cube]: {cube.transform.position}");
            Debug.Log($"[gorillaRPV] PositionDebug[mouse]: {mouseMovementY}");
        }
    }
}``` i get 0 and 0, 0, 0 in BepInEx console even when i move my mouse

This is a plugin for a vr game that is on legacy input system
austere grotto
#

You have a mouse position in a VR game? Also mouse position doesn't seem appropriate for something called "mouse movement"

snow kraken
#

I need movement but im just trying to get it to work like this and i can figure it out later

austere grotto
#

Can you explain the mouse position in a VR game thing?

tall sonnet
#

who knows how to add unity to a game and use unity and is willing to help me make a goril tag fan game named crazy apes

austere grotto
#

btw Mouse.current.position.ReadValue().y is the NEW input system

#

if the game is using the legacy input system as you said, it won't work

austere grotto
#

yes...

#

everything in UnityEngine.InputSystem is the new system

snow kraken
#

Well idek but its on the correct system

#

The other one threw errors

#

Can you not get mouse position on a vr game if you move it on desktop view?

limber axle
#

Very simple question. I'm getting frustrated with the input system manager. This thing is so frustrating, it is insane.

#

I don't want any prefab whenever I detect an input for someone new, but can't disable it. Now, I can deal with it. I want to create my own object via a list generated through another pattern, and the only thing I'm interested in is the new input from a new player.

I'm trying to transfert the input from the prefab created to the new one. but everytime I do that, it takes that as a new player joining AGAIN so I end up with an infinite loop. Why would every single input be a new player, that's stupid. is there a way to transfert the input from one to another without triggering OnPlayerJoined every single times?

austere grotto
#

a player is, basically, an active input device in this context.

limber axle
#

it's not but I need this input to be on my other prefab that is generated though another means (basically MVM pattern with my list of player auto-populating these prefab.). I want to pass only the input info in my player list, and then initialize the real PlayerInput on the correct prefab (and begone the auto-generated one I don't want).

I've tried a lot of combination by disabling stuff and activating other ot try and deactivate this hell behavior of checking for any PLayerInput component that appears in the scene.

#

Is there any other method to detect any controller hitting a button or something that isn't using PlayerInputManager?

#

I just want the detection, and then get the info for the device and scheme so I can set it manually. while still using the new input system.

austere grotto
limber axle
# austere grotto > and then initialize the real PlayerInput on the correct prefab You're fighting...

I'll find a way but this system is so inflexible, forcing us into a corner. Even if I leave the auto-generated prefab as it is and just move it wherever, it can't be a parent of the correct prefab, which it needs to in order to get the event broadcast. I'll go the ugly route and set it up like I am forced to I guess.

I wish there was just a simple event to listen to "Whatever" the PIM is listening to to get new input detection and let me do whatever I want with it. Simple and flexible. button input --> event --> DeviceId (or whatever let us get the info --> Create a PlayerInput however you wish to do so.

snow kraken
#

does Gamepad.current.leftStick.ReadValue().y; get vr controller input too? (quest 2 pcvr)

remote root
#

@austere grotto I think it describes how I could use the MoveAmount Vector2 with Move() Input, but I since I'm new I can’t imagine how this should look like^^

austere grotto
#

It could look like... whatever you want

#

Because your game is unique

#

I can't tell you anything about how to use the data because I have no idea what you want to do with it

remote root
#

Okay thanks for your feedback, I will add some more informations to ask a better question!:)

sly oak
snow kraken
#

I just went with vr joystick

slender vapor
grave lion
polar cosmos
#

the code probably fails there and thats why the ui doesnt work aswell

latent shard
#

Hey folks, has anyone noticed any issues with events not being carried through the system properly when using PlayerInput?

I have the following control scheme for a painting-based game:
BrushStroke - bound to Position [Mouse]
StartPainting - bound to <Mouse>/leftButton

Previously I was directly instantiating my GameInputActions class in the Start event and binding handlers with .performed += performedHandler, .started += startedHandler, .canceled += canceledHandler, etc, but I wanted to centralize handling and PlayerInput seems like a mostly good option. However the binding is different, and it seems like some of the events behave differently in PlayerInput than they do when using the InputActionsAsset directly

#

My mouse is moving as I expect, but I'm using a second component to detect specific shapes, and those shapes aren't being recognized when using PlayerInput

latent shard
#

Would be nice if the generated InputActionAsset wrappers could be exposed to the editor, but I spose that's the price we pay for convenience.

worn edge
#

how to check if i touch the screen or i swipe the screen ? I want to call a fonction only if it is a tap on the screen but i don't know how to do that. Help me pls (Mobile app)

split bear
#

I want to have a button input that returns true while held and false when released, but has to be held for a short period to activate (I want a different function to occur when the player simply taps the button). How can I set this up?
I currently have a standard 'press and release' interaction that activates instantly, but when I add a 'hold' interaction it doesn't return false when released from a hold. When I tap it, it does return false when released, but doesn't return true when pressed.
How would I accomplish this?

split bear
#

Okay I figured out how to make the hold also register a release, by changing the action type from 'Button' to 'Value' (and also setting the 'press' interaction to 'Release Only').

#

I wanted to make the quick tap be part of a composite for an axis input, but I tried it as its own action and it works better. Although when I do tap it it makes the first action (the one you hold) return false exactly 3 times

split bear
#

The two actions as they are currently, in case my explanation wasn't clear

grizzled topaz
#

how do I compare input control ?, I'm trying to make hotkey for inventory item and through CallbackContext I see the key being pressed under control

#

or how do I do this actually, tutorials covers setting up keybinds to actions but i dont want to make action for every item slot

weary lintel
#

hoping someone can help. using the new input system, I have made my own input reader script, (so not using PlayerInputs). But I need to check what device/control scheme is being used to trigger an input (a vector2). playerinputs has "currentControlScheme", but I can't figure out what i need to have something similar. For clarity, I have a gamepad joystick and a mousedelta feeding a vector2 action, and i need to run two different types of functions depending on if it's the joystick or the mouse. I have a bool ready to go I just don't know how to read the input to determine which one fed the action

sly oak
# weary lintel hoping someone can help. using the new input system, I have made my own input re...

One way to go would be to fetch the result from actionChange callback,
Its a hacky solution but Ig it qualifies by a bit for a private member for your input reader, and you can simply then feed the result to the bool ?

eg:
void OnEnable()
{
ToggleInputMethodChangeLister(true);
}

    void OnDisable()
    {
        ToggleInputMethodChangeLister(false);
    }
    
     private void ToggleInputMethodChangeLister(bool register) 
    {
        if(register)
            InputSystem.onActionChange += InputSystem_onActionChange;
        else
            InputSystem.onActionChange -= InputSystem_onActionChange;
    }
    
     private void InputSystem_onActionChange(object actionObject, InputActionChange actionStatus)
    {
        InputDevice lastDevice = (actionObject as InputAction)?.activeControl?.device;
        if (lastDevice == null)
            return;

      Debug.Log($"{lastDevice.name}");
        
    }
#

I use this to switch between different UI layouts at runtime, from gamepad to keyboard to touch etc.

lavish bluff
#

How would you do multiplayer UI navigation where you need all players to use the same set of buttons

#

Like a character select screen in a fighting game

#

I know you can have separate UIs for each player with MultiplayerEventSystem, but this is different

weary lintel
# sly oak One way to go would be to fetch the result from actionChange callback, Its a hac...

Thanks heaps for the reply, really clear and provided the example i needed! I ended up with ``` private void InputSystem_onActionChange(object actionObject, InputActionChange actionStatus)
{
InputDevice lastDevice = (actionObject as InputAction)?.activeControl?.device;
if (lastDevice.name == "Keyboard" || lastDevice.name == "Mouse")
{
Debug.Log(true);
isUsingKeyboard = true;
}
else
{
Debug.Log(false);
isUsingKeyboard = false;
}

    if (lastDevice == null)
        return;
  
}```

Which seems to do the trick. Yeah I had no idea about that call from the inputsystem directly, but seems to work, cheers for that!

weary lintel
#

ok so it was working earlier, now it seems to not be lol. i will restart unity and see if that helps.

#

hmm, in the end I had to just add the player input and use the "currentControlScheme" to make it work smoothly. I might revisit later to figure out what is going on

radiant mica
#

Why is it that when i play my game on mobile, a different button gets pressed when i touch the screen than the one i touch on

gaunt vapor
#

My on-screen touch joystick keeps stuttering on Android, but it works fine in the simulator in Unity.

I printed the control scheme and devices, and I noticed that the devices seem to be rapidly switching when using the on-screen joystick.

They switches between "Touchscreen:/Touchscreen, AndroidJoystick:/AndroidJoystick" and "Touchscreen:/Touchscreen1, Joystick:/Joystick".

The scheme remains consistent (Touch).

gaunt vapor
#

And here are the devices in the Input Debugger

hasty shadow
#

Hey, not sure if this is a Input System problem itself but I have this plugin in our project, which is super important and we can't get rid of it. But I need to rewrite the input code in there. However, when I do using UnityEngine.InputSystem, Rider says that it cannot resolve symbol 'InputSystem' and I'm not really sure how to solve this problem

austere grotto
hasty shadow
#

no wait in the plugin, oops

#

okay, got it now. thanks for the help!!!

grizzled topaz
#

do I really need to unsubscribe everytime I switched map ?, if player accessed enabled UIMap and I disable PlayerMap for that moment so the player cant move, re-subscribing seems like a hassle

#

tutorials i saw unsubscribe, so i guess its good practice afterall ?

austere grotto
fallen charm
#

So im trying to make it so you simply tap the button but for some reason even holding triggers it

#
    {
        _jump = context.action.WasPressedThisFrame();
    }```
split coyote
#

does anybody know how when using Primary Touch/Touch Contact? I can avoid detecting touch if using OnScreenStick or OnScreenButton?

tame oracle
#

Hello, i want to ask why touch not working in production but working in development. In development, the touch is registered and out the touch pos, but when in production, i build into aab and upload it in internal test and try download it and play, but the touch not register and there is no output.

neat compass
#

Hey there, I've got my generic movement setup on the left hand side, and on the right hand side I am trying to detect if the user is a Controller or Keyboard & Mouse.
When I start the game if I have them both in the scene, they seem to cancel each other out, what am I doing wrong here?

austere grotto
#

Also the input system has a whole control scheme system you can and should be using

sterile citrus
#

I have the most simple project set up possible: an otherwise empty project, a Canvas with a Button that does nothing, with an EventSystem on a separate GameObject using the new InputSystemUIInputModule. In the editor I can press the button and it's onClick event will be invoked. In a build the button will be pressed down (I can see the transition animation change its color) but it will not go back up when I lift my finger (it stays in the pressed state) and the onClick callback is not triggered.

Is there something obvious I'm missing? This is basically a Hello World project with the new Input System, I'm not sure what I could be doing wrong...

EDIT: If I use the Standalone Input Module, it works. If I use the suggested InputSystemUIInputModule, it is broken. Looks like a Unity bug, not sure how anyone is using this package at all.

austere grotto
sterile citrus
austere grotto
sterile citrus
#

Is there an up to date example project that proves this package even works? Warriors hasn't been updated for 3 years

austere grotto
#

the input system package works fine

#

not really sure what's going on with your situation

#

you sure it's a problabm of the event not being invoked and not something else?

sterile citrus
#

I'll submit a unity bug. Might be the new LTS for all I know. I have gotten it to work in the past

austere grotto
#

If the color transitioning is happen then I'd say the input module is working

#

maybe a touch bug

#

if it's not going back when you lift finger

sterile citrus
#

Yeah the color transition happens, but just the press, not the "up" (so it gets stuck in the pressed state)

austere grotto
#

what hardware are you testing on

sterile citrus
#

Google pixel 7a and my windows desktop

austere grotto
#

Ah I also have the 7a. horrible battery life 😢

remote slate
#

Hi!!!!

#

Guys is there a way to create a combo with the action mappings like street figther? for example:

sterile citrus
remote slate
#

I think the point of the inputs system is to make this kind of behaviours

sterile citrus
remote slate
#

but hap happens in this case that you need a combo, does the input system helps at all?

#

i dont know how to call the actions, combo1_step_1, combo1_step_2 ?

#

or i will need to use the input manager?

#

because the are no conditions to eneable or disable combo1_step_2

#

am I wrong?

#

I guess at the end you have to go back to the input manager

austere grotto
austere grotto
austere grotto
#

as in:

Square (X) – Light Punch
Triangle (Y) – Medium Punch
Cross (A) – Light Kick
Circle (B) – Medium Punch
R1 (RB) – Heavy Punch
R2 (RT) – Heavy Kick
L1 (LB) – Medium Punch + Medium Kick (Drive Parry)
L2 (LT) – Light Punch + Light Kick (Throw)```
remote slate
#

yes i understand the modifiers

#

how would you make a combo? i never worked with state machines, it sounds like something a will like

remote slate
#

is that link using the input system?

austere grotto
#

no

#

it's a conceptual guide

#

it does not directly use unity or C# or anything like that

#

the input system is irrelevant

#

that's just how you read the input

remote slate
#

ok

#

thank you @austere grotto

sterile citrus
#

@austere grotto I appreciate your help earlier. If you're able to take a look, here's a repo I put together that reproduced the issue I'm seeing (the button will work in the editor but not on Android). The intended behavior in this example is that the button just randomizes an image color.
https://github.com/njelly/input-system-hello-world

EDIT: I have submitted a bug to Unity through the editor.

EDIT: I was missing a PlayerInput script (which I guess Enables the actions?)

tropic salmon
#

Hey, I'm trying to make the new input system work on my game, though it looks like Jump() works but OnMove() doesn't, Jump() really worked first try, maybe I forgot something in the keybinds?

#

this is probably a dumb question but I can't seem to find the issue here

austere grotto
#

because this doesn't show us

#

OnMove looks like it's set up for a PlayerInput component in SendMessages mode

#

but Jump looks like it's set up for a PlayerInput in UnityEvents mode OR manually subscribing listeners to actions in code.

#

in other words - these are set up for two different styles of listening to the events

#

and you're doing one or the other. You should know which

fallen charm
#

for keyboard you want a 2d axis

austere grotto
#

That's irrelevant to the question

#

though it's true that Get<Vector2> is going to fail for a 1D axis

fallen charm
#

Yeah notice how the composite type for keyboard is "1d axis"

#

wait nvm i meant 2d vector

tropic salmon
fallen charm
#

theres no function

austere grotto
#

you have no listener functions set up on the left

#

and on the right you're creating a generted C# input object and not hooking any listeners up to it

#

perhaps there is more on the right side that you're not showing us (maybe in Start?)

#

but as is, neither of these will do anything

tropic salmon
#

I'm sooo lost I watched dozens of tutorials and they were all different lol... my brain hurts

austere grotto
#

you should just stick with one way for now to avoid confusion

fallen charm
#

I recommend simply hooking up player input to the functions

austere grotto
#

to do that though they will need to use the InputAction.CallbackContext parameter type

#

not InputValue

fallen charm
#

Be sure you only have on player input component

tropic salmon
#

(I'm trying to process the info)

#

so

#

the reason why my jump() works is because it has the callbackContext in parameter am I right

fallen charm
#

yes

#

probably

#

also click the (no function) button

austere grotto
fallen charm
#

it will give you a list of scripts and then a function to assign it

austere grotto
#

basically you're mixing and matching a bunch of incompatible things right now

#

and you happen to have matched something up correctly somewhere with Jump

tropic salmon
fallen charm
#

because it doesnt have an object

tropic salmon
#

oh what

fallen charm
#

(put the player itself in)

tropic salmon
#

it just unlinked it for some reason

fallen charm
#

(im assuming your movement code is on the player right?)

tropic salmon
#

sorry my pc didn't let me screenshot so PrtScn

#

I think I'm starting to somewhat get it

#

honestly I'm just not too sure what the function tab should be linked to, in fact every single tutorials just went "do that" instead of explaining what does what

fallen charm
tropic salmon
# fallen charm Link the move input to OnMove

if I understand what you just said, you mean selecting the OnMove() to this function tab? I might just be so far from what you're telling me, I've been trying to understand this for so long without success, confused af blushie

fallen charm
#

Yes thats what i meant

#

also yeah i know its confusing even im confused about somethings

#

Such as applying it to a state machine

tropic salmon
fallen charm
#

Did you put InputAction.CallbackContext in the parentheses of the OnMove function?

tropic salmon
#

I did

fallen charm
#

Id remove inputvalue

#

you dont need that

tropic salmon
#

alright alright

#

done

fallen charm
#

now test

tropic salmon
#

it works

#

but how do I get the inputValue if it's not a thing no more?

fallen charm
#

id do this
movementValue = context.ReadValue<Vector2>();

#

put this in the performed parentheses

fallen charm
tropic salmon
#

I see I see

#

My brain is melting holly molly

#

I'm starting to think my unity skills got destroyed after 2 years not touching anything gamedev related

fallen charm
#

you can get rid of the playeractions thing

#

since the component is already conected

#

so if you want to turn off input (like if your talking to an npc or in a cutscene) simply disable the Player Input Component

tropic salmon
#

oh right that's it

#

and about that axis thing

#

even if I only use one axis

#

do I still use vector2

#

and just leave the Y axis as it is

fallen charm
#

just use x

#

IE: movementValue.x

fallen charm
tropic salmon
#

it says cannot convert float to vector2, but that's just me and my goofy understanding of vectors, everything works just fine now

#

thanks a lot man, very wholesome of you to take some time of yours to help

foggy iris
#

Watching this Boundary Break video of Half Life got me thinking. (https://youtu.be/rEXjRokfUpY) How do I achieve teleporting someone to another small area that's technically part of the same level? Anyone got a tutorial?

Lets take the camera absolutely anywhere we want to learn more about Valves Half Life with veteran Half Life actor Mike Shapiro!

Follow Mike Shapiro on twitter! - https://twitter.com/mikeshapiroland

Every episode I have - https://www.youtube.com/playlist?list=PLYfhW_P-MkU7vBmWwwyqdIWNDzXfEZwnO

Keep me company on Twitter! We have fun there: ht...

▶ Play video
fallen charm
#

Also this has nothing to do with the input system

foggy iris
#

@fallen charm where does it belong?

fallen charm
foggy iris
#

@fallen charm thanks.

fallen charm
#

So Im trying to connect my player input component to my states in my state machine

#

however, the state scripts arent shown on the inspecter just the state machine

#

And i think it would be better if the input functions were in certain states

#

For example here is my ground state script

cold dust
#

Hi ppl! Im refactoring the input system on my prototype with Unity's new one. Is there a way to have the Up Down events on the new system? I know it works with events but it would be easier for me to refactor if I got an Up and Down event separatedly. Is that possible or I should find a way to work with a single event?

austere grotto
#

so it's unsure what you're asking for exactly

cold dust
#

new input systems trigger events when input is pressed

austere grotto
#

Are you asking "How do I check if the X key was pressed this frame"?

austere grotto
cold dust
#

old input works with Up And Down

austere grotto
#

It can do many things

cold dust
#

right, Im thinking if it is possible to get 2 events, for up and down with the new input system

#

😊

austere grotto
#

You could use this for a 1:1 replacement for GetKeyDown

DashDown = Keyboard.current[Key.X].wasPressedThisFrame```
austere grotto
#

since you're polling in the old system

cold dust
#

right

#

that is what I mean 😄

austere grotto
#

And for released:

DashDown = Keyboard.current[Key.X].wasReleasedThisFrame```
neat compass
#

Hey there I've got the following InputSystem setup and working fine, is there a way for me to determine if the player is using a Keyboard & Mouse or a Controller? And change the sensitivity dependent on this?
Or do I need to split Move and Look into two seperate actions ie. Move_Keyboard and Move_Controller?

fallen charm
#

Then add something like gamepad

#

So basically its like this

cold dust
austere grotto
#

this bypasses the input action system entirely

#

just like GetKeyDown did

#

(bypassed the old axis system)

cold dust
#

oh ok but isnt that going to work only for keyboard?

#

Im just using the new system to suppor xbox controller

austere grotto
#

if you want it to work for more things, you should use input actions

cold dust
#

right, that is my goal haha

austere grotto
#

if you want minimal code changes you can still poll input actions

cold dust
#

ok, I should refactor to work with the event I guess

#

thanks!

#

sorry for being so slow with this

austere grotto
#

like I was saying, the new system can be used in many ways

fallen charm
#

wait nvm I think i know

#

nvm didnt work

#

btw heres the state machine

fallen charm
#

I cant find anything on how to do this damn thing

spiral galleon
fallen charm
#

Trying to figure out how to connect the input action functions to my state machine

#

So each state is a script stored in the state machine

spiral galleon
#

Do you have a reference to the player state machine in your script?

fallen charm
#

all state scripts mention the player state machine

spiral galleon
#

I see

fallen charm
spiral galleon
#

Do you use the code generated input?

#

or just the asset

fallen charm
#

by asset i assume you mean the player input component?

#

If so then yes

spiral galleon
#

ah right thought it was your own mono behaviour for a sec

fallen charm
#

So I do kind of have a solution but its flawed

#

This is what i did before

#

The problem is that this method isnt good for using started,performed, cancelled etc

spiral galleon
#

How do you want to configure which button does what? Cause there's a couple of solutions you can use

fallen charm
#

sorry im just so confused

spiral galleon
#

The simplest solution is to do something along these lines:

playerInput.actions["Crouch"].performed += CrouchButtonPressed;
///

private void CrouchButtonPressed(InputAction.CallbackContext callbackContext)
{
  // swap state etc
}
#

ideally you would register that in Start() or Awake()

fallen charm
#

im trying it

spiral galleon
#

If you make your State Machine look like this:

public class CoolStateMachine : MonoBehaviour
{
    public void EnterCrouchState(InputAction.CallbackContext ctx)
    {
        if (ctx.performed)
        {
            // clicked
        }
        else if (ctx.canceled)
        {
            // released
        }
    }
}

Then you can use the input like this:

#

Assuming "MousePosition" in my example is your button for going crouch

#

@fallen charm

tame oracle
#

Can anyone explain why my joystick

#

isn't working?

#

My keyboard controls work perfectly

sly oak
austere grotto
tame oracle
austere grotto
#

no

austere grotto
#

Why are you worried about spamming it now.

tame oracle
#

its code from an asset. i'd rather not share it pubicily

#

Man. this discord is so hostile

#

No worries, thanks anyway man.

austere grotto
#

Well you shouldn't share it privately with me either then

tame oracle
#

I promise you man, you can be happy in life. you don't always need to be upset.

crimson schooner
#

Hey I'm having an issue with the input system where mayflash gamecube adapter controllers aren't joining the game when a button is pressed despite inputs being read by the input debugger. I'll attach some relevant screenshots

#

The input debugger is recognizing when changers are happening in the "value" column for certain button presses, but when I press a button in my game the "controller" prefab isn't being spawned, despite not having this issue with other control schemes in my action maps (keyboard/standard gamepad)

#

I was wondering if part of the issue was that I was using specifically the mayflash adapter as my input, but even when I used the joystick trigger option (which for some reason is the X button on a mayflash controller) it won't register either

#

Here's my action map for all control schemes

#

Unity can recognize the inputs when using "listen" but won't add a prefab as well

fallen charm
#

For some reason I when I try to add the action in my state script I get an error thats says "NullReferenceException"

#

its this line btw _p.p_input.actions["Jump"].started += Jump;

#

even though i have this in the state machine its referencing

#

private PlayerInput _p_Input; public PlayerInput p_input { get { return _p_Input; } }

#
PlayerGroundState.EnterState (PlayerStateMachine player) (at Assets/Scripts/Player/PlayerStates/PlayerGroundState.cs:29)```
#

This is the error

#

Also for some reason when this error occurs my statemachine script is turned off

austere grotto
#

Or perhaps _p.p_input

fallen charm
#
public abstract class PlayerBaseState
{
    protected PlayerStateMachine _p;
    public abstract void EnterState(PlayerStateMachine player);

    public abstract void UpdateState(PlayerStateMachine player);

    public abstract void UpdateStateLate(PlayerStateMachine player);
}
#

I forgot to mention that

austere grotto
#

Not an assignment

#

_p = something

#

That's an assignment

#

What you shared is the variable declaration

#

Also wouldn't it be ["Character/Jump"] to find that action?

fallen charm
#

Oh maybe

#
        pInput.actions["Jump"].started += Jump;``` this causes the same error btw
fallen charm
austere grotto
#

It's very simple. I'm shooting in the dark here because I don't have your project in front of me

#

One of your variables is null

#

Your job is to find out what is null

#

And why it's null

#

And fix that

#

I'm just giving you some possibilities

#

But you need to actually check with logs or the debugger

fallen charm
#

ok got it to work but when i try to jump i get an error

#
    {
       _p.velocity.y = Mathf.Sqrt(_p.jumpheight * -2f * _p.gravity);
    }```
#

it says this is causing it

austere grotto
fallen charm
#

the reason i did that was because

    {
       player.velocity.y = Mathf.Sqrt(player.jumpheight * -2f * player.gravity);
    }``` would not work
austere grotto
#

Of course not, that doesn't make sense

fallen charm
#

cause i need something that references the statemachinescript

#

wait i got it to work

#

wait for some reason i can jump in the air? even though i dont have the jump function in the air state script?

neat compass
#

Heya, just going to pop this in here as it it somewhat related to InputSystem, although I don't want to duplicate the same message.

#archived-code-general message

gleaming socket
#

anyone know how i can stop listening for input in the new unity input system?

timber robin
#

Well, you have to .Enable() your input action map, so just call .Disable() on it.

gleaming socket
#

oh ok, thanks

sly oak
crimson schooner
sly oak
#

@crimson schooner
so debugger shows 4 entries regardless of how many are connected ?

slender vapor
slender vapor
slender vapor
#

nevermind i dont need help, i got it now

thick imp
#

I've a problem with the new input system I don't understand. When I press the B button on my controller, with a UI input map active, this happens:

  • the B button triggers the action from the UI input map
  • we unpause the game (timescale, etc) (frame A)
  • we switch input map from UI to Gameplay
  • then, the frame after (A + 1), we receive input events in this order: B down, B up, B down, B up

all that with one button press and release

why would that happen?

edit: I've noticed that this B down, B up, B down, B up always happens whenever we press the button once, that seems a bit suspicious

thick imp
austere grotto
thick imp
lean arrow
#

Hey, complete unity beginner here. I want to make a game that only reads the ordinal and cardinal directions, like a number pad. None of the in-betweens. Is there a way to sort of add those constraints to the Input Manager?

crimson schooner
#

The debugger shows 4 entries regardless, but only one of them will update the value column depending on the number of controllers plugged in

neat compass
#

Any reason autoswitch doesn't work when there are two or more Player Inputs in a scene?
At the moment I have "Movement Controls" which is the player movement
and "Global Controls" which is for controls which should always be active, ie. pause menu, console, etc.
Should I merge everything into one?

sly oak
crisp wasp
#

Hi. I'm new to Unity. I want to use the new Input System 1.6.1, and I'm using Unity Editor 2022.3.1f1 and JetBrains Rider IDE 2023.1.2
I installed the package through the Package Manager and restarted the Unity Editor. The instalation should be correct but then, I start my Rider IDE and get the following 2 errors:

#

I also tried the Input System 1.5.1 and the Unity Editor 2022.3.0f1 and same exact error. I also tried with completelly new empty projects

#

Does someone know why this might be happening?

wheat cipher
#

why is this happening? i cant see the textbox and everything is overlapping

wheat cipher
#

the input system 1.6.1 seems broken for some reason

#

anybody having issues?

coral sphinx
#

hey, i'm was trying to follow this tutorial:
https://www.youtube.com/watch?v=Cd8eTgBM1ew&ab_channel=AwesomeTuts-AnyoneCanLearnToMakeGames
but it cuts at the end for some reason, now i'm stuck with the monkey movement. I'm trying to use the input-system to just constantly get the touch position when pressing the screen, any tips?

crisp wasp
#

Do you have a similar issue?

wheat cipher
#

no mines different, i can install the 1.6.1 but the issue is UI of the Input system overlapping

crimson schooner
#

If I plug the GameCube controller into the first port and press the A button, then in the input debugger only the first registered mayflash input device has its button 2 input changed.

#

Which again, is expected behavior. The problem is the inputs are not being read the new input system

worn edge
#

How can i detect with the input system if i clik on a UI element ? I have a interactable scene but i don't want to interacte with it when i click on a ui button. (I use raycast to interact with my scene)

worn edge
austere grotto
maiden crane
#

Are there any examples of floating joystick designs that utilize the on-screen stick available?

sly oak
maiden crane
sly oak
austere grotto
fallen charm
#

For some reason performed phase wont work properly for my state machine (it works but holding the button down does nothing)

#

started and cancelled work fine, but performed will just behave like cancelled

#

How do I fix this?

viral orchid
#

are you checking repeatedly if the button is being pressed

fallen charm
#

Its set to performed, which SHOULD mean that it works whenever the button is held

viral orchid
#

maybe call self.on_performed() in update method

#

idrk

fallen charm
#

Ive heard its best not to put input related things in the update method because then frame rate effects input

viral orchid
#

oh. well if ur gonna seperate input handling from update method so frame rate isnt made worse, then maybe make a handle_input method:

def handle_input(self, pressed):
self.pressed = pressed

    if self.pressed and not self.prev_pressed:
        self.on_pressed()
    elif not self.pressed and self.prev_pressed:
        self.on_cancelled()

    self.prev_pressed = self.pressed

then in the loop call button.handle_input(pressed)

#

lmk if it works

mental jackal
#

hello, so i had this code setup, and I noticed that when I would press "A" it would move me forward, and "S" it would move me left and vice versa, and I checked my input manager and everything seemed to be fine so I was wondering if there was something wrong with my code?

viral orchid
#

check what your binds are in your input system

mental jackal
#

my binds are the default in unity