#🖱️┃input-system
1 messages · Page 8 of 1
👍
Oh and one last question @sudden lagoon how can I detect if key is selected
something like this maybe? GameObject selected = EventSystem.current.currentSelectedGameObject;
you might want to check ISelectHandler and use something like
public class ExampleClass : MonoBehaviour, ISelectHandler
{
public void OnSelect(BaseEventData eventData)
{}
}
thanks, if not ill ask the always wrong chat gbt ai
chatgbt will know, it is amaizing for these kind of things, I use it constatly also 😄
I think he will give even better example than I can :"D like 100% sure of it 😄
honesty its so helpful for learning
and if its wrong
then we have this awesome community
chat gbt likes to use OnPointerDown
On pointer down is quite nice, as it works for touch and mouse. And also solves quite a lot of problems on webgl.
hmmm
Too be honest, I haven't looked into the new input system much, but is there a way to map Touch.Phase events to webgl click/drag events so that I can do my intended mobile builds and webgl? I just want to know if its possible before I head down that path. Thanks.
Touch.Phase is a concept from the old input system.
when you say "WebGL click/drag events" what are you talking about?
Are you talking about Unity's UGUI OnDrag OnPointerClick OnPointerDown etc? If so, yes you can use the new input system with that stuff, and with touch.
I just wondered if I can utilize one controller logic that will work for both. I do utilize Touch.Phase.Moved/Stationary etc. I was unsure if the new input system would handle the same way regardless if it was on webgl or mobile.
But yes, the built in OnMouse(events)
OnMouse events dont work with the new system. You should use the more robust UGUI events
so you are saying void OnPointerDown(PointerEventData eventData) detects both mobile touch and webgl mouse touches ?
Maybe the question should be worded this way. Does the new input system allow universal logic that accepts input from mobile touch and webgl pointer events that doesnt require writing custom code for each implementation?
I don't really know what that means exactly
You know how you can map multiple console controllers to the new input system using mapping ?
can the same thing be done for mobile touch and webgl pointer events
in what way? Like each finger being a separate player or something?
What I want to accomplish:
Develop a game that builds to mobile devices (Currently using Input.GetTouch(0) / Phases)
Build down the same game in WebGL where the player can use the mouse for click/drag/hold events.
Expected Outcome: (using new input system)
I want to use universal logic that supports both, without writing custom logic for each event.
I don't need to support multiple touch events
Not sure as to the terms (I don't have Unity open) but I think your control is set to a single value whereas you need a Vector2 to work with the Right Stick
i think my issue might be input system related for my player action map
my playercontrols script aint working
i cant move
Show how you set things up?
probably missing something simple
like an Enable() call
hi, how would you manage multiple gamepads and UI, with old input system? where each gamepad can only interact with certain ui elements. (for context, I'm trying to make a character selection/editor screen)
yoo im having some trouble with the input actions
so the joystick works fine but the wasd inputs are only down for like .1 seconds
im not sure if this will interfere
Recommend just polling for this style of input, but if you must use events you need to subscribe to the canceled event too
im jus following a tutorial
i fixed it..keyboard input doesnt work if u have a controller plugged in. do you know how I can resolve that issue?
How to map inputs to images to show what button it is?
anyone who uses new input system who could help me with some joystick movement
the problem is
that when i drag my joystick i have to keep dragging it i want it to keep moving as long as i have dragged it from its rest position
and i want to add a keep moving function for that
can anyone help me out please
Hi,
I'm having an issue with the New Input System (1.4.4) with Unity 2022.2.1. I have two objects with a PlayerInput component: Game Engine, and a Player. Both work fine in editor, but the one in the Game Engine doesn't work in build. The Player is spawned later which I would guess has something to do with why it works... Race condition?
Your code prolly has a value thats overwritting the Editors Value during runtime @maiden grove
Which value?
Idk i would have to see the code lol
hi I was trying to create an input system with the help of the built in Unity input system. However it is not working for some reason and I am not sure why
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SG
{
public class InputHandler : MonoBehaviour
{
public float horizontal;
public float vertical;
public float moveAmount;
public float mouseX;
public float mouseY;
PlayerControls inputActions;
public Vector2 movementInput;
Vector2 cameraInput;
public void OnEnable()
{
if (inputActions == null)
{
inputActions = new PlayerControls();
inputActions.PlayerMovement.Movement.performed += inputActions => movementInput = inputActions.ReadValue<Vector2>();
inputActions.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue<Vector2>();
}
inputActions.Enable();
}
private void OnDisable()
{
inputActions.Disable();
}
public void TickInput(float delta)
{
MoveInput(delta);
}
private void MoveInput(float delta)
{
horizontal = movementInput.x;
vertical = movementInput.y;
moveAmount = Mathf.Clamp01(Mathf.Abs(horizontal) + Mathf.Abs(vertical));
mouseX = cameraInput.x;
mouseY = cameraInput.y;
}
}
}
here is my code
I am assuming the first half of the code is working as the "movementInput" is giving me values however there is no change of values in both horizontal and vertical
horizontal and vertical are simply extracting the x and y coordinates from "movementInput" without including anything complicated and so I am really confused why it is not working
Where are you calling TickInput?
Also I would remove the closures in this code, as they make this a lot harder to read
(Basically replacing your lambdas with proper methods)
It's for the use of player movement part🤔 Not 100% sure why is it necessary as I am referencing someone else work
But is it the reason why it is not working?
Sorry I am new to unity and coding so I do not quite understand what are you referring🙏 do you mind elaborate more on that part?
If your MoveInput method is never being called it's not going to do anything
Oh shoot. Right, missed that part🥲
Thanks so much for the help. I will take a look and see what I can do tmr. It's like 4.40 am in my country and I am going to bed🤭
But really appreciated for the help🙏
All good 👍
Since you asked earlier, I'll rewrite it to remove the closures, you can look at it tomorrow if you like.
Sure. Thanks for the extra effort🙏
public void OnEnable()
{
if (inputActions == null)
{
inputActions = new PlayerControls();
inputActions.PlayerMovement.Movement.performed += MovementPerformed;
inputActions.PlayerMovement.Camera.performed += CameraPerformed;
}
inputActions.Enable();
}
private void MovementPerformed(InputAction.CallbackContext context)
{
movementInput = context.ReadValue<Vector2>();
}
private void CameraPerformed(InputAction.CallbackContext context)
{
cameraInput = context.ReadValue<Vector2>();
}
This is what I meant
It just makes it easier to see what is going on without the variable capture
public void HandleCameraRotation(float mouseX, float mouseY)
{
lookAngle += (mouseX * lookSpeed);
pivotAngle -= (mouseY * pivotSpeed);
pivotAngle = Mathf.Clamp(pivotAngle, minPivot, maxPivot);
Vector3 rotation = Vector3.zero;
rotation.y = lookAngle;
Quaternion targetRotation = Quaternion.Euler(rotation);
myTransform.rotation = targetRotation;
rotation = Vector3.zero;
rotation.x = pivotAngle;
targetRotation = Quaternion.Euler(rotation);
camPivotTransform.localRotation = targetRotation;
}
can sum1 tell me why my camera is kind of glitchy? when i run HandleCameraRotation in void update its smooth but the player goes all blurry, in fixed update its a bit jittery, and in LateUpdate it's also blurry
my controls file was accidentally made into a visual studios file instead of an action input file, how do i change it back??
anyone plz im so lost : ((
make a new control file?
Hello, I have this function that gets called when I press the left mouse button. this is Character class and I have two more classes, GunSlinger and Warrior. When I inherit from Character on GunSlinger it works fine. But when I inherit from warrior. I don't even get the print. What is wrong with this new input system?
@here
show code
show full scripts for warrior and character
ok, this photo is in the base class "Character"
the one above
this is the one on warrior
📃 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.
how can i make sure that two buttons/keys need to be pressed to trigger a certain action
theres a binding with modifier thing
can you expand by what you mean by modifier?
@austere grotto the character base class is : https://gdl.space/pamaguyucu.cpp
modifier is the second key
@austere grotto this is warrior class : https://gdl.space/hafivekero.cs
@austere grotto and this is gunslinger : https://gdl.space/ilaliqaqoc.cs
if (!_canDoPrimaryAttack) return;
base.OnPrimaryAttack();```
you are only conditionally calling the base method
I tried putting it above and that also doesn't work
it's onenable
you are not calling base.OnEnable
so it never runs
and the subscriptions never happen
I also don't do that on gunslinger tho
gunslinger is fine because it doesn't define OnEnable of its own
only warrior does
ok ima try that
You'll also want to do it for Awake and OnDisable too
and anything else you "override" in subclasses
I'll let you know
(you'll need to mark them virtual)
I'm 100% confident this is your main issue
I've seen this problem many times before
okay so i found the modifier plus binding but it seems i can only have a singular binding for either the modifier or the key. i want to try setup a sprint so i can have the left shift as the binding but i need wasd as the modifier in a 2d vector? is this possible?
you'd just do this with two actions
a move action and a sprint action
@austere grotto THANK YOU SO MUCH
It works lez gooo
I get it now
I didn't know it automatically overrides other functions
super simple in update:
float speed = sprintAction.IsPressed() ? sprintSpeed : normalSpeed;
Vector2 moveInput = moveAction.ReadValue<Vector2>();```
then just move using moveInput and speed
okay sorry could you explain what the ? and the : are
i think i get that if (sprintAction.IsPressed()) {speed = sprint speed} else {speed = normalSpeed}
sorry im a pretty amateur coder
yes it's exactly what you said
just a short way of writing that
okay great so i just use the sprint key to change the speed of the walk
yep
is that still possible to do if i want my sprint key to also be my roll key. im trying to copy the dark souls movement scheme for my controller if this is any help in understanding
sure why not
doesn't really change much here
i want to crate a joystick with on 8 axis movement also i want to normalize the value i tried the process and using .normalized but it does not work idk what's wrong
to do that would i have to use interactions, like if it is tap then roll but if held then sprint? would that work with one action being held and one action being tap?
also may seem really stupid at this point but how can i reference like sprintAction.IsPressed() in my script?
neither would use a hold interaction
for this you'd need to have a reference to the input action somehow
either using public InputActionReference sprintAction; and dragging/dropping. Or doing like InputAction sprintAction = myPlayerInput.actions["Player/Sprint"] or if using the generation actions class myInputObject.Player.Sprint;
or directly defining it public InputAction sprintAction; etc..
there's many way sit all depends on how you set things up
is there a way i can some how import my input system and then do like inputSystem.sprintAction so i dont need to define all my actions or is that not possible?
yes using the generated actions class
okay so i make a reference to that (i think that would be using objects) then i can just do PlayerInputMaster.sprintAction right?
it'd be:
myInputObject.MapName.ActionName
{
if (controlInput.Gameplay.Sprint.IsPressed())
{
}
}
okay so when i press left shift, the if() will be true right? sorry this may seem really basic but ive been trying this for days and i understood nothing and today i think i might be getting it
you would check this in Update (ok if this function is called in Update)
also just make sure controlInput.Enable() is called in OnEnable or Start or something
would it be fine in Awake()?
sure, but kinda better if you Enable() and Disable() it in OnEnable/OnDisable
why is it better to do that?
in case you disable your script it will stop it from capturing input (wasting resources)
ah alright that makes sense, thank you
ive also been using float horizontal = Input.GetAxisRaw("Horizontal") float vertical = Input.GetAxisRaw("Vertical"); to get my input but now im using a pass through action and a 2d vector, can i some how just easily store the data froom the 2d vector in the horizontal and vertical floats?
Vector2 moveInput = myMoveAction.ReadValue<Vector2>();
oh my god youre amazing thank you so much i actually got it all working
ive been trying literally for a week now and i havent got it working
thank you so much
Somebody save my sanity, there must be a better way!
keys 1-9 will be able to select menu items from my menu system. In the base menu class, I'm setting up the callbacks:
is there a way I can pass a value through with this binding, so that I only need one method; SelectOption, instead of 9 methods...
because I'm about to copy out 9 identical wrapper methods that just pass an int to SelectOption
:V
+= () => SelectOption(n);```
I really need to wrap my head around all the ways you can use deltas, don't I? 😄
pfft haha, just goes to show
this is probably the 5th or 6th time this project that my problem has been not understanding proper lambda use
(thanks!)
ookay next problem. doing this requires SelectOption() to take a callback context parameter
but I'm not sure how to get that
I think that's the problem: Argument type 'lambda expression' is not assignable to parameter type 'System.Action<UnityEngine.InputSystem.InputAction.CallbackContext>'
+= ctx => SelectOption(n);```
or even just:
+= _ => SelectOption(n); since you're ignoring it you can use a discard
more lambda magic! The discard worked, and that's all I need
I thought assigning it that way was wrong because it causes memory leaks or something
All the tuts i see say you need to be able to remove a listener to prevent mem leaks and you cant remove an anonymous method when you use lambdas
it will make it impossible to remove the listener, individually, yes,
THis may or may not be a problem in this person's specific case
It won't be a memory leak though
Ah ok
I wish i knew what was going on in the back end but whenever i try to learn about this stuff in technical documents from ms it just goes over my head
Also for the method that just reads a numbers key in onr of my projectsi just made an action with bindings tied to all number keys and the method extracts which key was pressed
So i only need to assign on method to one actio
Ill post the code when im at my pc
so im trying to assign sprint and roll to the same button (button east) and have put tap interaction on the roll and set the max duration to 0.2 (default). i have put the held interaction on the sprint and set hold time to 0.4. im under the assumption that if i let go of the button in under 0.2 (units im not sure what units) then the roll will play but if i hold it for more than 0.4, the sprint should activate
am i right in this assumption?
the units are seconds
and yes as long as you are looking for the action's performed event
ProcessEventsInDynamicUpdate vs ProcessEventsInFixedUpdate
What is the pros and cons ?
I guess dynamic is being called/checked more often then fixed, as this is relying on your setting on how often fixedupdate gets called / second.
Hi there, I'm trying to get a pinch gesture to work on touch. I'm using this custom composite: (https://forum.unity.com/threads/implementing-pinching.1369809/) trying to make a uniform input action for zooming.
The issue I am having is that the phases of touch #0 and touch #1 always return 'none' (in fact, each touch has all fields at 0/none although other touch reliant behaviours work). I do also enable enhanced touch in an awake function and am quite certain I have the inputs wired up correctly, since my Debug.Log calls do fire at the appropriate locations to make sure code executes that far. If anyone wants to help, I'm happy to post github gists of the relevant code, just wondering if there are any commonly known errors or esoteric knowledge about the numbered touch inputs in the input-system. Any help would be greatly appreciated as I can't seem to find anything in the forums or on stackoverflow either.
Hi everyone, I was wondering if anyone knew how to access the Home button either through the PicoSDK or through the new Input System, I've seen online that there are ways to disable the home button, but not ways to actually run code on it being pressed.
The official docs don't say much in terms of how to access it
https://developer-global.pico-interactive.com/document/unity/input-mapping
And the Input System doesn't have anything for the home button.
What happens if you hit the Listen Button and hit the home button?
I considered this, but I'm not sure how to get the Pico working with the PC in the editor. I've seen that you can do this through steam VR but thought that might be an issue since its not the correct input system
Did you consider the docs about the name? https://developer-global.pico-interactive.com/document/unity/input-mapping
Hmm, I was assuming it would be a controller key, but looking at it in terms of the keycode it may work with KeyCode.Home, I'll look into this, sorry
Thanks btw
If you can't get it working I recommend asking on their support forum. They are pretty responsive
Thanks, I ended up finding a work around actually. I realised that what I wanted did the exact same thing as using OnApplicationFocus(...) when this returned false. Since the Home button takes focus from the game and onto the main menu, this would run first and then go to the menu. ^-^
I think in the future I would want to see if I can access the Home button input action properly but for now this works well xD
Thank you though
It might not be possible to get it after all, since it's a system button that shouldn't be possible to override
Sounds like a good enough workaround
Yeah, I did try using the Home refernce from the keyboard at first since that was the only one that seemed to share the same KeyCode, but didn't seem to work. Though this makes sense since this may refer only to the keyboard one.
i want player to move diagonally on button press - e.g get vector2(1,1) or something like that
or are there any composite part for movement like (north-east) instead of just up down left right
make your own
Vector2 northEast = new Vector2(1, 1).normalized;```
how do i get that value on a button click?
wdym
just define it somewhere it and use it wherever you need it
e.g.
static readonly Vector2 northEast = new Vector2(1, 1).normalized;
void MyButtonHandler() {
Vector2 direction = northEast;
}```
hmm i think there is a miscom
wait
what i want - press q to move composite part or get vector 2(1,1)
if this is from input why are you defining anything like this
so i was wondering if i should write one custom vector2composite
just read the data
Vector2 input = myInputAction.ReadValue<Vector2>();```
or
Vector2 input = myCallbackContext.ReadValue<Vector2>();```
the vector(1,1) / diagonal movement is only possible when you press 2 button at the same time like press w and d you would move north-west
i want to click just one button to get north-west
the composite part [Up] would only give me 0,1 value
this is confusing to me
can you elaborate
how would that work
are you trying to basically "rotate" the whole composite?
So that up would go up-right and left would go up-left?
and down would go down-left, and right down-right?
so when i press wasd i move up, down, right and left
yes
so just do that
Vector2 input = myAction.ReadValue<Vector2>();
input = Quaternion.Euler(0, 0, 45) * input;```
^rotates it by 45 degrees clockwise
the how would i move up and down?
basically wasd for up, down, right and left
qezc for up-left, up-right and so on
press both W and A to move directly up
ik but i want a single button
make a second composite for the diagonals
for touch button
add them together
i don't understand what you mean
how do i do that
following
Then you can just do this:
void Update() {
Vector2 normalInput = moveAction.ReadValue<Vector2>();
Vector2 diagonalInput = diagonalAction.ReadValue<Vector2>();
diagonalInput = Quaternion.Euler(0, 0, 45) * input;
Vector2 finalInput = (normalInput + diagonalInput).normalized;
}```
How do I reference XR inputs in different scripts e.g trigger button or like the select .
when you mean performed do you mean isPressed() or is that something else because I can't get isPressed() to work with both
no I mean performed
either subscribing to the performed event or checking if the current phase of the action or callback context is Performed
can you explain what you mean by subscribing. i think i understand the callback context and i think it uses the notation like -= + etc
yes C# event subscription
the callback context is just the parameter to that delegate
I'm not telling you to switch to that if you're not doing it already. That's just one option.
so far i havent got anywhere with it so im open to any ideas. is there a way i can implement my sprint (holding the button east down) easily into this code just by changing the if. before my sprint used to be a seperate button so isPressed() worked
currentMoveSpeed = sprintSpeed;
anim.SetInteger("condition", 2);
Debug.Log("is sprint / anim2");
}
not if you want to use the Hold interaction
if you want to just know if the button is currently pressed, that works fine
if you want to check if the hold interaction has been satisfied this frame you use https://docs.unity3d.com/Packages/com.unity.inputsystem@1.4/api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasPerformedThisFrame
but you probably want to store isSprinting state in a bool
if (controlInput.Gameplay.Sprint.WasPerformedThisFrame()) {
isSprinting = true;
}
if (controlInput.Gameplay.Sprint.WasReleaseThisFrame()) {
isSprinting = false;
}``` for example
depending on how you want it to behave
ah alright im getting that now
and for tap can i do WasPressedThisFrame() which returns as True only the first time i press the button right?
not if you don't want it to happen if you hold
if you want to actually use the Tap interaction you'd do the same thing as here (just with an action configured to use the Tap interaction). Tap will be performed if you press and release within a certain window of time.
WasPerformedThisFrame()
you can also go event-based 😉
im getting the feeling you want me to use event-based method. would you say its better
I wouldn't say that
It's different
I think you should use whatever you're most comfortable with
alright i think im gonna stick with this then, seems easier to me
im not gonna run into problems later on where by not using the event system ive made something much harder for myself will i?
¯_(ツ)_/¯
yeah sorry that was dumb question. my project different to anything one elses so who knows
if (controlInput.Gameplay.Roll.WasPerformedThisFrame())
{
PlayerRollStart();
}
am i doing this right, i still can't seem to roll/sprint with the same button and i think this is the issue as i roll before i sprint even if im holding
add some debug.Logs and make sure the code is running as expected
okay i managed to do something but now i can sprint but can't roll and i get this error. i presume it means i did something like isPressed() somewhere for an action with a held or tap interaction but i havent done that anywher so im a bit confused
the code by the way is the same i just moved the roll to below the movement
I've never seen that error before lol. What does your code and action look like now?
oh god okay sorry i fixed it, i realised i was adding interactions to only the controller bindings of the action and the keyboard actions didnt have the interactions
but good news is it all works now, i just need to adjust timing so its more snappy
thank you very much though, youre single handly saving my input
I'm having two problems with the new input system
when first starting unity, it picks up a seemingly non-existent controller
but I can remove it from the input debugger
the second is when reloading scripts, it stops getting any kind of input
reloading scripts at runtime?
yeah
no fixes exist?
the fix is use only scripts where every single bit of state is serialized
it's not practical
when you change code, just go out of play mode
its kinda frustrating when I'm debugging a specific piece of code and I have to restart the game every time
well what about the first thing?
no idea
double check there's no stray controllers plugged into your computer
or on bluetooth
no bluetooth, and I only have the keyboard and mouse plugged in
completely sure of that
Hello, how can I separate game input from UI input ? For example, when I click on a button, my script from a totally different game object also recognizes the click
In the new input system you can separate these into different action maps and enable/disable the action maps based on context.
For example while the pause menu is showing you could disable the main game action map and enable the UI one
That would work, but in my case the player can interact with the UI at any moment :/
what's the "other" click handling behavior doing?
You can probably fix whatever it is by migrating that other code to use the event system too, rather than handling the input yourself
moves the player at cursor coordinates
yeah - that can be fixed by doing that with the event system
e.g. IPointerClickHandler / EventTrigger on some object in the game world (like the terrain or ground or whatever)
Okay I'll check that, thanks
This works ! Do you know if the same kind of interface exists with other inputs ?
not sure I follow
could you give an example of another input you mean?
keyboard
but in what context?
The keyboard generally is not associated with a pointer position for example
same as for the click, changing weapons with some keys, so that they are not registered when the user is typing in a text box
but it's not really a problem for now
Hi, I'm just learning to use unity and for some reason my camera keeps going to the top left continuously, I can't control it with the mouse but it still shoots in the FPS microgame. I've tried reloading Unity, disconnecting and reconnecting all my devices, and ive spent nearly an hour looking online for solutions but the only relevent post I could find on the forems seems to be unresolved back from 2019. I havent got any controllers or other devices connected to my pc other than my mouse and keyboard and still no luck.
How can I have 2 PlayerInputs in the same scene without one of them switching to another control scheme?
I have one PlayerInput that I use for general camera control, and I set up another one for specific function in this scene. But when they both exist, one of them switches automatically to controller and one to keyboard + mouse.
is using new input system for "demo" games the right choice? I tried to start my side project on my own and the new input system is starting to make me crazy (I know unity in a level of jr to mid-ish)
Hi, I have a problem with callback context controls/action controls. I have an action with with Negative/Positive composite and when I bind DPad Left/Right to it, it somehow shows dpad left in the action's active control, despite being triggered by dpad right. Dpad right is also marked as pressed in action controls. Am I missing sth?
the new input system is pretty straight forward after the basic tutorial for it. You create an input asset, you create your actions, then you can hook into them with performed += or whatever you need and call your functions. Once done its easy to set up again
Im following a tutorial and I can't find the 2d vector composite
- Change your action to: Action Type : Value, Value Type: Vector2
- It's called Up/Left/Right/Down composite now, which will be visible once you change the action/control type
what do i change in that setting?
oh wait nvm sorry i didn't see you forgot the space
you could also rename the axis to MouseX using that setting though
np
has anyone here successfully setup multiple gamepads with the input manager? the second gamepad will create another instance of the player prefab, but either gamepad will then control both players
Hey yall, This probably isn't the place to ask, but I was recently tasked with installing a new vr game onto a beat saber arcade cabinet. I have the game in unity, but I have no idea how to access the card reader from usb (At least I think it's usb). Does anybody have an idea on how to do so in c#?
I have a boolean that's set to false, but I need to set it to true once someone scans their card
Why can't I jump in unity
First person 3D
I followed a tutorial because I couldnt get it to work
But it still doesnt work
Idk if its just my computer
Could someone please help
you will have missed something in your tutorial / done something improperly,
I'm not able open any .inputasset, anytime I double click it or click the edit asset button, nothing opens. What could be a likely issue
Restart unity, reset the UI layout, maybe readd the Input Asset Tab
how would I readd the input asset tab?
Let me fire up a project with input real quick
What does your inspector looklike when you select the inputactions asset?
And clicking on edit asset? Does nothing?
double clicking on the file and clicking on the edit asset does nothing
Oh wait, is that inside a package?
You are in the package part of project view, right?
You gotta copy that to your Assets Folder for it to be editable
Packages can never be edited, cause they get reset as soon as you update/reimport them
I don't think that's the issue, I get the same thing when I create a new one in the Assets Folder
You could also just try to reinstall the input system package and see if that fixes the issue
The screen is empty btw
I'm embedded a unity client within a WPF application and I'm having issues with, as far as I can tell, Input.GetAxis("Mouse X"/"Mouse Y"). It works fine when not embedded, but does not work when embedded.
Here is part which deals with rotating camera around the object
if (IsCameraRotationAllowed())
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Camera.transform.RotateAround(HeadModel.position,
Camera.transform.up,
Input.GetAxis("Mouse X") * Time.deltaTime * MouseSpeed);
Camera.transform.RotateAround(HeadModel.position,
Camera.transform.right,
-Input.GetAxis("Mouse Y") * Time.deltaTime * MouseSpeed);
}
IsCameraRotationAllowed just checks if the left button is pressed. The cursor's lockstate changes as expected but the camera's transform is not modified
Hello ! is there any way to have more than one .WithCancelingThrough in a rebind operation or should I just cry in my bed for eternity ?
Did you check the docs on this?
var rebind = new RebindingOperation();
// Cancel from keyboard escape key.
rebind
.WithCancelingThrough("<Keyboard>/escape");
// Cancel from any control with "Cancel" usage.
// NOTE: This can be dangerous. The control that the wants to bind to may have the "Cancel"
// usage assigned to it, thus making it impossible for the user to bind to the control.
rebind
.WithCancelingThrough("*/{Cancel}");
Yep but i couldn't modify the inputs in the */{Cancel} in any way
Hey. My input is not performing myaction that ive set up
I press space bar and nothing happens, its supposed to log into my console.
here's the code...
using UnityEngine;
public class PlayerControl : MonoBehaviour
{
private Rigidbody2D player_rb;
public float jump_power = 5f;
// Start is called before the first frame update
void Start()
{
player_rb = GetComponent<Rigidbody2D>();
}
public void Jumping()
{
Debug.Log("Jump!");
}
}
I think i have all the steps made correctly, am i wrong?
This is my first time working with the new input system
Do you even read your inspector ? 😄 Device Lost Event?
Well your character should jump when you detach your device 😄
Ah no thats because i changed a lil format. but the script was not working before hand.. my bad
OH
WAIT
oh
which one should i use? reassigned or changed?
regained it says
nvm i know
.. ithink..
These events are for when a input device gets detected I think. You need to hook into the performed action
This might help you understanding the input system setup 🙂
wait... okay i understand what's wrong.. my Jump action is nit showing in the Events tab
ah... because i didnt press the drop down menu :)))
Not sure where you mean, never worked with the playerinput, always doing the manual coding with input system 😄 But glad you found it 🙂
needed to press that
so this shows
i swear to god its the dumbest things that hold us for the longest times
I totally agree on that 😄 Been there a lot of times. glad you found it 🙂
hi, I'm using the new input system. Is it possible to have multiple gamepads control the same UI?
What I'm trying to do: all gamepads can control the same UI (main menu). Then each gamepad is controlling its UI during character selection.
I am looking for a good tutorial on controlling ui with keyboard and gamepads. If it includes steamdeck then even better
It pretty much works automatically unless you do something to screw it up
Just make sure you select one of the UI elements at first
My ui is more complex than the automatic navigation can handle out the box
Then welcome to the marvelous world of "custom scripts for UI behaviors" :')
You should be able to override the different classes that inherit from Selectable (Button, Toggle, ...) and then override different methods like OnSelect() and FindSelectableOnRight() / Left()
Or making a general state machine script for your UI
is there any good way of telling which index is what action, as i have a Move action that is 0, but now i have a Teleport action, and i can't seem to find what index it is... Is there a way to tell? Or do i just trial and error until success?
this really seems annoying to do via trial and error, perhaps im doing something wrong? ```cs
UnityEngine.Object.FindObjectOfType<PlayerInput>().actionEvents[0].AddListener(ThrowInputs);
UnityEngine.Object.FindObjectOfType<PlayerInput>().actionEvents[1].AddListener(ThrowTeleport);
You could define the listener methods and hook them up through the inspector
im using a SystemBase, so unfortunately i do not believe that to be possible
aha i worked it out, in the inspector you can copy property paths, which then allows you to grab array indexes from the actions yayyy
why i can't add action for specific devices? did i something wrong in video
You need to set the binding of the action
if I want to destroy a game object via touching it do i need the touch position and game object position to match for that to happen or is there another way?
like when u touch the game object's collider with ur finger it gets destroyed
The usual way is doing a raycast from the touch position to find what object was touched
Even better/easier way is use OnMouseDown or IPointerDownHandler
does someone know how to adjust thumbstick dead zone? i changed it in project settings but it doesnt really change anything. im using new input system
In a mod I wrote I'm using InputSystem.DisableDevice() to lock out control to a game so only my UI can be interacted with. Everything functions as expected, however doing it on the mouse [ InputSystem.DisableDevice(Mouse.current) ] after like 5/10 seconds the mouse cursor disappears from my UI, but can still interact with the UI as expected. Is there a better way to block out controls?
Why not just disable the action map?
the typical approach is have one action map for gameplay and one for UI, and you just disable the gameplay one when in a menu
I'll have to do more research on that, not familiar enough with the system - when I looked into this earlier nothing was easily exposed for me to modify without patching in
Action maps are there for this exact reason
Do you have any references for disabling it at runtime? Everything I'm seeing refers to the editor which won't work for me.
myActionMap.Disable();```
going to dig into it a bit more, but I doubt this will work for me - the game dev isn't exposing the action map to anything public and I'm still currently of the opinion a mixin for this would be excessive
mixin?
i don't know the context of what you're talking about jsut saying this is the standard approach
getting an action map reference is quite easy, it just depends on the setup
well idk what you do or don't have access to
never done modding myself
find it hard to believe you wouldn't have access though if you have access to input data
but that all depends on how they've set their game up I suppose
yup - I had to go down this path. Most of it have been explicitly settings the navigation but for more complex parts I had to make custom scripts..
Custom scripts are the fundamentals of using the Input System of Unity 🥲
Well it's an input system not a UI system.
Is there a way for the player input manager when a player joins for it to call a function?
Thanks!
Does it provide the player that it spawned or should i spawn it inside of the function?
Yes it provides the player that spawned
that's why the delegate is Action<PlayerInput>
Do i put it inside the parameter of function eg:
public void PlayerJoin(Action<PlayerInput> action)
{
}```
Sorry about not knowing this
so I have those 2 functions
and these 2 subscriptions
yet only the Jump one works
and the other doesn't
why
The parameter is just PlayerInput
Did you enable the whole thing
Also how are you checking if it's working
And how did you set up the action/bindings
k, i decided because it was easier to switch to c# events which helped me get this. THanks!
Yes I enabled the whole thing
Debug.Log a message in the OnWalk method, and Debug.Log the value of inputhorizontal
sorry for the 3 pings lol
I am sortof sure that it's not the fault of the InputAction since it worked before, the only change I've made is that I made the PlayerInputActions object external from a singleton, instead of within script
the Jump function works and it's set-up in the same way
and _runHeld also works correctly (it's fixed update)
Also the control key works for crouch but S doesn't
for some reason
It worked before as Value
like I said, I only changed the position of the PlayerInputActions variable from being a member to being referenced from a singleton
and I've made sure the execution order runs the InputManager before the other scripts
Update: It appears WASD aren't working, I tried switching the S to an X and the X worked
but changing it back to S stopped it from working
Yep, WASD keys are not working
changed left to z and right to c and crouch to x, all work
what is happening
Seems to be a Unity problem
@austere grotto any idea?
Updated Unity, bug fixed. I hate unity.
Hey, is there a way to save on a JSON file the bindings in a input action asset
and to load them as well?
i have a joystick (logitech attack 3 specifically (does it count as a joystick?) ) and it automatically just worked for the ui, but i cannot get my player movement to work with it... No matter what binding i give my player movement it doesn't seem to do anything... Is there anyway i can work out what binding i need in order to get a vector2 from this joystick?
Using the new Input System package, I am trying to get multiple axis and buttons working on the same action. I thought it would be pretty straightforward, but it doesn't seem to work at all. I'm only testing with a Steam Controller right now, but it seems like for some reason only one of the many buttons/axis I've assigned to the action will actually trigger the action. Any idea what I might be doing wrong?
Pretty sure the north/south/east/west bindings cover all of that stuff. No need to double up like that
Yes. @austere grotto is right. You need to change the action type from button to Value, and after modify the control type, in this case, it is Vector2. After you can add bindings with the type Up/Down/Left/Right, and you can rebind each key in the slots.
Hey, i have multiple errors with rebinding UI, When I click on the button (from the prefab), the rebinding UI is appearing, but the first time I'm pressing a bind, the game freezes, and i have those kind of errors :
I don't really know how to fix it
Hey guys, I am trying to simulate clicks on my UI for my unit tests in unity using the following function:
Camera camera = GameObject.Find(cameraName).GetComponent<Camera>();
Vector3 screenPos = camera.WorldToScreenPoint(uiElement.transform.position);
Set(mouse.position, screenPos);
Click(mouse.leftButton);
Currently, I want to test if the menu changes from the main menu to the settings menu. When I run the test code using this function code(^) it does not simulate the click. I have a few questions:
- Does the InputSystem's
Mousehave a different cartesian layout thanInput.mousePosition? - Does the type of camera (i.e.
OrthographicorPerspective) affect the clicks? Since Perspective was giving me thescreenPosas (0.00, 0.00, 0.00) where as Orthographic was giving me thescreenPosas the position mentioned in the editor...
i am trying to implement a checkpoint system, but when the player respawns at the checkpoint, pressing spacebar reloads the scene
i have no idea what could be causing this as the only script reading input from the spacebar is the playercontroller
fixed, turns out i forgot about my respawn button
If you want to change key-binds at run time , that is done by saving and loading so called BindingOverrides.
There are two extension methods for that purpose.
- UnityEngine.InputSystem.InputActionRebindingExtensions.LoadBindingOverridesFromJson
- UnityEngine.InputSystem.InputActionRebindingExtensions.SaveBindingOverridesAsJson
Question 1:
Is there a way i can see /check which bindings and overrides are actually active? I try to use the InputSystem Rebinding-Example and it does not work.
Question 2:
I'm using an instance of the class whose sourceCode is generated from an InputSystem-Asset. The Unity InputSystem Rebinding-Example however works on the asset. Are those linked to the same instance at runtime or does the C#-Script create a whole different instance?
Edit: Question 2 got answered and the answer is "no, they are not the same, they dont interact with each other and the Unity InputSystem Rebinding-Example does not work with C#-Generated classes" ...oh well.
yeah i got it, but the input system doesn't answer as i need, so it's ok i revert it ^^
Mouse and touch coordinates are in screen space, direct from the OS. I'd recommend looking into creating a custom InputModule dedicated to handling unit tests so you can work a little close to game logic as everything input related will get processed by an input module anyway. That will allow tests to focus on game logic instead of handling input spaces.
how do i better organize this im having issues with the coding rn since i gotta reference each dash action one by one and its getting repetitive and messy
What a channel journey 😄 So what is your issue? How do you reference them right now?
im kind of new to the new input system so heres my code
private void OnEnable()
{
movement = playerInputActions.Player.Movement;
dashUp = playerInputActions.Player.DashUp;
dashDown= playerInputActions.Player.DashDown;
dashLeft = playerInputActions.Player.DashLeft;
dashRight= playerInputActions.Player.DashRight;
movement.Enable();
dashLeft.Enable();
dashRight.Enable();
dashUp.Enable();
dashDown.Enable();
playerInputActions.Player.DashUp =
}
its unfinished
Okay, so you can use the .performed value to know, if some key was hit. Where would you go from there?
no im not asking how to continue the code
is like
i gotta reference dashup dashdown dashleft dashright
is there a better way to do this
Why do you need to reference them?
Just to enable them?
yea
oh
or maybe even playerInputActions.Enable(); not sure 😄
is there any way to sort of group multi tap input actions
You can make Dash a Vector2 and sett the buttons as an Up/Down/Left/Right composite:
problem is i cant make them multi tap if its vector 2
You would need to implement that logic yourself, yeah
But otherwise you can't group them
Hey, i just noticed that using a Gamepad and binding a trigger (Left or Right, with Press and release button interaction), when i release slowly the button stays pressed until i press that button again
Is there any way to avoid this? Is this intended to work like that or an issue?
im using wasReleasedThisFrame to check
Did you double check with another controller? It could also just be the controller outputting wrong values when handled this way. Just to be sure
Hi, I have a script implementing IDragHandler interface, but the OnDrag method is called with the Trigger button of my XR Controller. I don't know why, I'd like to change it for the Grip button. Anyone can help please ?
I am using new input system and XR Toolkit
I need to check that just wanted to make sure if other people got this behavior when released very slowly
it can perfectly be the controller
Ah okay, yeah, I did not experience that issue yet, tho I have not actively tried to replicate it
Im using the visual debugger sample UI and the values seem to be very acurate
im not really sure but i believe its because of the way wasReleasedThisFrame works
is possible that because of the slow input it is not considered "pressed"?
public bool wasReleasedThisFrame => device.wasUpdatedThisFrame && !IsValueConsideredPressed(value) && IsValueConsideredPressed(ReadValueFromPreviousFrame());
Oh, well looking at this, that might be the case
Just realized it is indeed a bug
im tired of these bugs fr
These days, you will not find software without... they just keep too much work on features everywhere 😄 But yeah, so the wasReleased is a bug because of the slow movement?
i think its the opposite (too fast?) im not sure
At least they seem to have some workaround in the forums
yeah it perfectly worked, thanks for the feedback btw
yw even if I did not really do something 😄
The PlayerInputManager class exposes a method to manually join a player but I can't find how to remove one?
playerLeftEvent?
@chrome walrus That's just a callback to notify the player has left
You want to remove the player?
Aye
Cant you just destroy the player? Not sure about it tho
thats maybe why you got a playerleft event but not a leave function, even if I would expect that, but I guess the join functino is just named badly here 😄
Another Q input systems friends,
I'm trying to manually read values from an input actions asset within a certain class. All values read default regardless of whether or not they should, unless there is a PlayerInput class somewhere in the scene. If there is a PlayerInput class, proper values can be read.
Why is this happening?
You need to enable your player input, either by having the component playerinput or by creating yourself a new one at runtime YourPlayerClass newClass = new etc etc. and then newClass.Enable();
@chrome walrus No way to manually listen to input without the PlayerInput class?
As I said, in your script, you create an instance of your class and enable that
@chrome walrus I'm unclear on what you're saying. What is YourPlayerClass supposed to be? Are you proposing I inherit from PlayerInput?
public MyClass : MonoBehaviour
{
public MyInputClassGeneratedByUnity myInput;
void Start(){
myInput = new MyInputClass...();
myInput.Enable();
}
}
@chrome walrus Cool, thanks
Hey! I'm trying to copy state from the controls of an input system-managed device into the state of a custom "virtual" input device. Next, I'm trying to queue the state of the custom device using InputSystem.QueueStateEvent in the OnUpdate method included with IInputUpdateCallbackReceiver. The values displayed in the Input Debugger are unexpected and constant across updates.
Here is a snippet of my code. Both my custom device and the rightHandDevice extend the XRController device type.
CustomXRControllerDeviceState state = new CustomXRControllerDeviceState();
state.triggerPressed = rightHandDevice.GetChildControl<ButtonControl>("triggerPressed");
state.buttonSouth = rightHandDevice.GetChildControl<ButtonControl>("primaryButton");
state.gripPressed = rightHandDevice.GetChildControl<ButtonControl>("gripPressed");
...
InputSystem.QueueStateEvent(this, state);
Documentation is lacking for custom input devices (I've watched the excellent Rene Damm tutorial). Quite stuck - if anyone has experience with this, please let me know. Thank you!
https://i.imgur.com/4d6Tqmh.png why is this giving me a error?
InvalidOperationException: Instance not valid
UnityEngine.InputSystem.InputActionSetupExtensions+BindingSyntax.Erase () (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Actions/InputActionSetupExtensions.cs:1483)
FirstPersonController.Update () (at Assets/Imported Assets/ModularFirstPersonController/FirstPersonController/FirstPersonController.cs:304)
I'd guess it couldn't find that binding?
Ok i'll see what i can change
you'd want to check if the binding accessor is valid before using it probably?
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/api/UnityEngine.InputSystem.InputActionSetupExtensions.BindingSyntax.html#UnityEngine_InputSystem_InputActionSetupExtensions_BindingSyntax_valid
How would i do that?
I just linked you to the property
oh ye i'm lookiong
I'm not seeing anything but boxes telling me that its a InvalidOperationException
I linked the way to check, right here.
Basically i'm saying, that i'm seeing a whole lot of nothing
I'm looking at the doc
I don't understand what you mean then
I'm saying that i dont know what i'm looking at in the doc
that is the property to check if the binding accessor is valid
You are looking at a property, which tells you if the binding accessor is valid
and?
and that is how you check if the binding accessor is valid
ok
if you check that before calling Erase on it for example, you will never get the InvalidOperationException
https://i.imgur.com/gZ3GVz9.png This is what i'm getting inside of this script
this is the code
oh ok
what does this have to do with the earlier question?
It is part of the error
FirstPersonController.cs:304 is the relevant part
okay
So what line of code do i put before erasing the binds?
its just showing declerations
code checking that it's valid by reading this property
so what makes the code not valid?
what makes what code not valid?
it's not the code that is invalid, it's the binding accessor
I'd guess it happens when you try to call "ChangeBinding" with a binding string that does not exist on the Action.
So this isnt what i'm supposed to put?
How can I make the values smoothly go from -1 to 1? Right now it can only have three values: -1, 0, and 1. I want it to quickly lerp between values like the old input system with axis did
Does it have something to do with this?
a key can only be pressed or not be pressed. if you want smoothing with keyboard input, you need to do it codewise
Okay. Thank you for answering my question
📃 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.
Why does this think I'm using the new input system? When I'm not
Are you sure you did not install it? Check your packagemanager
probably something to do with updating AR Foundation.. but there's no package showing
did you check your package json, just to be sure there is no dead entry lying around or so 😄
what action do i subscribe to if i want to call a function on press and hold?
w press --- foo()
--- foo()
--- foo()
--- foo()
w release ---
Old or new input?
new input
nothing in there
Weird. Maybe clean up the project, library folder and reimport after backing up. But I would google, never heard of that happening. 😄 What happens ify ou switch to Input system package in your active input thing?
Does it call you to install the package? Maybe just do that and remove it
Hello, I wanted to see how good the new input system works for touch controls. It is working fine when i swipe left or right, but when i swipe it top/down it is kind of acting wobbly. Can't get my hands on what exactly is this issue. Thought would get my answer here.
this is the code i used for the movement.
[SerializeField] InputAction mousePos;
[SerializeField] float speed = 1;
void OnEnable()
{
mousePos.Enable();
}
void OnDisable()
{
mousePos.Disable();
}
void Update()
{
float xValue = mousePos.ReadValue<Vector2>().x;
float yValue = mousePos.ReadValue<Vector2>().y;
transform.position = new Vector3(xValue * Time.deltaTime * speed + transform.position.x, transform.position.y, yValue * Time.deltaTime * speed + transform.position.z);
}```
and the mouse values i am using.
generally you should not multiply mouse-delta-style inputs by deltaTime
since they're already framerate independent by their nature
alright, removed delta.time, but its not the one causing the issue.
im trying to create a local multiplayer on one kwyboard
keyboard
i gave one object the first action map and another object the otherone but nothing is moving
gave them the maps how?
you'd have to show your code and, if you are using the PlayerInput component, the way you set that up.
ok
wait
in this case this is the player one object and i only put in callback functions under its own event mapping
and leaving the event maping in the other mapping blank
ok and what are you doing in the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public float runSpeed = 40f;
float horizontalMove = 0f;
private bool isJump = false;
private Vector2 Movment = Vector2.zero;
public GameObject bulletPrefab;
public Transform firePoint;
public float bulletForce = 20f;
// Start is called before the first frame update
void Start()
{
}
public void OnMove(InputAction.CallbackContext context)
{
Movment = context.ReadValue<Vector2>();
}
public void onJump(InputAction.CallbackContext context)
{
isJump = context.action.triggered;
}
public void onShoot(InputAction.CallbackContext context)
{
if (context.action.triggered)
{
Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
}
}
// Update is called once per frame
void Update()
{
horizontalMove = Movment.x * runSpeed;
}
private void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, isJump);
}
}
and the CharacterController2D is brackeys charecter controler
btw evrything worked when i intianly set it up for controler and keyboard
add debug.log - make sure OnMove is being called
also using PlayerInput this way is super weird
probably broken because you're trying to use the same device for multiple players
PlayerInput component expects itself to have exclusive access to a single device
Hiya, I've spent ages scouring the web and every time I find a forum where my question is asked there's 0 replies. I've been learning to use Unity's new input system and have been making it so my game can run mouse/keyboard, gamepad, and mobile, for mobile, my joystick controls the character's movement and swiping the screen rotates the third-person camera. The issue I'm having is that anywhere you touch on the screen counts as swipe input, so moving the joystick will also rotate the camera. I've tried using a canvas group to block raycasts but this doesn't seem to affect touchscreen input. Is there a way with the new system to either block touch input or designate a specific area of the screen to allow it?
do the swipe input via the event system rather than just reading touch input directly
So the new input system doesn't have a way to do it?
do what
input system just reads device input
it doesn't know or care about what's happening on screen or in game
that's why would want to do this at the eventsystem level
I see, thanks for confirming that
you should be using Time.deltaTime to lerp your position, not just set it, because that will just give you jittery movement
You mean multiply the x and y values with deltatime?
you are setting your position to Time.deltaTime, which will vary on every frame, cause its the time between frames. So this can be any floating value. You use time.deltatime to have a frame independent value to lerp your position from current to the new position with your speed * Time.deltaTime.
ah, nvm i actually removed delta time. PreatorBlue mentioned the same thing. That wasn't the issue as i mentioned above.
So its still jittery without deltatime?
yup
Can you paste your code again as its now?
[SerializeField] InputAction mousePos;
[SerializeField] float speed = 1;
void OnEnable()
{
mousePos.Enable();
}
void OnDisable()
{
mousePos.Disable();
}
void Update()
{
float xValue = mousePos.ReadValue<Vector2>().x;
float yValue = mousePos.ReadValue<Vector2>().y;
transform.position = new Vector3(xValue * speed + transform.position.x, transform.position.y, yValue * speed + transform.position.z);
}```
Hey, I've been up all morning trying to figure out how to get the touch joystick AND having swipe as a way to rotate the camera working and I've found a scuffed workaround after being completely unable to achieve something that works how I want. Instead I've told the game to ignore inputs in dead zones. The problem at the moment is only the first finger that touches the phone can rotate the camera, and if it touches a dead zone it won't initially rotate the camera, but when a second finger is put down outside of a dead zone, the first one now controls the camera.
Anyone know what I can do to let any number of fingers be eligible for the input, and how to tell it to completely ignore all input from swipes that start in dead zones?
i made a first person core project then when i added player input component to an object, the movement stop working completely , is it becuse theres 2 player inputs?
it was
Im a little confused by the examples Ive found for the new input systemn
Hey guys, is it possible to simulate clicks for testing UI or 3d object picking in unity?
Is there any link to achieve this?
does it make controller left stick have 1 and 0 variables?
i want to make thumbstick have only 1, 0, -1 values so it doesnt make player move slower when thumbstick isn't pulled fully
Give the action a Normalize processor
ok
where
i dont see it
in the move field or xbox controller field?
The action
Move is the action
you can also do it on the xbox binding if you want
either one
hi! i have made player movement with new unity input system and when i pull thumbstick left and right, it works normal, but when i move it to upper left or any thumbstick corner it makes player slow down. does anyone know how to make move script ignore Y axis and only operate with X axis? move script: rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
oh wait
i edited video wrong
wait guys
done
you see? player slows down when i pull thumbstick slightly down or up while still having it on left or right
any ideas why when I first use wsad, arrows wont work. When I use arrows first then wsad wont work? It doesn't print the inputVector
why 3D vector?
Also where and how are you calling GetMovementVector?
you're still only reading two axes
all you have to do is swizzle them to x/z
not use 3D vector
it's a 2D input
where is this running?
in my camera controller script
show the code
since this is in Update it will run every frame
no matter what is happening with the input
so you should get a log output every frame
I am yeah
but why arrows wont work when I first press wasd or vice versa, that's what I didn't understand
show how the action is configured?
I did above
its my first time using the new inputs so I am not sure what the actions are
"Movement" is the action
click that
"WSAD" and "Arrow Keys" are the bindings
No changes I've tried all 3 options
sec
yeah same
setting it to 2d vector fixed the problem but I wonder why it didn't work on 3d
How can I return 1 when I press q and return -1 when I press e? Created an action with action type: value and control type: integer but they both return 1
do I need vector2 again?
Action Type: Value
Control Type: Axis
and create a 1D axis composite
How do I get the current active input asset? I want to get the bindings to show keys to the player in dialogue
Just posting a video wont make anyone trying to help tbh
Checkout the example scene from the package "In-Game Hints"
what registry is that in? I cant find it
Your input system package, in package manager
oh i forgot the samples tab existed my bad
Hey thought I’d share this here
https://twitter.com/prvncher/status/1620516968037244929?s=20&t=_C88z-9u8fVsOVFkvm3p9g
Pro tip if you're using XR with the new Unity input system, Input System 1.5 adds a new hotpath that super optimizes input reads. You just have to make this call once in your code.
"InputSystem.settings.SetInternalFeatureFlag("USE_OPTIMIZED_CONTROLS", true);"
I felt like it was easier to explain that way
Alright who has the best tutorial on the new input system. I want to switch over to the dark side.
So If I select Button North Gamepad as a binding and I don't specifically add Y-Xbox controller binding, will the xbox controller not work ?
Just starting with this new input system and I don’t see how to do this:
I have an InputActionAsset in which I'm trying to create a composite Action for “CameraControl”, the value I want to get out is a 2D vector.
I’ve got it working fine with WASD and the 4 arrow keys, but I also wanted to give the user the option to use the mouse scroll-wheel for forwards/backwards, and just do left/right using keys.
Things I’ve tried:
The controls it allows me to select for each of the composite binding elements are ONLY buttons, it won’t let me select the mouse scroll wheel. (Which makes sense- it’s looking for a single bit for each of the elements; UP and DOWN)
It also won’t me select the scroll wheel when it’s NOT a composite binding (which also makes sense as in this case it’s looking for a 2-d input, not the axis input the scroll wheel provides)
I’ve been able to create 1-D (axis) ACTION that allow me to select the mouse scroll wheel as the control- but it doesn’t look like I can make THAT action, provide input to uh.. “some” of my CameraControl action’s bindings.
How can I implement this?
^ solved: solution- TYPE in the path to the mouse scroll wheel
Problem:
I'm assigning context.ReadValue<Vector2>().x to a global _horizontalMovement variable
I use a teleport ability that resets _horizontalMovement back to 0 and the controls are locked until the player stops teleporting.
The input system doesn't detect any changes from the controller because its still on -1 or 1 (which the player should start moving after teleport is over)
How do I force an update to the Movement action so it continues to read that the player has the joystick in a movement position?
The only way to regain movement is to move the joystick from whatever position it was at before teleport started which is horrible player experience.
I figured out to loop through the player input's actions array looking for my movement event name and force update my player's _horizontalMovement to that of the ReadValue and it works.
what is the best approach to have some button in my canvas to simulate inputs, is the best solution to implement my android controller?
whats the difference between tap and press
How do you switch back to the old input system ?
remove the package , change your player settings to old input system which is under configuration > Active Input Handling, then change your code back to the old ways.
when my player dies they get deactivated which also deactivates the player input and prevents me from pausing the game
also the player is a prefab so i cant just separate the input into another object
Make a second action map that deals with the UI ? Add that to a different object ?
ive tried that but it doesnt work
it disables the inputs on the other player input controller
is that not intentional?
No that's right. It is still on the same .inputactions asset. Maybe create another .inputactions asset that is for UI ? If not that, try a different route of achieving what you want and not setting your player's object to disabled?
making another input action doesnt work either
i kinda have to i cant really work around it
If you make another input actions asset and you dont disable that object, it should still work. The one attached to your player object would become inactive
I beg to differ on this. There is always a way.
that would be a really nice solution but it doesnt work, for some reason the second player input takes priority over the input thats on the player
so you cant move as long as the other player input is active
ig i could try disabling it while the other player input is active
that seems extremely unnecessary why cant 2 player inputs just work at the same time
Well I got it working on mine just now
you have multiple player inputs in the same scene??
how do you have your inputs set up?
im just using sendmessages and not doing anything with generate c# class
my behavior is Invoke Unity Events. I find it a lot easier. But that shouldn't have anything to do with the object being active or not
Honestly I can't tell what you are really doing since I cant see your hierarchy
i have a player input on the pause menu gameobject
then im spawning a player as a prefab and they have another player input on them
And you have assigned different inputactions asset to them both?
ive tried different inputactions and different maps
the one on the pause menu always takes priority and just prevents the other one from working
the other player input just doesnt read any inputs
how did you manage to get yours to work?
Do you see this when running 2 in the scene ?
After I disabled my character, I pressed the start button on my gamepad and that is what's firing, which is firing from the UIInput object
my player is instantiated so ill try assigning the UI module with code
My question is though, Why cant you just lock the player ability controls and hide the model from the view during game pause ? Instead of SetActive(false)
the player has a lot of stuff on him and just due to the nature of how my game works i need to keep the player on the scene
it doesnt work
it seems like once a player input is in the scene it takes priority over anything even after its been disabled
im just gonna try some weird janky workaround
ok well now i have another problem
im trying to switch to unity events
but this doesnt show up on the list?
is it because of the inputvalue
public void FirePaintGun(InputAction.CallbackContext context)
expand events > player and assign via script
for move you would do
public void Movement(InputAction.CallbackContext context)
{
if (GetControlsLock()) return;
PlayerController.Instance.MovePlayer(context.ReadValue<Vector2>().x);
}
ah
thank you
my janky solution kinda works now but i just have one more problem
is there a way to assign functions to an event at runtime
not sure on that one but I feel like the functions you need to subscribe to should also live on the prefab if it has to do with the player
i made an empty gameobject and placed it in the player prefab and told it to basically disconnect itself from the prefab when it spawns
I use a PlayerInputManager class that deals with all the events, then i just dispatch out where i need to go
so all i have to do now is assign stuff like pausing to it
huh
how does that work
Also I feel like you could've nested your player object in a container object and have the input component on the container if you were going be deactivating your player itself so then the input system still works. But I don't have a clue exactly what you are doing.
basically the player spawns with a controller object and that object loses its parent when spawned
so it remains in the scene
I do something like this. All my player abilities have their own script and a single instance of them that live on the player object so I can always call on them when needed via their instance. This also will allow to swap out abilities to buttons using player prefs or something.
https://pastebin.com/S5dTWHnD
So on the Player Input component I only ever add the PlayerInputManager script to reference
how does input manager work?
ive tried using it but theres almost no documentation about it
No lol, thats a custom script I created
Hello can you help me in my code because i'm making game like flappy bird and my sprite (player) don't fall down and don't move up when space pressed
pls help me FAST!
its my school project
@everyone
For some reason, setting VSync to the highest level under Quality completely eliminated input lag. Why is it like this?
Setting it to 1 or 0 causes a relatively huge (around 500 milliseconds) of delay even though the game is running at 60fps
its Update, not update. Also input.touch, if in the editor, only works when you have simulator window as your game window. Also, no need in multiplying by delta twice before assigning direction
I'm using the new unity input system and Im trying to create a local multiplayer but when referencing the PlayerInput through the script it uses the same one for every charcter so when I jump all the players jump is their a way to change this?
You should be using PlayerInputManager which will create a separate PlayerInput (and player prefab) for each player
I did but when assigning this in script it controls all the players playerControls = new PlayerInputActions();
Because you're not using PlayerInput if you're doing that
You are using your generated C# class
Use PlayerInput instead
if I use playerinput instead how would i go about assigning things through a script than like this line for example playerControls.Player.Jump.triggered?
By reading the article
quickly before I read It will this allow me to use if statements or will it all have to be done through events?
How would I go about using 2 joycons as a single controller in unity
my functions aren't being called when I press the keys related to each action, any idea why?
Looks like it should be working at glance. Checkout Code Monkey video on new Input System. Might find what you are missing.
yeah I did exactly the same steps as I did in my other project and it works there 
could it have something to do with the player being a prefab
I didn't have problems trying this approach from just following the video. It's when instantiating class you get additional gotchas of having it enabled properly.
I... did the exact same things 🥲
I found out the issue is with the control scheme thingy
it was an oversight on my part
do we really need to use update in order to check if user holding a button in new input system? like to check if holding shift then sprint. Not talking about the hold .5 sec to fire an event
Update is one option.
Event based handling is another
How do you do it with events? I subscribed both performed and cancelled. Created a bool to check if holding and set true if performed, set false if cancelled in update
Yep by subscribing to performed and canceled and setting a bool
still we have to use update then
If you want to do something every frame you have to use update. This is unrelated to the input system
But what are you actually doing in Update
placing tiles while holding left button
Is there a reason you expect to see pipes?
What are pipes in this context?
What do pipes have to do with #🖱️┃input-system
to add onto the question earlier, how does holding one button continuously work, is there not an option when setting the action in the input manager? do I have to do it with a subscription and a book or can it be done from the inspector too
You either use events for start/cancel or you poll it in Update
ah could I use smth like button pressing down/release for start/cancel? @austere grotto
Working on converting my project to use the input system. I have the UI stuff on Canvas working fine. But I also have a custom map upon which I use the mouse-posiiton to determine which “map-tile” the mouse is over- this is custom code, not event based, (though it does generate its own events).
I have the following code in that MouseOverMapTile monobehavior:
InputAction moseOverAction => inputActions.FindAction("MouseOver");
InputAction selectAction => inputActions.FindAction("Select");
Vector2 mousePos => moseOverAction.ReadValue<Vector2>();
HexIndex2D previousMouseOver;
HexIndex2D mouseDownOver;
void Update()
{
Debug.Log("mousePos: " + mousePos);
…stuff…
}
In the inspector I dragged my configured InputActionAsset (see pic) onto the public field above. The problem is that the debug log output ALWAYS show the mouse position as (0,0)- no mater where I move the mouse.
What am I doing wrong?
I'm trying to add playercontrols for ps4 controller for a 2D-project with this piece of code:
float moveVertical = Input.GetAxis("Vertical");
float moveHorizontal = Input.GetAxis("Horizontal");
transform.Translate(new Vector3(moveHorizontal, moveVertical, 0) * moveSpeed * Time.deltaTime);
I'm still using the old input manager and for a reason, my vertical movement doesn't work. only horizontal. If I'm setting the y-axis to x-axis for "Vertical", then it moves both right and up (but not directly up.)
Could someone help me with it? Idk what could be the problem
nevermind found the answer (god I'm awful at searching- sorry): solution: inputActions.FindActionMap("TacticalMapActions").Enable();
for 2D on the XY plane this look ok. But if your 2d plane is XZ, then you'd probably want to feed moveVertical into the Z coordinate of the Vector3. Which plane are you using?
I'm using x and y
hmmm, then it LOOKs ok to me.. what do you mean by " If I'm setting the y-axis to x-axis for "Vertical", then it moves both right and up (but not directly up.)" was that just a test?
also what do you get if you Debug.Log(" horiz: " + moveHorizontal ); does it ever have a non-zero value?
I mean this
if I set the axis from Vertical to X-axis instead of Y-axis, then it moves both to x and y axis
simply said, if vertical is y-axis, then the player only moves like the left side of the drawing.
If the vertical is x-axis, then the player moves like on the right side of the drawing.
It seems like it doesn't repond when it's set to y axis
ok, THAT makes sense: the diagonal direction is simply due to the fact that your using the same value for the X and Y components of the Vector3 you use in translate. What do you get for the Debug.log, I suggested above (when vertical is set to you Y-axis).
afk fam
hold on
(the problem is in the vertical axis, so I changed it for horizon: to vertical:)
I only get the 0 value. It seems to not respond on the y axis.
hmmm, lets confirm it's not a hardware issue. Add some keyboard inputs for vertical (one for positive, one for negative) and see if THOSE give non-zero output in the debug log. If they DO, I'd start to wonder if there is a problem with the controller.
Can you test that controller some other way? does it work when playing (not-your) games?
yeah, I play other games with it too. it reacts normal
hmmm, I don't have any other ideas other than the sanity-check of testing this on a new project.
(to confirm nothing else in the project is messing this up ... somehow)
Hmm, I'll test it.
oh! doubt this is it.. but do you have the same "dead" value for vertical and horiz (in input manager)
ok, was a shot in the dark. Could TRY setting it to zero, but doubt that'll do it.
no, doesn't work indeed
thnx for your help. I'll try later with another controller. If that still doesn't work, then I'll change it to the new input system
ah, you did everything you could. It's prob smt with my settings or controller
alr. have a good day!
Quick Question, what is CallbackContext duration supposed to represent, I thought that it represented the time between performed and cancel, but it seems to always be 0? Am I not including some setting to have it keep track of that time?
deltaTime between start and current, e.g. duration a button was held down (given the control is a hold type action)
There is little documentation on that, i generally expected it to be the time between start pressing and cancelling which is very useful.
Make sure your action is not a momentary one if you expect the value to be non-zero
any idea why MoveLeft gets called twice whenever I press the button?
MoveRight behaves just fine
NVM
I can't understand why it doesn't work. It worked, but when I something changed it stopped working((. I can't find it
What is "it" that does not work?
What are you expecting to happen?
What is happening instead?
I want to make something like this:
- When I Enter my cursor to UI Object it a little bit opens
- When I Exit my cursor from UI Object it closes
I wrote a code and it worked. However, I changed something. And I can't find it for 2 hours
does anyone know why im not given the option to select 2d axis for the type
It's only for Value action types
ah so movement will be value rather than button right?
yes
alright thanks a lot
hi there
does anybody know how to handle multiple action maps with player input at one?
Specifically, I have an action map for controlling the camera from an isometric perspective and one action map for doing so with a drone type perspective (free roam)
both are driven through one playerinput instance, which gets its action map changed depending on the mode the camera is in
now. how do I handle global actions with playerinput (like pausing the game) without having to add the action to all action maps?
Create a third action map
leave that one always enabled
Id have to enable it manually somewhere right?
don't use SwitchCurrentActionMap, you can control the maps individually as you wish
through myPlayerInput.actions.GetActionMap("actionMapName")
should that work well with control schemes? I'm trying to differentiate between MKB and controllers
Hi guys, I am loading my InputActionAsset into my InteractionSystem through Resources.Load - This of course allows the InputActions in the project to be dragged into any inspector fields.
I also want to enable the use of code to access those same InputActions, for example: InteractionSystem.PCGamepad.heldItem.primaryAction
However, it seems to be impossible to have the code reference the same InputActionAsset as the one loaded through Resources.Load, because PCGamepad myPCGamepadInputActionAsset = new(); Creates a new instance of the InputActionAsset in memory
and myPCGamepadInputActionAsset.asset = theResourcesLoadedOne; is not possible because .asset is read-only.
My Interaction system is managing the enabled state of all the maps throughout the state of the game.
Does this mean that if I intend to support both editor drag and drop and code access to InputActions, I need to hold two InputActionAssets in memory and keep them both in sync inside my InteractionSystem?
Is there any way to create a code accessor (InteractionSystem.PCGamepad.heldItem.primaryAction) to the asset loaded by Resources.Load?
How do i add new things or edit existing ones in input system
what kind of "things"?
Yeah but i saw that there is already some basic inputs
like "jump"
how do i access them
That's only in the old input system
And you just set those up through Edit -> Project Settings -> Input Manager
if you're a beginner stick with the old one for now
Why?
it's simpler
Any thoughts on my question? Many thanks if you can help
I'm not sure I understand this line:
myPCGamepadInputActionAsset.asset = theResourcesLoadedOne;```
I thought myPCGamepadInputActionAsset is already an InputActionAsset
why does it have a .asset field
oh it's the autogenerated class right? That's a bit different from the InputActionsAsset you're loading from Resources.Load
it's a wrapper
It's not an IAA, it's the c# class generated by one
But I'm not sure I see why you would want to use the loaded one if you're using the autogenerated one
Yeah the wrapper
Because the resources.Load one is the one I can drag references to into inspectors
I understand that if I load that into my interaction system and start enabling and disabling maps, the asset in the generated c# isn't the same thing, therefor the management of maps is out of sync between the two
Yeah I'm not sure you'll get away with mixing and matching like this
Also look into InputActionReference if you haven't
Yeah I've used that a lot in places. I wish I could do some kind of input action asset reference.
Shame it's one way of working or the other, not both raw code and inspector references.
you can just drag and drop an entire InputActionAsset as well
but no you won't get the wrapper like that
I'm actually kinda curious
is there a constructor for the wrapper that takes an asset?
Yeah :/ I guess my only solution to support both is have the interaction system hold on to them both and keep them in sync.
Sadly not
The generated code makes it all readonly in a partial class, I even tried writing my own supporting partial that would allow it, but no luck.
i just hopped in Unity, is using the input system good on performance when it goes into multiplayer networks?
what do "multiplayer networks" and input system performance have to do with one another?
(nothing)
sorry, i meant if the input system does not have problems when it comes to multiplayer games
im trying to learn the engine and im seeing stuff that i havent seen like 6 years ago
Here's a mad one, anyone know where the code is that generates the C# classes for the InputActionAssets?
- I want to add my own custom public constructors
How can I ReadValue<float> from a button type action?
I'm guessing you want context.ReadValueAsButton() == true ? 1.0f : 0.0f; ?
Yes! Thanks
Doesn't seem to work
No option for ...AsButton
only AsObject
one sec...
Can I do ReadValue<bool>() ? 1 : 0;?
mayyyybe I think that's an odd one and is why ReadValueAsButton exists
What is your HandBrake type?
Here my context is an InputAction
In full for my example (It's a debug UI showing the values of various InputActions
Thank you. I will try reading the value as a float
I'm running 1.4.4
Might be why. Anyway ReadValue<bool>() didn't work
ReadValue<float> worked though
0 if not pressed, 1 if pressed
Thank you for sharing your script
Brill 🙂 no worries, glad it helped