#🖱️┃input-system
1 messages · Page 12 of 1
ok
keep going
add more logs and see where it stops
e.g. add one inside the raycast if statement next
Also make sure you're not getting any errors in console. (maybe you have errors hidden for example?)
confident that I dont, it shows 0
and you are weirdly right, it does stop at the raycast, weird considering the same raycast does do the exact same thing but elsewhere
ok now you know where to look next - figure out what's going wrong with the raycast.
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...
Inspect / debug all the parameters
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
i copy pasted the code
same code sure but the scene is in a different state at those two points
also it could be running on a different object
with different data
i put it in the same script
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
Something about the raycast is probably different
its kinda not getting into my head, both the raycasts are ditto the same
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?
I'd probably use the event system for this - IPointerClickHandler
does anyone know why this doesnt work now😭 😭 😭
script:https://gdl.space/akunimiwom.cs
you really need to explain what is wrong
"it doesn't work" is borderline meaningless
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
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
If you haven't already, I'd suggest taking a look at the touch samples in the input system package. I think you can figure out your user case from there! Good luck!
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?
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();
}
}
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
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
Why is my button not registering a click despite following this tutorial to the letter?
Tutorial:
https://www.youtube.com/watch?v=IqpgJlhtmoo
(Video with my settings)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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/...
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
This isn't a great way to handle input.
Probably the performed phase is happening and tripping you up
should I use unity events or C# events?
alright. what's better about it?
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
Let’s check out what Unity is working on for the new Input System!
► Go to https://expressvpn.com/brackeys to take back your Internet
privacy TODAY and find out how you can get 3 months free.
● Get the new input system here: https://bit.ly/2SiXsgS
👕Check out our merch! https://lineofcode.io/
♥ Support Brackeys on Patreon: http://patreon.com/b...
alr thanks i'll check it out
Hello, using the new input system, how could I manually change my device during runtime?
i'm pretty sure that when you use C# events with the Player Input component, you just subscribe to a single event that gets fired for every single action
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
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
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'
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;
}
}
!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.
please use a paste site for large blocks of code
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
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
i'd just clamp the brake torque
torque = Mathf.Max(0, torque);
something like that
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;
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
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?
You should use PlayerInputManager and the PlayerInput component
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
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
if you use Unity Events instead of SendMessage then you can check the CallbackContext parameter you get
public void MyCallback(InputAction.CallbackContext ctx) {
if (ctx.started) {
}
else if (ctx.performed) {
}
else if (ctx.canceled) {
}
}```
Yeah I know but Im basically bound to SendMessage since I need the Player Input to only communicate with the inputManager I made in the same object
That doesn't mean you're bound to send message
unity events do the same thing
just assign the callbacks to the input manager instance on the same prefab
ok I'll try, maybe I mistaken it with the invoke c# events behaviour
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.
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
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
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.
I fixed it, it was because I didnt click save asset to apply changes
now I can go back to fixing the original error I was having
jeez
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
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
maybe this is the problem? https://stackoverflow.com/a/65027248
@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
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
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?
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
}
It's from the event system
You have to upgrade the input module on it
omg ooh I see it now, wtf
you guys are freaking beast
omg Im getting a new type of error, cant add script
ima google this one, bc its not code related
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
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)
How can I detect if a controller input gets unplugged? I tried this but its not working
yeah probably this, how can I sue this event from the code?
Subscribe to it like any other event in C#
mhhh...any help?
eh?
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?
I would like to use the premade Device Lost Event but is not working, even if I put inside it a simple debug.log and unplug the controller it doest fire the event
So either something is wrong here or I need to find an alternative to get the PlayerInput that disconnected
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?
wdym "continuously"? How often? Why?
Repeatedly for as long as it is held down
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^
I have that part handled, it's getting the interaction to fire performed in the first place correctly that I'm struggling with
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
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.
You have two options:
- do something like what I wrote above
- implement your own custom interaction
I am currently implementing my own custom interaciton
Sorry if I hadn't made that cleaerer
Yeah but there's a whole timer situation in there that you'd have to change too
I have
I guess there's a bug in your implementation
It's probably a lot easier to just do something outside the input system like this
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.
Does anyone know how to get this to work with the new input system? https://gdl.space/hecifatibu.cs
This is my action map
This is my empty game object
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?
What is the position of your tilemaps / sprites?
everything is 0,0,0
and I wasn't using that extension but I probably should
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
Depends how you want it to react to those inputs
But basically - make an input action with both of those bindings and use it
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
how would you know without loading them? Wouldn't they be stored in some kind of save file?
Check if the file exists, no?
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);
}
so it looks like you already have a solution to what you asked
sorry just placed in the wrong place
How can I properly check if a player is scrolling using the new input system?
There is an input axis for scroll wheel. Use that.
I already got it working, but thanks for the reply 🙂
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?
A shared instance has a few benefits:
- Better for performance
- The ability to globally enable / disable action maps
multiple instances will work in general - meaning you probably just failed to do something in the laptop script - e.g. enable the instance.
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
you'd have to show your code
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?
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)
Ah yes I'm getting a NullReferenceException on CarInputs._controls.Laptop.ToggleLaptop.performed += ToggleLaptop;
yep - you have a script execution order issue
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
Rule of thumb:
- self contained initialization goes in Awake
- when you need to reach into another object that needs to be initialized when you do - use Start
No more NullReferenceException, but nothing happens when I press toggle
Do I need to call SetCallbacks()?
no
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
...
}
}
}
CarInputs._controls.Laptop.ToggleLaptop.performed += ToggleLaptop;
CarInputs._controls.Laptop.NextScreen.performed += PageRight;
_controls.Vehicle.Laptop.performed += ToggleLaptop;```
Why are you subscribing to actions on both your own instance and the CarInputs instance?
Whoops I'm not doing that, sorry I copy and pasted my sections of code wrong
and anything you do to CarInputs (e.g. enable/disable action maps) won['t affect your instance
Dumb question here… if a game object is already enabled, is OnEnable called when the game first loads?
yes
It's called when the object is created and initialized, which happens when the scene loads
Hmm in that case I don’t understand why the subscribed events aren’t being called
you'd have to show the current code
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");
...
}
you never called _controls.Enable()
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
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
running, jumping, steering, and FOV zooming are 4 different features.
Work on them one at a time
!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.
📃 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.
is this trash? https://hatebin.com/vnoltidffd
Can someone help me💀
I don’t know how to solve it, I just want to make my character controller work
As it says, your code is using the old input system but you switched your project to the new one
You have to update the code to use the new one or switch the project back
how can I update the code for using it
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.
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?
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"
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?
with the new input system, is there a way to check when a key is released?
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
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.
im trying to do this if (playerInputActions.Player.SwitchItems.WasReleasedThisFrame) but was relesesed this frame is a method so that doesnt work
so... call the method?
if (playerInputActions.Player.SwitchItems.WasReleasedThisFrame())
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
even if this was true (which would be wild):
bool wasReleased = playerInputActions.Player.SwitchItems.WasReleasedThisFrame();
if (wasReleased)```
Hello, how would I be able to MANUALLY SAVE the input device to give it to another PLAYER INPUT component?
Hi, how I can remove this input events? I try "inputActionSprint.performed -= ctx => isSprint = true;", but this doesn't work
make it in to a function instead
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
Thanks 😉
you can also store the anonymous delegate in a variable/field
class Sample
{
event Action foo;
Action _handler;
void Enable()
{
var t = DateTime.Now;
_handler = () => { Debug.Log(t); };
foo += _handler;
}
void Disable()
{
foo -= _handler;
}
}
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
Those are two different instances of the input asset
sounds like you're only rebinding the PlayerInput's copy
oh i see
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
thank you that makes sense. i should be able to figure it out
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?
You need to share the code, the error message, and be specific. No the input system doesn't treat them differently. You've made a mistake somewhere.
Thanks, if I can't get it figured out I will share more. Just wanted to check that it wasn't something weird like that as I didn't see any mistakes. Will take another look through though!
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
apparent resolution: everything was ok when put in update -- it's just that rotation should also be done in update https://forum.unity.com/threads/released-kinematic-character-controller.497979/page-25#post-5731675
Which makes sense. The camera needs to rotate every frame.
it feels great now
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
well, just having an action doesn't do anything
how are you using the LookMovement action?
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
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
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?
you might have been using Cinemachine
the Cinemachine POV aim component can directly read input
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
once you have a POV camera, it should have a little info box saying that there's no input provider attached
ah got it
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
-
How are you checking that they're false?
-
Why not just use a 2d composite instead of 4 actions here?
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
In the input system what's the difference between Button With Two Modifiers and Two Modifiers?
Also what does Override Modifier Need do?
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
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.
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?
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?
maybe this will help you:https://stackoverflow.com/a/71488591
this is the unity docs page referred to in the above linked answer: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasReleasedThisFrame
if it works it work 😋
just like tarkov
we have multi view depend on scopes
I'm not sure if I understand (since I didn't play tarkov)
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
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...
idk how to get rid of it xd
I still don't get it
I was asking what's the difference between "Button with Two Modifiers" and "Two Modifiers" in Unity
"Button with Two Modifiers" have 3 parts of binding
So does Two Modifiers
1 binding?
This is why I am confused since I didn't see a difference between them
There's a 1 Modifier version
trying to figure out how to make a sprinting script
holding down a button should make the character faster
great
managed get it working but on the character is now always running after when i pressed once
When you calling this function
when i pressed the button
void Update()
{
if(Input.GetButtonDown(SprintButton))
Speed = SprintSpeed;
else if(Input.GetButtonUp(SprintButton))
Speed = DefaultSpeed;
}
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
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
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)
You dragged the script itself instead of the component attached to a GameObject
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?
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! 🙏🏽
(please mention me along with your response)
Lock the cursor
Thanks. I indeed didn't look the cursor, but it makes no difference unfortunately.
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;
}```
if (device is Gamepad g) return g;```
What is leftshift's name in input manager?
'leftshift' doesnt work
HELP
Thanks
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?
you'd have to show your code
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.
you'd have to show your code. It's possible you are dealing with multiple instances of your input action asset and not enabling or listening to the correct one
{
if (!context.performed)
{
return;
}
_controls.Player.Disable();
_controls.UI.Enable();
_uiGameObject.SendMessage("OpenInventoryWindow", SendMessageOptions.RequireReceiver);
}```
this is only a small part of the code
and possibly the least important part.
show the full script
it's the part I know is working
_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
{
public InputMaster _controls;
...
public void OnEnable()
{
if (_controls == null)
{
_controls = new InputMaster();
_controls.Player.SetCallbacks(this);
}
_controls.Player.Enable();
_currentScene = SceneManager.GetActiveScene();
}```
ok and where do you set the callbacks for the UI map?
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
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
you would need to do _controls.UI.SetCallbacks(somePlayerUiManagerInstance);
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
by default the input module uses a completely separate input action asset
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
so it's fine to leave it on the default if I don't want to override those?
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
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.
I would fix this by getting rid of this code entirely and use the event system for everything
e.g. use IPointerClickHandler on the map or a big invisible UI element behind everything else to run this code
The code for my composite is the same as the one in the link...just a small fix to make it compile with a new version...do you want to see any other code?
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
- What fix did you make?
- Maybe you copied something incorrectly
- yes of course - the code that actually handles hooking up and listening to the action
- Just added a public var missing
- Checked everything several times
- It is just the method I sent in the original question hooked up to the unity event of the input action
Is there any way I could control the conditions that trigger these actions? I understand that it happens when the context changes: started/performed/cancelled...do you know about this?
All the triggers happen correctly the problem happens when I press left A, then right D for instance, there is no context change thus no event ...but with the first press or any button release any I get the call
sounds like it may just be a consequence of the implementation.
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
yes, I will go for this, polling on the Update...thanks!! sorry I thought I posted the code...my bad
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?
Cant someone help me out?
I am having this issue where I have both the pick-up (PickItemsFromSlot) and drop item (DropItemsOnSlot) action both using the same button (LMB) and they are both fired at the same time so it always picks up and right after drops the item on the same frame...
Any obvious way to fix this?
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 😄
The right way to do this is to use the event system
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?
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?
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:
- Is this the right way ? Is there any other way to handle custom layouts ?
- 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.
- If in entirety any other better solution or premade solution is present which covers all usecases Im happy to hear.
Thanks and Regards.
OnMouseDown has the same limitation
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.
Thank you for your response, @austere grotto !
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 ?
there are USB controllers that uses the Playstation layout and some that uses the XBOX layout right?
how does the Input System differentiate that?
It just uses generic terms like "left joystick" "right joystick" "button south" "button north" etc and makes reasonable default guesses. And as a last resort, it supports runtime rebinding in case someone's gamepad is just funky or whatever.
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?
Ps dpad will perform directional operations. Thats the essence of input system compared to legacy where axis mapping were hardcoded
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...
I would also try using the input debugger and see if and how it's getting picked up
Difficult part: this is strictly on my steam deck
ahhh I see
I did check that d-pad input is working in game
i'm also having a related Very Weird Issue #📲┃ui-ux message
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.
this could help with that
monitoring the currently-selected object (according to EventSystem) indicates that the selection isn't actually wandering off to other places.
god this is weird
steam sometimes does some weird joystick emulation stuff
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
weird
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!
the Other Problem remains. go figure.
well
in the meantime
i think i'm just going to say "don't use the d-pad"
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?
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?
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?
Wouldn't you want the text to display in the same language as your keyboard?
It seems to me that English language is necessary for bindings
you can set the input action's shortDisplayName if I remember correctly
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?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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...
the input was choosing keyboard for a player and gamepad for the other
all I needed to do is in the code force both PlayerInput components to switch to the keyboard schema
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?
solved by disabling all of the enabled actions when the rebind operation is running
You never hooked up your functions to the PlayerInput instance nor any input action assets in this code. Setting it up in the inspector for PlayerInput is indeed one valid approach.
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
If you use the event system for everything, UI elements will block clicks on stuff behind them
If you're doing your own manual raycasting, all bets are off
I tried setting it up in the code, but it didn't seem to work, so I used the PlayerInput inspector
What happens if I hook a Hotas to the PC and use input system?
Do I need specific setups for it?
Well it doesn't, and I'm not raycasting anything 
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
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 :
Welp, that seems to be the way to go, despite having warnings :l
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/manual/UISupport.html#ui-and-game-input
Welp, it works
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)
This is your PlayerInput component
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
No you're not using the event system here at all
Assets\Scripts\GameManager.cs(12,12): error CS0122: 'InputManager' is inaccessible due to its protection level
How to fix this annoying error pls
Post your code. The error means that the InputManager you're referring to isn't public
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...
}
UnityEngine.InputSystem.InputManager is internal, not public. Your code is trying to use that. Are you sure it's not supposed to be PlayerInputManager?
Its player input manager
It says public InputManager inputManager on line 12 there, not PlayerInputManager
Fixed
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?
Just set those keys up as bindings to the actions
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.
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?
There are other points in the game where the module is working fine, just not on the title screen when the game first loads.
How i do it on the code ?
You don't
It's done in your input actions asset
These are the basics of the input system
but when I press z it plays the walk animation but also the q, s and d keys except that I would like s to play the walkback animation
It does whatever your code tells it to do
so I'm trying to figure out how to say in my code z = walk and s = walkback
Don't worry about the keys
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)
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);
}
}```
Yeah just if (Move.y < 0) then you know it's going backwards
ok so up = 1, down = 0 and right and left ?
Down is -1
Right and left are the x component
ok
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);
}
}```
You didn't do what I said
Read your code
It doesn't make sense
This is what I suggested
if(Move.y < 0) is for S not for Z
it all depends how you bound your controls to the action
I am not privy to that information since you haven't shared it 🤷♂️
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
You have a mouse position in a VR game? Also mouse position doesn't seem appropriate for something called "mouse movement"
I need movement but im just trying to get it to work like this and i can figure it out later
Can you explain the mouse position in a VR game thing?
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
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
Is it?
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?
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?
just disconnect the concept of a "player" from an actual character or avatar or whatever in your game.
a player is, basically, an active input device in this context.
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.
and then initialize the real PlayerInput on the correct prefab
You're fighting against the system. Just work with the system. Set things up such that the input events are redirected to or simply listened to by your "correct prefab" when it is spawned.
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.
Still didnt get an answer
does Gamepad.current.leftStick.ReadValue().y; get vr controller input too? (quest 2 pcvr)
Could someone explain me the comment or give me a code example for that? I think maybe its my problem.
Its from Unity Website in the ActionsAsset and PlayerInput Components Workflow, https://docs.unity3d.com/Packages/com.unity.inputsystem@1.6/manual/Workflow-PlayerInput.html .
public void Update()
{
// to use the Vector2 value from the "move" action each
// frame, use the "moveAmount" variable here.
}
@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^^
It's just telling you that variable has the input data in it
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
Okay thanks for your feedback, I will add some more informations to ask a better question!:)
Check in input debugger weather your device gets mapped to any existing ones (incase it emulates native input) or it recognises as seperate device.
Then proceed to modifying inputActions accordingly and use ‘yourinputaction’.performed or ‘yourinputaction’.ReadValue() according to input type.
That will save you a lot of headaches.
I just went with vr joystick
Hey, I need help understanding why this doesn't work how i want it, when i play my scene, i cant jump nor will my ui work, https://gdl.space/wecinitofo.cs.
I mean, the whole system is working fairly nice on its own, but you shouldn't expect to take only a part of it and make it work like a charm
You should really consider using it as it is, and adapt your code on top of it
Either that, or create your own system, because fiddling with it will eventuallt cause bigger problems afterhand
You dont check for isgrounded at all and that whole => Physics.Raycast(new Vector2(transform.position.x, transform.position.y + 2.0f), Vector3.down, 2.0f); belongs in FixedUpdate or Update.
the code probably fails there and thats why the ui doesnt work aswell
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
Found my problem - it's a bit trickier to manage state with these functions, and I didn't have my previous/new state filters set up right. Easy fix, once I found it.
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.
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)
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?
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
The two actions as they are currently, in case my explanation wasn't clear
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
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
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.
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
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!
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
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
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).
And here are the devices in the Input Debugger
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
Most likely your plugin has an assembly definition and you'll need to add a reference to the input system assembly in that assembly definition
you mean in one of those?
no wait in the plugin, oops
okay, got it now. thanks for the help!!!
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 ?
No need to unsubscribe when disabling an action map.
Only unsubscribe when the subscriber is being disabled or destroyed
So im trying to make it so you simply tap the button but for some reason even holding triggers it
{
_jump = context.action.WasPressedThisFrame();
}```
does anybody know how when using Primary Touch/Touch Contact? I can avoid detecting touch if using OnScreenStick or OnScreenButton?
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.
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?
Who knows. Wdym by having them in the scene? Wdym by canceling out? These are assets. They're never directly in the scene
Also the input system has a whole control scheme system you can and should be using
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.
show screenshots of your input module, event system, etc inspectors
It is exactly how I described it (this is the broken setup)
InputActions are the DefaultInputActions in the package
what is your Active Input Handling set to in project settings?
It is set to use the new input system package
EDIT: one other setting I've changed is that I have set my target architecture to ARM64 and enabled il2cpp (ARMv7 w/ mono is not compatible with my device). Unity 2022.3.0f1 LTS InputSystem 1.5.1
Is there an up to date example project that proves this package even works? Warriors hasn't been updated for 3 years
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?
I'll submit a unity bug. Might be the new LTS for all I know. I have gotten it to work in the past
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
Yeah the color transition happens, but just the press, not the "up" (so it gets stuck in the pressed state)
what hardware are you testing on
Google pixel 7a and my windows desktop
Ah I also have the 7a. horrible battery life 😢
Hi!!!!
Guys is there a way to create a combo with the action mappings like street figther? for example:
Afaik you would be better off coding your own solution for this. You can require another button to be held down at the same time (press A and Y to do an action) to trigger the event you want (via modifiers) but you can't encode a sequence (A then Y). Maybe this is something they're working on?
I think the point of the inputs system is to make this kind of behaviours
No the point is to handle lots of different input methods (controllers, keyboards, etc) and map them to the same actions.
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
yep make a state machine to recognize the input sequences
no the input system will not handle fighting game input combos
more like:
"light punch", "medium punch" etc
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)```
yes i understand the modifiers
how would you make a combo? i never worked with state machines, it sounds like something a will like
This might be a helpful guide
https://andrea-jens.medium.com/i-wanna-make-a-fighting-game-a-practical-guide-for-beginners-part-6-311c51ab21c4
Input buffers — or how to read and make sense of that list of mashed buttons.
is that link using the input system?
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
@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?)
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
you'd have to show how you actually hooked the actions up to the code
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
for keyboard you want a 2d axis
That's irrelevant to the question
though it's true that Get<Vector2> is going to fail for a 1D axis
Yeah notice how the composite type for keyboard is "1d axis"
wait nvm i meant 2d vector
This is what I have mb for not sending the whole thing, hope it helps
theres no function
these are both doing nothing
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
I'm sooo lost I watched dozens of tutorials and they were all different lol... my brain hurts
I know that feeling
there are a few different ways of using the input system
you should just stick with one way for now to avoid confusion
I recommend simply hooking up player input to the functions
to do that though they will need to use the InputAction.CallbackContext parameter type
not InputValue
Be sure you only have on player input component
(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
that's part of it... it's also being hooked up somewhere that you haven't shown us yet.
could be in a PlayerInput component inspector or some other code
it will give you a list of scripts and then a function to assign it
Your Move code would work if your PlayerInput component was set up as "Send Messages" mode though
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
For some unknown reason the No Function button is disabled (?) and it wasn't like this last time I worked on all of this
because it doesnt have an object
oh what
(put the player itself in)
it just unlinked it for some reason
(im assuming your movement code is on the player right?)
yes
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
Link the move input to OnMove
Which im assuming is in your player_movement script
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 
Yes thats what i meant
also yeah i know its confusing even im confused about somethings
Such as applying it to a state machine
Did you put InputAction.CallbackContext in the parentheses of the OnMove function?
now test
id do this
movementValue = context.ReadValue<Vector2>();
put this in the performed parentheses
that way movementvalue is set to the vector2
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
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
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
so for example rb.force(movementValue.x,movespeed)
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
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...
My guess it’s to have a trigger that sets the position of the player to a certain point in the map
Also this has nothing to do with the input system
@fallen charm where does it belong?
Probably code general
@fallen charm thanks.
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
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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?
The two bits of code you highlighted don't seem to be directly related to one another
so it's unsure what you're asking for exactly
new input systems trigger events when input is pressed
Are you asking "How do I check if the X key was pressed this frame"?
thjat is one of the things it can do
old input works with Up And Down
It can do many things
right, Im thinking if it is possible to get 2 events, for up and down with the new input system
😊
You could use this for a 1:1 replacement for GetKeyDown
DashDown = Keyboard.current[Key.X].wasPressedThisFrame```
you don't want events, you want polling
since you're polling in the old system
And for released:
DashDown = Keyboard.current[Key.X].wasReleasedThisFrame```
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?
You go to Control Schemes
Then add something like gamepad
So basically its like this
is that something I should configure on the PlayerInputActions asset?
nope
this bypasses the input action system entirely
just like GetKeyDown did
(bypassed the old axis system)
oh ok but isnt that going to work only for keyboard?
Im just using the new system to suppor xbox controller
yes, your existing code only works for keyboard too
if you want it to work for more things, you should use input actions
right, that is my goal haha
if you want minimal code changes you can still poll input actions
ok, I should refactor to work with the event I guess
thanks!
sorry for being so slow with this
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.6/api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasPressedThisFrame
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.6/api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasReleasedThisFrame
no you don't need to
like I was saying, the new system can be used in many ways
Anyway, how can I properly connect each input action in an a state script
wait nvm I think i know
nvm didnt work
btw heres the state machine
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I cant find anything on how to do this damn thing
what are you trying to do
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
Do you have a reference to the player state machine in your script?
all state scripts mention the player state machine
I see
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
ah right thought it was your own mono behaviour for a sec
So I do kind of have a solution but its flawed
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
This is what i did before
The problem is that this method isnt good for using started,performed, cancelled etc
How do you want to configure which button does what? Cause there's a couple of solutions you can use
sorry im just so confused
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()
im trying it
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
Can anyone explain why my joystick
isn't working?
My keyboard controls work perfectly
Completed working on device detection module and so far it works well, might help you and others.
Cheers.
PS TouchScreenPad is my Custom Input Device so it might differ in your use-cases.
you 'd have to explain what "not working" means and show the code for this Joystick script
Could I DM you so i don't spam this channel?
no
didn't you literally just complain about this channel being "dead" 10 minutes ago?
Why are you worried about spamming it now.
its code from an asset. i'd rather not share it pubicily
Man. this discord is so hostile
No worries, thanks anyway man.
Well you shouldn't share it privately with me either then
I promise you man, you can be happy in life. you don't always need to be upset.
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
For some reason I when I try to add the action in my state script I get an error thats says "NullReferenceException"
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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
You never assigned _p
Or perhaps _p.p_input
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
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?
so it cant be this
Huh
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
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
_p is clearly null
the reason i did that was because
{
player.velocity.y = Mathf.Sqrt(player.jumpheight * -2f * player.gravity);
}``` would not work
Of course not, that doesn't make sense
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?
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.
anyone know how i can stop listening for input in the new unity input system?
Well, you have to .Enable() your input action map, so just call .Disable() on it.
oh ok, thanks
Are there 4 joysticks connected ? or are those just multiple entries of the same device ?
The adapter has 4 ports to plug different gamecube controllers into
@crimson schooner
so debugger shows 4 entries regardless of how many are connected ?
I dont kow if your up to help but i think i need to enable my action but i cant seem to figure out how to do it, ive read the documentation and im just a bit slow, this is what i got so farhttps://gdl.space/fapaleqovu.cs, if you have any advice or imput i would really be so thankfull
my menu doesn't want to work at all, and my jump use to work but that stopped when i added the IfGrounded statement but thats something else i can do on my own and tweak, but if you have any idea on why my menu wont work then please let me know
nevermind i dont need help, i got it now
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
UIinput map - we unpause the game (timescale, etc) (frame A)
- we switch input map from
UItoGameplay - 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
it was this ^^'
all that remains is to figure out why the action triggers twice
your code might be subscribing more than once by accident
didn't look like it, but i might've missed something; I changed it to use a passthrough action type and there's no more duplication, and it fits better to the needs anyway 🤷
thanks
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?
Correct. Sorry for the delayed response, I'm at work
The debugger shows 4 entries regardless, but only one of them will update the value column depending on the number of controllers plugged in
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?
By depending on number you mean 2 controllers are connected and upon pressing key from any controller, only 1st controller's values in input debugger are updated ?
Can you explain it a bit ?
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?
why is this happening? i cant see the textbox and everything is overlapping
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?
Two Cups Of Coffee Or Become A Pro Game Developer?
https://www.awesometuts.com/ultimate-game-dev-academy-dis?utm_medium=video_page&utm_source=youtube&utm_campaign=videos
The Untold Secrets Of Mastering Game Development (Free Training)
https://www.awesometuts.com/3-day-free-training
If You Are A Complete Beginner And Want To Learn How To Make G...
Yeah, I showed it here #🖱️┃input-system message
Do you have a similar issue?
no mines different, i can install the 1.6.1 but the issue is UI of the Input system overlapping
Only the corresponding "port" of the adapter will have it's values updated, but this is expected behavior. This is what the adapter looks like for reference.
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
Can someone help me?
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)
I think you can add an InputAction to detect when you are pressing the screen. Then, add loop and while the screen is pressed, with an other InputAction, get your current screen position
Just use the event system for the game world interactions too and you get this free
Are there any examples of floating joystick designs that utilize the on-screen stick available?
Just change the behaviour in the on screen stick to ‘ExactPositionWithDynamicOrigin’ rest all remains same.
Turns out that I had an old version of the input system package installed. Upon researching your comment it became clear I had to update it, which then revealed the behaviour field. Thanks!
Understood, Will update u on this asap. Gotta dig around a bit myself!
Glad it worked out!
What do you mean ?
Instead of using manual Raycasts for your game interactions, use event system stuff like IPointerClickHandler
It work, Thx !
For some reason performed phase wont work properly for my state machine (it works but holding the button down does nothing)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
started and cancelled work fine, but performed will just behave like cancelled
How do I fix this?
are you checking repeatedly if the button is being pressed
Its set to performed, which SHOULD mean that it works whenever the button is held
Ive heard its best not to put input related things in the update method because then frame rate effects input
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
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?
check what your binds are in your input system

