#🖱️┃input-system
1 messages · Page 32 of 1
Use the event system for all your touch interactions instead of handling them manually like this and you'll get this behavior for free
Do you mean the events on the objects themselves? That won't work for me sadly, since I need raw input data to determine things like the exact type of swipe performed or how long the object was pressed for etc
Not necessarily, you could put the event handlers on a big invisible UI image behind your main UI
And all of those things could be handled with the pointer and drag events
Yea I suppose that would solve my issue but is this really the best solution here? Sounds clunky as hell
Also, how's multitouch handled in this solution?
is multitouch a requirement?
Like pinch or something. Would I be able to detect it?
I mean it'd be nice to be able to add it someday
And not lock myself out architecturally
it can be done this way, but multitouch is best handled with the enhanced touch API. It definitely complicates things.
I don't mind using it, but point stands - how do I filter out ui touches
Either via input system, or via touch api
I've never really thought about it with multitouch and it can get really complicated.
For example if you're doing a pinch zoom and your fingers start outisde of UI but at some point during the zoom your fingers go over UI, what do you expect to happen?
Is there a convenient way to detect if a touch clicked on some ui element? Take a screen position and do a IsRaycastableUIAtThisPosition
Or what if one finger is on UI and one not
The most exhuastive way is to manually do a Raycast from the GraphicRaycaster or the EventSystem and check if any ui elements were hit
the cheapo way is EventSystem.IsPointerOverGameObject but that's not going to cover your multitouch use cases well either
That definitely won't work
But this might?
yeah that cheapo way also doesn't work if you use the event system for anything other than UI
Where can I read more about this? I always did just normal raycasts
How do I do a ui-specific raycast
Neat, I'll take a look, if this is fine performance wise I might use this
Thanks
Hopefully doing it a few times a frame is fine
Hello. I am development a game for mobile, but when I play in Play mode in Unity, the game runs good. But when I make the build for android. The game goes slowly and the movements are not the same that in Unity… what have I to do?
Hi, i can try to help u.
U can start by sending the movement code and maybe a video showing the difference between mobile and pc controls
I will try my best to help
Is there a way to navigate title screen buttons with keyboard and mouse ?
yes
you can navigate with a mouse or with a keyboard
After the scary email today, when anyone updated their version of Unity, did you have issues of inputs no longer working? Because that is my current issue
which version did you update from/to?
2022.3.17 i think. to the 2022.3.62
I wonder if the scripting define symbol is missing? Should I have one called like INPUT_SYSTEM or something?
which input system setup are you using?
Check your input system settings
new input system. i have them both enabled though. all my settings seem to be the same as before the update
I tried quitting unity and reopening. inputs still aren't working
have you tried the input debugger?
yeah. inputs work in the debugger
I'm also using the PlayerInput component if that matters
then it's probably something like a control schemes issue
And/Or - you have more than one PlayerInput in the scene
it wouldn't be that, because it worked this morning before doing the Unity Version update. SO something broke during/after updating the Unity version to one of the new patches
i'm manually updating the input system just to see if that 'wakes it up' or something (i see there is an update available)
YAY! updating the insput system fixed it!
The issue I am having is I have to click on the button in order for the game to register the keyboard. I would like to know how I can make this immediate? I have set it so that when the keys are selected they change to red. I also have the inspector set up like this for the event system.
Here's a video demo of my issue. I have to actually click on the buttons for it to allow me to move up and down with the w,s and up and down arrow keys.
I could really use the help im not too familiar with how to set this up properly
Yes. Sure. Thanks in advance. I will send you in private message as soon as possible. Thanks again
You just need to call SetSelectedGameObject in Start for example
Do someone know that why car is moving in horizontal rotation?:
PlayerControls.cs:
https://paste.mod.gg/ahzseznpjlyd/0
VehicleControls.cs:
https://paste.mod.gg/zlpzqwjqheec/0
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
But PlayerControls.cs works fine for character. Its only happening to car
I already have it set in my script but still have the issue i described
I have to click on the button first before I can move with my keyboard and mouse I would like it to do so without me having to use my mouse to register the keyboard?
I see that you are also making a 2d game, I have been doing 3d for some time. I just started learning 2d, for some reason there is something wrong with my input system or the code I wrote, can you please help me out. ❤️
You are using the old system not the new system
please don't ping random people for help
!input
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.
Hello, I have two scenes with one being my main scene and one being a minigame scene that I wanted to load using LoadSceneMode.Additive. The two scenes have PlayerInputs in them with different action map and I'm having trouble understanding how do I manage this system. Do I only keep one player input and have the minigame subscribe to it's action map events and then switch it ?
Here are the two player inputs with their Unity Events
Yes you should only have one playerinput if you must use the playerinput component
You can initialize it in a bootstrapping scene.
But if this game is not local multiplayer you can use another workflow
I see thank you ! I'll just subscribe with the Fishing Pole minigame then
hi
i think its a input problem
not about the input system itself but...
i made a custom joystick (its old i made it like 5 years ago i think)
its not the first time i use it so i know its not the issue here,
for the games i made it, i was using either third person or 2d directly so i never have this problem.
im taking on a new project with some things on going and one of the things that was pissing me off its the character moving very off from the previous joystick...
i switched to my then i realized that i get a new problem
the game is 2.5D and the movement are calculated in a more raw way
so the problem is.
i need to change my input from x(-1,1) y(-1,1) (circle since its normalized) to a eliptical shape
how can i calculate it?
Explains how to perform two different types of projections of a point onto an ellipse.
- If you would like to support me to make these videos, you can join the Channel Membership, by hitting the "Join" button below the video, and making a contribution to support the cost of a coffee a month. It would be very much appreciated. Or by clicking he...
tks
Though to be honest I'm not sure I understand why you need this
Hi guys, I didn't have this channel on my list for some reason, but I'm having an issue (explained here: #💻┃code-beginner message and i'd love some experienced brains to take a gander. TIA
Yep as I asked in the other channel can you share your code and how you set it up?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
https://paste.mod.gg/xtcmnocztjja/0 I think thats all the relevant scripts. I initialize the game, which sets the windows/ pause state etc. when pause is pressed it fires off an event, pause manager switches states, ui panels turn on and off based on state
A tool for sharing your source code with the world!
The PlayerInput component makes its own unique copy of the actions asset.
Enabling or disabling action maps on that copy is not going to have any effect on the InputActionReferences
Because they refer to the original asset
If you did for example pauseAction.action.actionMap then you'd get the map that InputAction is a part of
oh... that's, confusing lol. Thanks, I appreciate you taking a look. I'll go check the documentation again, I must have misunderstood unity's tutorial video.
there was a distortion when the input as been transfering the vector2 (hud joystick) to the player (on 2.5d) i thought it as the distortion of the 2.5d was messing of the right direction...
actually it was the projection...
i was using the camera (right and forward) to point the direction... but the camera itself was inclinetad... so thats is the source of the shit.
bcs the camera was inclinated, the forward and backward was "retuning 1 or -1" when translating to the player movement but something around 0.7 or -0.7.
so insted of moving and rotating in a circle... it was moving and rotating on a eliptical shape... and i was trying to correct it
(since now i know what was happening i already solved it, but tks anyway)
I am building some menu based controls, and I want to know there preferred design pattern. Do you make one click handler for everything and route based on the button name (fewer files but more messy), or one click handler class per button (tons of files, but each has only one purpose)?
Sounds like a #📲┃ui-ux question
Is there a way to fix that I can't press buttons made with OnGUI whenever vr is on?
Hey! Is it possible to make a static Player Input Manager class with the new input system or does it have to be a MonoBehaviour?
Please ping me if you respond
You can use the generated C# class from your input asset
https://nohello.net , just open with your question
(you can tack those things to the end if you want)
i have a problem with the editor input read (i think thats it at last)
so i have 2 scripts that derivates from the same script for my input system (a mobile script (for touch and custom joystick) and a pc script (for axis and mouse click))
currently im using the old input system in the script (im used to the old one)
(for the settup of the project im using both input systems)
today i was testing responsivity of the screen and i realized that the pc script stops reading the axis when i swith the game view from game to simulator
you are most likely just reading Input.mousePosition without enabling touch simulation
Set Input.simulateMouseWithTouches to true or use Input.touches[] instead of mousePosition
i removed my check for the device type in the scrips and in my player settings for mobile are all set to both input system handles
my problem is not with the touch
the mobile simulation is working fine
the problem is my normal/pc stops working
even if i force the pc read
So it works on a device but not in the simulator tab?
Yes, then please read the text again
im explaning it badly
you are now getting touches instead of mousePositions
if i switch this
the engine base inputs (get axis ("horizontal")-get axis("vertical")-get button("custom")) stops working
you usually trigger them by pressing WASD?
yep
can you show the code where you read them?
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
oh
this is good
!code
using UnityEditor;
using UnityEngine;
public class PC_PlayerController : PlayerControlManager
{
void Start()
{
print("PC ON");
//if (SystemInfo.deviceType == DeviceType.Desktop)
//{
PlayerScript.player.input = this; //forces as main input
//}
}
void Update()
{
movementDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized;
print("pc"+movementDirection);//no update //displaying x0.y0
isInteracting = Input.GetButtonDown("Fire1") || Input.GetButton("Fire1");
cameraRotationDirection = new Vector2(Input.mousePositionDelta.x, Input.mousePositionDelta.y) * cameraRotationMultiply;
AddZoom(Input.mouseScrollDelta.y);
}
public override void Callback()
{
return;//faz nada
}
}
There's no command called
code using.
wait
dump question, have you clicked into the simulator once before trying wasd? sometimes it doesnt properly get focus
use
```cs
CODE
```
i didnt have clicked before,
but today i was making a screen fit check... spended some time then i got that what is breaking the input
Hi everyone, I’m not sure if this is the right place to ask, but I’m trying to create a settings section in my GUI where the player can choose their keybinds. I’m using the new Unity Input System and I’m not really sure how to do it. Could someone help me, or maybe point me to a good tutorial?
Third video is from Unity themselves - hope these help sorry I'm not expert on the topic yet.
Tyvm
that kind of thing you should just google to start yourself tbh
yeah those were the first 3 videos type shi
i did but i couldn't find anything
"unity rebind controls" was what I searched for 👍
maybe "unity allow player to change button mapping" is more specific prompt
they didn't pop up to me, idk why, tyvm
"unity input system rebind menu" gives plenty of results
you generally don't want/need sentences in keyword searches
my YouTube stopped recommending crappy Unity channels lol 🤷♂️
Input Manager. What will a key or pad button return?
I know a Vector2 binding will return Vector2, but a key? A bool, or something else?
EDIT: The exception said, it's a "float" - but could I have known in advance?
buttoncontrol is a subclass of axiscontrol, all buttons give floats
but you could also check ispressed to get a bool, respecting the pressPoint setting for analog hardware
also, that's not the inputmanager - that's the old system, your screenshot (and this channel) are of the new system, inputsystem
I was mixing things up in my head then. I meant the new input system.
Though... my button press detection suffers from bouncing.
I get them from the input system (from active action map) with:
pauseInputVal = inputActionPause.ReadValue<float>();
if(1f == pauseInputVal) // Button presssed?
{
toggglePause();
}
Using ESC or a controller "start" button shows clear bouncing, toggling my pause screen on and off unreliably.
Is there a better way to avoid picking up physical button bouncing?
that's not bouncing, you're toggling the pause menu every frame the button is pressed
use WasPressedThisFrame for the check (and if you do need to check if it's currently pressed, use IsPressed instead of the == 1f check)
Uh. I have a state variable... just using it wrongly. Ouch. Ty.
you generally won't be using ReadValue if you want to treat an input as a button, use these 2 (or the other WasXThisFrame methods) instead
Works like a charm. +1 Karma.
New input system is so nice with being able to seamlessly support a controller and KB/M.
Hey, i have a system which shows in UI, some keybinds hints like "[E] Interact", and when I rebind my key, (if the hint is disabled, next time it'll show up and show the correct keybind. However, if the player is close to the point where the hint is displayed, if he just rebind while he's standing in front of the hint, the hint won't be updated unless the player go away and go back to the "hint point".
I tried to do some event in the RebindActionUI class, however this event can't be subscribe from a script from my namespace, so it doesn't work at all
Does anyone know a solution ?
Nevermind i found a solution to refresh all UI enabled when menu is closing, it's very easier
How can I check to see if I have a controller connected? Please ping me as soon as possible
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerInputManager : MonoBehaviour
{
public InputActions InputActions { get; private set; }
public bool HasController { get; private set; }
public static PlayerInputManager Create() => new GameObject("[Player Input Manager]").AddComponent<PlayerInputManager>();
private void Awake()
{
DontDestroyOnLoad(gameObject);
InputActions = new InputActions();
InputActions.Player.Enable();
InputActions.UI.Enable();
InputSystem.onDeviceChange += HandleDeviceChange;
}
private void HandleDeviceChange(InputDevice device, InputDeviceChange deviceChange)
{
if (deviceChange == InputDeviceChange.Added || deviceChange == InputDeviceChange.Enabled | deviceChange == InputDeviceChange.Reconnected)
{
HasController = true;
}
else if (deviceChange == InputDeviceChange.Disconnected || deviceChange == InputDeviceChange.Disabled ||
deviceChange == InputDeviceChange.Removed)
{
HasController = false;
}
print(HasController);
}
}
I want to migrate fully to the New Input System in my solitaire game
the problem is when I want to use it for UI and GameObjects and both of those are enabled, it just doesn't detect interactions for GameObjects
public class Card : MonoBehaviour, IPointerDownHandler, IPointerEnterHandler {
// ...
private void OnMouseDown()
{
// OLD LOGIC with old Input system
Debug.Log("OnMouseDown {name}");
// Create stack if suitable
if (!Revealed || !Slot.IsStackable(this) || Manager.DisabledInteractions) return;
Slot.OnStackGrab(this);
// _stack = Slot.OnStackGrab(this);
}
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log($"OnPointerDown! {name}");
}
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log($"OnPointerEnter! {name}");
}
}
once I disable UIDocument with overlaying GUI, it detects those interactions with GameObjects
how to set this input system and ui toolkit that it would let those events pass through the ui layer
Can someone help me translate this code to Unity 6? Just upgraded my project and struggling to find the updated way to do this:
nothing has changed with this in Unity 6, you just copied it wrong. Event.current is incorrect
double check wherever you're copying this from
Oops, the image I sent was an attempt to fix this issue, This is the code Im using and it says "The name 'EventSystem' does not exist in the current context." And yes I do have "using UnityEngine.EventSystem" at the top of my file
using UnityEngine.EventSystem is not correct either
using UnityEngine.EventSystems;
save the script and check the unity console
this may just be a case of your IDE not being synced properly
what errors if any are in the Unity Console
Ah you're probably right about that. There's been a few of those already. Crap that makes me realize a lot of the "fixes" i've been making this morning might be breaking my project more. Better fix the ide. Thank you
yup, when I updated the project, my editor in the project preferrences was no longer set to VS Code. I regenerated project files and then CTRL + Z'd the last 3 hours of nonsense (
) and we are functioning in Unity 6. Thanks again @austere grotto
is there any way to get a generated c# input action class to use the project wide asset instead of instantiating a new asset from json?
Currently no not without modifying the generated C# manually.
I've been asking for this feature for a long time: https://discussions.unity.com/t/feedback-allow-input-system-generated-c-class-to-use-an-existing-input-actions-asset-instance/1524850
ah, that's a bummer
i wanna make my player jump shorter on light tap but i still jump in same jumpForce
anyone knows solution?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
you're only lowering the force when you're still on the ground
if you put 3 little tick marks ` it makes ur code
easier to read
ohhh
just put 3 on either side of the entire message
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 6f;
public float jumpForce = 6.5f;
Rigidbody2D rb;
float moveX;
public Transform groundCheck;
public LayerMask groundLayer;
public Vector2 groundCheckSize = new Vector2(0.5f, 0.05f);
void Start()
{
rb=GetComponent<Rigidbody2D>();
}
void Update()
{
rb.linearVelocity=new Vector2(moveX * moveSpeed , rb.linearVelocity.y);
}
public void Move(InputAction.CallbackContext context)
{
moveX = context.ReadValue<Vector2>().x;
}
public void Jump(InputAction.CallbackContext context) {
if(isGrounded()) {
if (context.performed)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
}
else if (context.canceled)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, rb.linearVelocity.y * 0.5f);
}
}
}
private bool isGrounded()
{
if (Physics2D.OverlapBox(groundCheck.position, groundCheckSize, 0, groundLayer)) {
return true;
}
return false;
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.darkRed;
Gizmos.DrawWireCube(groundCheck.position,groundCheckSize);
}
}``` im trying to do variable jump height mechanic i need help
thank you i didnt know that :D
much better thank you
i dont really know how to fix ur issue sorry but that'll make others more likely to help you
you´d need some kind of time based function, keypress and keyrelease to determine how long the key has been down, after keyrelease you can perform your jump and multiply with that small timer
Hi please help me understand what all of the ForceMode things are for
im not sure which one to use for regular movement and jumping
i tried ForceMode.Force for movement but my player isn't moving
here the docs have descriptions for them https://docs.unity3d.com/6000.2/Documentation/ScriptReference/ForceMode.html
if they dont move at all its not because of the forcemode, can u share ur code
ok
i agree, it has to be something else.
Doing Physics like this needfs to be done in FixedUpdate
whats that
it's the place to do physics
If you do physics in Update your game will play differently at different framerates
ohh okay
as for why your object is not moving it could be all kinds of things
start by showing the inspector of the object in question
probaly using the new input system but using code for the old input
ohh shoot thats probably the issue
i changed it but sometimes it goes back to the new input system
let me check rq
you should have many warning and errors in the console though
nope it isnt that
it just says the field Movement.force is nevr used
as a warning
if you are planning to use with WASD you should consider making use of Horizontal and Vertical axis instead
wdym
we should focus on the "why isn't the object moving" part before changing other things
Show us the inspector please
true sry
which part like the whole thign?
the whole inspector of the object this script is attached to
even better would be the whole uncropped unity window with that showing, tbh
and when you run the game, make sure the console window is open
can you run the game with the console window open and you pressing the W key, and show a screenshot of that?
Can you go to Edit -> Project Settings -> Physics
and show what's set there
Ok now Project Settings -> Time
And Project Settings -> Physics/Settings
Also are there any other scripts in the scene?
Can you try changing rb.AddForce(Vector3.forward * 2, ForceMode.Force); to rb.AddForce(Vector3.forward * 2000, ForceMode.Force);?
ok
Oh also make sure you've actually saved your code changes
right - so now, move your Update code into FixedUpdate and put force instead of 2000, then you can modify it in the inspector
you probably also want it to be float force not int force so you can have decimals
hi i have another problem im not sure how to make a good jump mechanic where it has the momentum from moving and also jumps
if i try to make a simple jump mechanic it starts moving in the air
and doesnt come down
if(jumped == false)
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded())
{
rb.AddForce(Vector3.up*100, ForceMode.Impulse);
jumped = true;
}
}
if (jumped && rb.position.y>=5)
{
jumped = false;
}
public bool isGrounded()
{
return rb.linearVelocity.y < .01f; //if its 0 or almost 0 then its true
}
this grounded check doesn't make sense
you will have a negative y velocity any time you are falling.
i.e. any part of the second half of the jump
but when it touches the floor the y velocity would be 0 right
probably not. Have you checked? YOu should be debugging.
so it is 0 when its on the ground
wait ohh but if its falling it would be negative
What if you're running up or down a hill?
so the isGrounded check would go off even if its falling
Basically checking the y velocity is not a good proxy for a ground check
so what about position
nope. You can have ground at any position presumably
unless your game design specifically precludes that
yeah im trying to make a platformer
so it will have some floors in the air
is there like a collide function or whatever
to check if it collides with cubes
Most people use physics queries to detect the ground
ooh whats that
huuhh
oh wait i can just check if the velocity is exactly 0
if its grounded it wont slightly move
YESS it works
this is also true at the very top of the parabolic arc
It will work 99% of the time though
but it won't work if your player can run up or down slopes
no it wont run up slopes atleast not for this one
ok now i just have to fix my actual jumping
hi im wondering something
so for isGrounded() im trying to use physics.raycast to check if it hits the floor but the problem is im not sure what the maxDistance should be
is there a way of finding it out
or should i just tinker with the numbers
it should be the distance from the point you are originating the rraycast at to where you would want the ground to be for the player to be considered "on the ground"
for example if you start the raycast from the center of your player, and your player is 2 units tall, then you would expect the ground to be about 1 unit away from the center of the player when he's standing on the ground, right? So you would do a raycast of maybe 1.05 units long, to add a little padding
it all depends on from where you originate the raycast and how far that is from your player's feet
ohhh
so if i want it grounded then i would start the raycast at the bottom
so like .5
.05
for padding purposes
wait no
ohh i understand
so basically for demonstrations sake it shoots a beam down from the player
and then it checks if it encounters something in that distance
if it doesnt encountr anything then its airborne
otherwise its grounded
yes
yess :DDD my jump works
only issue is like if i move while jumping it goes wayy farther than it would without jumping
Hey guys got a question. Please ping me as soon as possible but with the new input action, are you able to use it with Player pref settings to say, invert the Y axis of the look, increase/decrease sensitivity, etc? And what I mean by this is strictly set the processors to the player pref settings, or am I going to have to hard code them in??
You’ll still have to code any user-facing settings.
Okay so I can't use processors for this sort of thing
They are programmable, it seems. So it's possible. But honestly that just adds an extra layer of complexity since you're still going to have to store it across sessions.
Okay so I should just use my own values, thanks
Hi gyus, i have a little problem
I implemented the key rebinding system with the new input system and it works perfectly, i have only one problem, when i change a keybind and close the game, when i open the game the keybinds in the settings pnael shows the default keybind and not the one the user chose
do someone knows why?
btw i used this tutorial to implement it:
https://youtu.be/qXbjyzBlduY
Ty in advancee to anyone! 🙂
I'm not familiar with that particular tutorial but the general idea is that you need to save the rebinding data somewhere, e.g. a file, and load it back when you reload the game
Presumably the tutorial doesn't cover that part, so you'll have to write it yourself
maybe tomorrow i'll give it a try ty
I have an Xbox Wireless Controller paired through Bluetooth right? So how do I access it within Unity?
Gamepad.all does not show any results
I've tried various Input wrappers including OpenXR and it just doesn't show up.
The Input System doesn't even see the GamePad (Xbox Controller)
Holdup the YXBA buttons work.. but not the joysticks
I think InputAction.ReadValue<T> is broken on Android because the PlayerInput Component works but not my other code.
Nope, for some reason the gamepad is disabled while my vr controllers are active.
Great job unity or meta
hi i have another problem
so my jumping and moving works pretty well
only thing is that theres a bit of momentum
like it keeps moving even after I let go
how do i stop that from happening
I have a setup in Unity where, in the main menu, devices are connected and for each device a GameObject is created with a PlayerInput component, which is bound to that device. The problem is that when I load a level, there is already a character with a PlayerInput component, and it can no longer be controlled because the device is only bound to the GameObject created in the menu. What is the best way to handle this?
Make your PlayerInput objects survive across scenes.
Or destroy them and recreate them in the second scene
It's 1:1 PlayerInput to human
Often it's best to just have a "stub" object with the PI and use some glue code to modularly connect it to stuff as needed such as menu controls, player characters, etc
Thank you for the fast reply. I made the objects to survive across scenes. Is there any way to switch the user of the persistent PI to a PI already existing in the scene?
You don't want to have two
Each PI is tied to a human
If you're going to have persistent ones from a bootstrap scene, don't spawn new ones in the new scene
You could/should use PlayerInputManager to spawn them BTW
got a question on the Input Actions Editor.
or rather an issue
the action properties panel is broken
interactions and processors dont pop up when i add them
i sent something on some discussions.unity.com but those are kinda slow and discord has always been faster for me
Im in the action editor,
action type: button.
Interactions is blank right now
but in trying to add a 'hold' interaction
i click the plus, click 'hold' when it appears
but nothing appears.
the dull message saying 'no interactions has been added' disappears, but nothing appears in its place
my teacher has said something about it bieng some 'NullReferenceException' though he couldnt help much because he isn't experienced with this new input system
and i have no clue whats relevant or whats happening because i am not a programmer, but just some design student brute forcing the programming with tutorials from youtube.
Any help would be greatly appreciated 🙏
could you show a screenshot or screen recording, perhaps? just to see what's going on
should i include my error messages too? because there are a small handful which i dont understand
that's very crucial info, yes
these are the errors
so seems like it did create the interaction, since the "no interactions" thing disappeared. the errors seem to suggest that it's having trouble drawing the interactions.
save the asset, and then try restarting the editor
if that doesn't work then try a library reset
no dice
library reset...?
is that deleting the library file and letting unity do its own thing?
close the project, delete the Library folder, and then reopen the project
it'll take longer to open since it has to rebuild the library
o7
that didnt fix anything unfortunately
also sorry if i reply late, im trying to finish a different assignment task atm @_@
got the same error when checking the location...
@toxic lintel how can i add a 2d vector composite in Unity's input system?
https://duckduckgo.com/?q=how+can+i+add+a+2d+vector+composite+in+Unity's+input+system
The medium link has a detailed guide
DuckDuckGo. Privacy, Simplified.
that tells me to add up/down composite
i don't have that either
So you're not seeing the option?
are these old features? i updated Unity a few mins ago
yeah
Composites are definitely still there, but the UI may have changed.
This is what i see
I can't find the 2d vector composite, nor the up/down composite
Add binding, then set action type to "value" then set control type to Vector2.
Hello everyone, I'm new here and I came to ask a question!
I'm trying to find a way to transform an action on a UI button to a UI navigation event
On the left is a list of buttons (all UI) and the circle will be "selection wheel"
Basically, I want to be able to "scroll" that wheel and it triggers a Nivigation event on the button list, going up and down
Right now I have it setup and it works, but I'm not using the navigation and if I want to put another "menu" on the screen it will not work, so I want to make it "universal" to all my menus and navigate on this black screen
I have the new input system on, and I say there's a mapping for the UI navigation. Basically I want that my "OnScroll" event on the wheel translates to a "Up" or "Down" of the UI inpout mapping
Right now this is how it's setup
The wheel:
Hi guys, I'm trying to save the input the user chose so that the ui can be also updated, but i'm having some problems in importing the namespace, do someone knows why?
i imported the samples
iirc they're in their own asmdef, so this might not work?
you should treat the examples as examples though, not modules
adapt the code into your own work, don't use them in your actual project
oh, ok ty
trying to adapt the code i'm having some problems, when i copy and paste the code in a new script and then put it in the GameObject in the Inspector the variables looks different, in particular Binding ID/Binding, do u happen to know why?
or if i can solve in another way
the sample components have custom property drawers iirc
you could copy that, but when i went through the samples to make my own rebinding UI, i copied mostly just the logic and handled the linking myself
but i don't understand why Binding in the sample script is a dropdown and in the adapted script it's a string, like the samples convert the ids?
the custom property drawer does that
okk ty
Hello, do you know why i have this yellow msg ?
it's a warning that using the default input actions asset as the asset for a PlayerInput is not intended
it's not usually an issue
i should create a new one to not have this message right?
no
you could just.. unassign the default input actions asset
or the alternative would be not using PlayerInput
you don't need to create a new one just to avoid the message
Its a bit weird no? to have this msg cuz you are using default, but thanks for answer i'll just go throught
I'm having a problem, so when i click to rebind a key only one of the rebinding buttons actually check for duplicates bindings (i have a function for that), it worked before adapting the script to my project so i could save the keybinds, but i don't understand why now it doesn't work
Ty to anyone in advance 🙂
this is my ActionMap
nvm, i fixed it
Is anyone else seeing repeated input events being fired in the editor recently?
I suspect that these are no longer being cleared when exiting play mode.
I'm a bit puzzled on how to clear these
do you have domain reload disabled?
Yep.
there's your issue
you have to clear these yourself if you don't have the domain reload doing it
I'm trying that but Dispose doesn't work and I can't clear a lambda.
I'm aware, yes 😄
couldn't you action.started = null;?
ah wait it's an event isn't it
Yeah it's an event
Because it's 30 input mappings
or make a reference for it
sooo more reason to make it into a method, to reduce repetition?
your lambdas are all the same
it'd need 1 method
oh shoot, it's a closure
Yeah, both mapping and context are different
Context, of course, we can pass. But not mapping
Currently experimenting with storing the lambdas
Right. This did the trick;
Action<InputAction.CallbackContext> callback = context => Invoke(mapping, context);
_callbacks.Add(callback);
action.performed += callback;
action.started += callback;
action.canceled += callback;
Weird how this started with .58f2
How to handle PlayerInput the right way?
Im spawning it during game scene and destroy on main scene loading
am i supposed to spawn PlayerInput in main menu scene and keep it DontDestroyOnLoad?
What is the right approach?
I always keep it loaded, so yeah. That'll do.
Generally you should keep it instantiated while the current game mode that uses it needs it, whether you do that via DDOL or a custom system-scene is up to you
You can also opt to not use it at all.
Appreciate it 🤘
Hello. For the game Battleops, what file contains the touch screen sensitivity configuration?
Sounds like a question for the developer of Battleops
We're not just mobile game publishers; we're collaborators in the extraordinary. Seeking a passionate partner for gaming greatness? you've just found us.
Noted. Thank you
for mac os and unity 2022.3.8, how would you enable XRI RightHand Interactions for XR simlator? XRI RightHand Locomotion seem to be working though
nvm
is there any issue with having one key do the same thing like this?
before rebinding and such theyr all set to the same binding
essentially doing the same action 3 different times?
is there any performance issue with this or smth
so i wanted to ask if nothing bad will come from having one input system on an object that is destroyed than that input system being transferred to anther obj (I have an egg that once destroyed will give you a playable character with the egg and player having an input system attached to them) the problem is when the egg is destroyed and the player is spawned I cant move the player at all.
I mean technically everything you do costs performance but this isn't going to be noticeable
It is a little unclear to me why you need 3 actions though
If by "input system" you mean the PlayerInput component yes it's not good.
It's better to have a single, persistent, PlayerInput component per human player
having multiple different rebinds that do one thing
like jumping with scroll wheel or space bar
you can do that with a single action
than how can I make my egg hatch without the input system because I need to click it to start the hatching process
Have a third, persistent object that is always there and always active handle the input
oh ok i think i get what you mean thanks for the help imma try to that now
how do i do that
you can have as many bindings on a single action as you want
so this is what you told me to do right put it all on one central empty object right or am i being stupid because once the egg hatched my player still cant move
Note that PerformInteractiveRebinding has a parameter for the bindingIndexhttps://docs.unity.cn/Packages/com.unity.inputsystem%401.1/api/UnityEngine.InputSystem.InputActionRebindingExtensions.html#UnityEngine_InputSystem_InputActionRebindingExtensions_PerformInteractiveRebinding_UnityEngine_InputSystem_InputAction_System_Int32_
how did you hook your code up to the PlayerInput component?
I see you're using Invoke Unity Events but your vidfeo has the Events thing collapsed
oh thanks
ig i didnt need this
lmao
you can also do inputActionAsset["Movement/Forward"] as a shortcut
i think im hooking it up normally right because i can still move in my other scene
public void OnMoveLR(InputAction.CallbackContext context)
{
horizontalMovement = context.ReadValue<Vector2>();
if (GetComponent<SpriteRenderer>().flipX)
{
rb.linearVelocity = new Vector2(-horizontalMovement.x * moveSpeed, rb.linearVelocity.y);
}
else
{
rb.linearVelocity = new Vector2(horizontalMovement.x * moveSpeed, rb.linearVelocity.y);
}
isSwiming = true;
}```
cool
but I don't see the Player object in the scene in your earlier screenshot. You said you're instantiating it. So you'd have to glue the PlayerInput event to it at runtime somehow.
Really what I meant with the persistent object was to have a script which serves as glue between the input handling and your other objects like the egg and the player
oh ok i have them all in different scripts so should i just make one script that handles all of the player input
i have my movement script and my player hatch script that handle different inputs
its still not working should i just use both the old and new input handlers so movement is done with the new and the egg hatch is done with the old
Are there benefits to using external input packages, i.e InControl, over the input system? For me, it's the ease of code
I found AnyKey in the input actions Keyboard bindings.. but I'm also hunting for an equivilent for GamePad.. but i can't seem to find that
if its even possible.. any suggestions?
the only thing I know to do is use the .current
private bool AnyInputPressed()
{
// Keyboard
bool keyboard = Keyboard.current != null && Keyboard.current.anyKey.wasPressedThisFrame;
// Gamepad
bool gamepad = Gamepad.current != null &&
Gamepad.current.allControls.Any(c => c is ButtonControl b && b.isPressed);
// Mouse
bool mouse = Mouse.current != null &&
(Mouse.current.leftButton.wasPressedThisFrame ||
Mouse.current.rightButton.wasPressedThisFrame ||
Mouse.current.middleButton.wasPressedThisFrame);
return keyboard || gamepad || mouse;
}```
nevermind.. since i really dont understand Linq i've redone it in a for loop
var controls = Gamepad.current.allControls;
for (int i = 0; i < controls.Count; i++)
{
if (controls[i] is ButtonControl button && button.wasPressedThisFrame)
{
gamepadLoop = true;
break;
}
}``` it'll work for now
I'm using the new input system for mouse "OnLook", it does work when i play on "Maxmized" screen but not on focused! any idea?
you would have to share details of your setup, your code, etc
and what you mean by "working" and "not working"
mouse rotation works + left click "fire" works. on focused screen mouse input doesnt do anything.
public void OnLook(InputAction.CallbackContext ctx)
{
lookInput = ctx.ReadValue<Vector2>();
if (ctx.performed) Debug.Log($"Look: {lookInput}");
}```
not even logging on focused mode. the mouse input doesnt seem to work at all
Hi! I'm having an issue with the new input system when I try to control the button up (released) state.
"InputActionPhase.Canceled" is supposed to tell when the button is released, but it is triggered too if any other button is pressed.
Anyone knows if this is a bug or if I should setup the inputaction mappings any different?
i believe thats when it applies to Composites.. if its a composite pressing another button of the same composite can cancel the current action..
its per-control.. instead of per-action..
ie. multiple bindings on the same action can cause one press to cancel another.
im still at teh very infancy of my input-system education.. so i can't suggest solutions... but maybe the 2-cents above helps out a little 🍀
ohh also check ur cursor's state.. Cursor.lockState = CursorLockMode.Locked;
if its locked or something it may not get its delta's
I'm not sure what you mean about composites. The use case is: I hold "Y" button on the gamepad and it keeps pressed until I press any other button or direction on the gamepad and the Y button phase changes to Cancelled
composite inputs is a single Input Action but its made up of multiple controls..
like combining multiple buttons or axes into one logical input
for example WASD keys -> Move vector would be a solid example Unity treats it as one action but internally watches four seperate keys..
each control in a composite can start/stop the action independently
pressing one key may cancel the previous key's contribution..
im testing right now.. tho to confirm my suspicions.. (im still very much learning so i wouldn't take my advice completely to heart.. instead take it w/ a grain of salt..)
i think theres a way to log which button/ input triggers the Performed and Cancelled callbacks
just for more context can you show the full script (use external paste-bin website)
and a screenshot of that particular action in ur inputactionmap
using UnityEngine;
using UnityEngine.InputSystem;
public class MinimalInputTest : MonoBehaviour
{
void Update()
{
if (Mouse.current == null) return;
Vector2 delta = Mouse.current.delta.ReadValue();
if (delta.sqrMagnitude > 0.1f)
{
Debug.Log("Mouse Delta: " + delta);
}
}
}
brand new project
ohh wait.. i totally mixed up two different issues
chan's message right after yours seemed almost identical to me
haha i can see why now
you need to click onto the window for it to be captured / become focused
does the issue still persist even after clicking on it?
im on 6000.0.60.. im not sure if that really matters... unless it does and its a bug.. but imma test real quick once my project finishes loading up.. (its blank for the most part) so imma just test w/ a maximized and minimized game window for ya and just report back my findings) 👍
tyvm, i will update as well on my 6.0
@distant raptorsame problem on 6.0
is it just the mouseDelta?
you have the correct Input Handling selected correct?
oh wait a moment i accdiently recreated 6.2 project 😬
one of them mornings for me too
interesting..
does it work for you?
i think i found a fix, no idea what was it like that
yes..
- first half of clip (maximized window) -> works automatically like you had mentioned
- second half of clip (minimzed/docked window) -> works after clicking onto it to grab focus
i went to Input Debugger
when testing I always click onto the Game window before expecting any of my inputs to work correctly..
but it always does.
and found this while Play was active
yes i do as well, still no luck with that
hmm ^ mine doesn't say anything about it being Disabled..
now you know what you could use to research further..
thats the difference between ur test and mine
yep, i can enable it and it does work tho
do u have that device simulator touchscreen as well?
nope thats the difference i noticed too
your mouse is Device ID 3.. mine is 2
soo its possible thats the culprit.. can't say for sure tho
yea i assume it take it as the default and this is why the mouse doesnt respond
When the Device Simulator or a touchscreen is enabled, Unity may disable other pointer devices to avoid conflicting input.
does it tell how to disable it? cz when i "Play" it always returns
maybe in the PlayerInput / actionmap thingy?
im not sure in honesty..
im learning as i go 😅
i deleted the playerinput just to be sure
thats another thing i was going to mention.. is making sure you had the correct components in the scene.. im not 💯 what those are tho
usually the EventSystem is related in some way or fashion
ahh nevermind.. quick search says that stuff is more about the UI driven stuff (buttons, sliders, etc)
shouldn't interfere
well, finally I came to a very dirty solution to keep track if a button is pressed, no matter if any other buttons are being pressed or released:
Gamepad.current.buttonNorth.ReadValue();
Will return 1 if the button is pressed and 0 if not. I would have extected context.ReadValue<int>() to return the same value, but it doesn't
shouldn't it be ReadValue<float>()?
context.ReadValueAsButton() is what you want. It returns a bool
"it should be ReadValue<float>" and return >0.5 if pressed, but it returns 0 too
context.ReadValueAsButton() also returns false while the button is still pressed.
I believe Unity is pre-processing something between the raw button push, which is captured directly from the gamepad, and the callback. Sadly I can't find in the Unity's doc what is causing this behaviour.
I'm planning to create a prototype, where I can switch between a RC car, drone and a regular character. How do I architect the whole Input system.
Obviously I plan to use the newinput system with the generated class.
you can make separate action maps for each object you can control
Obviously
But how do I decentralise all the movement logic for entities and communicate with something like a central manager?
Do you have any interactions or processors on the input action?
Exactly like that. Make the instance of the generated script owned by some central manager and have it expose the input object as a property for individual scripts to be able to interact with.
You mean the central manager exposing functions like move(), jump() etc?
this immediately makes me think you probably need a state machine, with each state being the different characters you can control
Nope
Just exposing the generated class instance
The generated class already exposes all the actions etc. no need to duplicate that
Can you share more about your setup? What workflow are you using?
Or we could just make the generated class a singleton and get its reference wherever needed? Wouldn't this be more simple @austere grotto ? Why just create a manager class just to expose the reference of the generated class.
Did you suggest the creation of Manager class as it is preferred to not modify the generated class?
What do you mean by "make the generated class a singleton"? What would be creating and managing that singleton? If you mean modifying the generated class yes that's a bad idea, because every time you make any change to the input action asset the generated code will be overwritten.
got it. Thanks!
It's pretty basic setup. Just the input actions system action I sent above, and a "Invoke Unity Events" Behaviour on the Player Input component. The code is pretty basic too:
public void GrabAction(CallbackContext context)
{
//TODO: find another aproach to this!!
float buttonNorthValue = Gamepad.current.buttonNorth.ReadValue();if (context.phase == UnityEngine.InputSystem.InputActionPhase.Started) { grab = true; } if (context.phase == UnityEngine.InputSystem.InputActionPhase.Canceled && buttonNorthValue == 0) { grab = false; }}
well you just make an input action with the space, c and j bindings
and subcribe to its performed event
input.action["jump"] isnt a boolean apperantly
InputSystem.actions["Jump"]?
nevermind i figured it out, i needed to have it read the value .ReadValue<>()
yeah
How can I do GetKeyDown/KeyUp with the new input system?
you can subscribe to the performed or cancelled events of the input action
Thanks
Check the action phase for started/canceled
Or use WasPressedThisFrame and WasReleasedThisFrame
InvalidOperationException: Cannot read value of type 'Single' from composite 'UnityEngine.InputSystem.Composites.Vector2Composite' bound to action
Did i convert this wrong?
ughhh the new stuff is so confusing
is Move a composite, perhaps?
if so, you'd read a Vector2 from it
your move action is a Vector2 (2-dimensional) input, but you're trying to read a single number from it
I see now, thats waht I did the first time but it was giving me an error but i just found out you can do .ReadValue<Vector2>().x/y
thanks for the help
🤦♂️ 😆
⭐ hello, can anyone help with Layout Overrides, specifically how to access Gyroscope/Accelerometer of a Gamepad?
Just being able to see everything the Gamepad reports would be fine too. (SwitchProControllerHID)
I've looked into previous posts here, and online, but I can't seem to get any data coming in. But the Layout Override works fine (see image)
the new input system feels like hell
It's pretty straightforward for most things. No?
bro when i download unity 6 and ddidn't knwo about the new input system i almost broke t he pc 💀
For sure yeah not knowing how to use it can lead to some issues
actually i feel like learninG THE NEW INPUT SYSTEM I AM GONNA TRY
not working
there is no working toturial
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(CharacterController))]
public class Player : MonoBehaviour
{
private InputAction _move_Action, _jump_Action;
private CharacterController _characterController;
[Header("Movement Settings")]
public float moveSpeed = 5f;
public float jumpHeight = 2f;
public float gravity = -9.81f;
private Vector3 velocity;
private bool isGrounded;
private void Awake()
{
_move_Action = InputSystem.actions.FindAction("Move");
_jump_Action = InputSystem.actions.FindAction("Jump");
_jump_Action.performed += Jump;
_characterController = GetComponent<CharacterController>();
}
private void Jump(InputAction.CallbackContext context)
{
if (isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
}
private void Update()
{
// Check if grounded
isGrounded = _characterController.isGrounded;
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f; // Small downward force to keep grounded
}
// Movement
Vector2 moveVector = _move_Action.ReadValue<Vector2>();
Vector3 move = transform.right * moveVector.x + transform.forward * moveVector.y;
_characterController.Move(move * moveSpeed * Time.deltaTime);
// Apply gravity
velocity.y += gravity * Time.deltaTime;
_characterController.Move(velocity * Time.deltaTime);
}
}
no way that is not complicated
Nice use of [Header], that’s cool. And well, that’s like the bare minimum right there. I don’t even see any animator related stuff etc, it gets more complicated 
Remember that with configuration stuff like gravity jump height etc, scriptable objects can be great. For 2 main reasons - being able to save/duplicate/etc an entire config, easily switch at runtime, and changes stay after Play mode exits.
A cool motion matching asset called MxM uses that “scriptable object config” 
oh thx
I’d give this a read asap too
https://gameprogrammingpatterns.com/state.html
and object pooling next if you want to work with projectiles / “creating” and “deleting” game objects at runtime in general - Unity has a built in one
tysm
it isn't, you're kinda using it twice
you have a PlayerInput set to SendMessages - an event-based approach, but you aren't actually receiving any messages and you're polling one of the actions and attaching events to another
so you're combining 3 approaches here
that's more complex than it should be
is pinch zooming on smartphones has direct component that can read it and utilize it directly? like on-screen stick or on-screen button
i had an UI like this, that bunch of button is within a grid layout
what i want , is being able to zoom in on that part
or i still need to read input and calculate the value and use it myself
ok i think im making progress now
gestures (like pinch) are not something you can do with InputSystem alone, modifiers won't get you there. you need to implement the gesture from multiple pointer inputs yourself. Or use Fingers (asset) https://assetstore.unity.com/packages/tools/input-management/fingers-touch-gestures-for-unity-41076
ty, i think i will try to implement the gesture myself first
public static float ZoomAction(this InputManager manager)
{
if (Touch.activeTouches.Count < 2)
{
return 0; //single input , ignore
}
Touch touch0 = Touch.activeTouches[0];
Touch touch1 = Touch.activeTouches[1];
if (touch0.phase != TouchPhase.Moved && touch1.phase != TouchPhase.Moved)
{
return 0;
}
if (touch0.history.Count < 1 || touch1.history.Count < 1)
{
return 0;
}
return Mathf.Clamp(Vector2.Distance(touch0.screenPosition, touch1.screenPosition) - Vector2.Distance(touch0.history[0].screenPosition, touch1.history[0].screenPosition), -1, 1);
}```
i used enhanced touch to make my own pinch gesture
private void Update()
{
float ZoomInputValue = InputManager.Instance.ZoomAction();
BatchPlanMap.enabled = ZoomInputValue == 0;
if (ZoomInputValue < 0)
{
Debug.Log("shrink");
}
else if (ZoomInputValue > 0)
{
Debug.Log("zoom");
}
}```
and i let any UI that need to listen the gesture to call and listen the function
BatchPlanMap is a scroll rect , because pinching two finger actions might have conflicts with dragging/moving grid layout , that will cause glitches
so , if pinching action is detected, disable the scroll rect to remove conflicts
if pinching is not detected, enable the scroll rect
it works tho, not that performant i think?
Hello, I'm new to Unity and I'm trying to make a rhythm-based action mechanic like the one in Crypt of the NecroDancer, but I don't know how to use the Input system or how I should use it for such a mechanic
I recommend you read the workflows page on the input system docs - helped me understand it better than any of the countless tutorials I watched about it on youtube
Thanks
I barely understand anything 💀
you are not alone, the input system documentation is terrible at giving you a good idea how it is supposed to work. Some of the recommendations in it are terrible (particularly the recommendation to use the singleton accessor + Find("ActionName")*). And nobody knows why they are maintained. Regardless it is a system worth learning. But nobody can give you a recipe for how to use it that allows you to skip understanding its many options to use it competently.
*).Find() should be replaced by serialized InputActionReference fields.
InputActionReference is my preferred way to go
you neatly assign references to the actions you need
my way is to have a dedicated manager to store the asset reference
i know enhanced supports cant be used with input action on same behavior
i just make sure theyre not conflicting
This FindAction stuff?! Can you not reference actions in the Inspector at least instead of grabbing them by string in code? I suppose you could serialize the strings but still bad...
you can reference them in the inspector, you just need to serialize an InputActionReference and then access its action property
But can I bind it to an action in my input settings?
yeah, if you serialize an InputActionReference instead of an InputAction you can give it an action from the input actions asset
ah OK nice
Is the documentation wrong about mouse input - InputSystem.Mouse.current.leftButton.isPressed - Mouse is not present
that should work
actually, i think you need either UnityEngine.InputSystem.Mouse.(...) or just Mouse if you have the using statement
InputSystem.Mouse is not a thing
Mouse exists in the UnityEngine.InputSystem namespace, so as cookie said
InputSystem is also a class in that same namespace
OK thanks - its just the docs showing the namespace in the statement when should start Mouse... I think that is bad docs really
Also from microsoft: DO NOT use the same name for a namespace and a type in that namespace.
what docs are you referring to?
ah, yep, that's definitely wrong in the docs
It was a poor decision to add a class with same name as namespace, but is there other docs?
Keyboard and Gamepad have the same issue
yeah, I shall report!
Gamepad is also capitalized incorrectly, goddamn
Do touch devices emulate mouse input by default in new system? There seems no option in new API
Vector2 lookInput = inputSystemActions.Player.Look.ReadValue<Vector2>();
Is giving me a huge value during the start and rotating my camera to a random rotation. But other than that it's fine.
I've tried flushing the input on the first frame, but it still starts with pointing to a random rotation on the start.
i think that's an editor only thing, it happens when you press on play and then move your mouse back to the viewport
yes
if you start playing using a hotkey instead does that still happen
I'll try that
It does not happen, if I start play with a hotkey, It works fine.
Tnx
anybody handle both mouse and touch and combine them into 1 down/move/up type mapped system? It would seem annoying to setup separate systems for basic mouse-first games. You can simulate touch but seems both ways not just touch to mouse which maybe is fine though not sure what happens behind scenes
was it really needed to have .current for things like a keyboard? Could they not have had Keyboard.commaKey.wasPressedThisFrame which would return false if no keyboard?!
If you just do:
Keyboard K => Keyboard.current;```
Then you could simply do `K.commaKey...`
well technically current can be null though
But for typing's sake I am using a function now - hopefully compiles down!
so what should Keyboard.commaKey be if there's no keyboard?
whatever the answer, it doesn't really extend to analog inputs for mouse/gamepad and it also duplicates a ton of members
(also, what praetor suggested is also technically a function)
Is there something like sensitivity, gravity, snap for actions in new system?
Check out Processors
No gravity one at the moment though
Yeah I made a custom processor now for sensitivity and snap as per the old one, but can not handle gravity as no callback if no input!
Hi everyone my name is Ming I'm new here
hi, this is not a social space https://nohello.net
if you have a question, feel free to ask
please do not advertise here #📖┃code-of-conduct
something like gravity is tricky if you're using an event-based workflow because it involves changing the input value on a synthetic cadence without the actual hardware input changing
If you're willing to eschew events you can write a processor with the EvaluateOnEveryRead caching policy: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.15/api/UnityEngine.InputSystem.InputProcessor.CachingPolicy.html
Otherwise I recommend just implementing gravity in Update outside the input system with MoveTowards.
I want to build something small for altctrlgdc, and was curious if anyone has experience with using gyroscopes in unity? I tried using a wii remote with an api (wiimote api) but it wasnt the most polished considering it's like 15 years old, and want to look into alternatives. The wii remote is actually the perfect size fit for the alternate controller we're sticking it in, and while Ive seen some people use their phones somehow, a phone is just too big atm (might use it anyway but again, wanna see alternatives due to size). Are there specific pieces of hardware I could use that will work with unity? I literally just need to access the rotation of it so I can create the controller, and im not sure where to look/start
Does anyone know how to enable gyroscope as an input method in 2d?
i want to get it working like it's a mouse but for some reason it just doesn't let me, not to mention that ll the tutorials are about mobile phones and not controllers
bind an input action to the gyroscope
but what kind of controller do you mean
hi does someone know any tutorial about how to do first person movement form scratch using new input system
try googling around
if i didn't why i will ask here in the first place
googling can give you a ton of results much faster
do you want us to just google for you
the only 2 i found one feels like it came out of hell and the second one 3 hours video and the he editing anouther script with old input system thet it's tutoria is 2 jours
and i am not doing that
have you tried different keywords or just scrolling further
i found several 10ish minute tutorials from a single search lol
i ahve been doing this doing this for a week
i trievrything
chatgpt
even deepseek
im not gonna spam 20 links here, so here's the search terms i used
"unity inputsystem first person controller"
yeah no those won't help, you can just cut genAI out
bro you did the thing that made me wanna quit in 5 mins like tysm i own you everything
remember, googling effectively is a skill too
yeah like i thing i am dumb cuz i wrote weird hologriphic stuff
yeah the video used the cmaera movent the old input system but i will figure it out
using UnityEngine;
using UnityEngine.InputSystem;
public class PllayerMove : MonoBehaviour
{
[SerializeField] float speed = 10f;
Vector2 moveinput;
Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
run();
}
public void run()
{
Vector3 pleyvelocity = new Vector3(moveinput.x * speed, rb.linearVelocity.y, moveinput.y * speed);
rb.linearVelocity = transform.TransformDirection(pleyvelocity);
}
public void OnMove(InputValue value)
{
moveinput = value.Get<Vector2>();
}
}
why i cannot add it to the inpector
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Add what to the inspector?
what are you trying to add
onMove func
Because it has an unsupported parameter type for that
CallbackContext is the parameter type as you can see here
oh so when i don't add nothing happends
If you're adding these with UnityEvents mode, you need to use CallbackContext as the parameter type.
You only use InputValue if you're using Send Messages mode
You seem to have mixed up two different workflows here
i have no idea what happend but tysm cuz it wroks but how to make the func work as a callback
Pretty sure what you want is this:
public void MoveHandler(InputAction.CallbackContext ctx)
{
Vector2 moveInput = ctx.ReadValue<Vector2>();
Vector3 pleyvelocity = new Vector3(moveinput.x * speed, rb.linearVelocity.y, moveinput.y * speed);
rb.linearVelocity = transform.TransformDirection(pleyvelocity);
}```
then you can assign it in the inspector properly
tysm man w dude
but what is the diff between callback ans send message which one is better
You mean the difference between UnityEvents and Send Messages?
UnityEvents you assign in the inspector
The biggest difference is assigning it in the inspector vs using the name to call it automatically
what it ti
what is the big diff
Hope it's right channel to ask about input actions. I got hit with a bug? that my keyboard input for some reason didn't read while it worked fine with both mouse and gamepad. Then i made new exactly same copy of broken map and it's working just fine
I can't figure out what's the problem and perhaps how to avoid this in future. Top screen is old and bottom is new
fwiw, that window is driven from a json file which may contain issues which dont show up in the UI, you could check the raw json to see if something is different between the two versions.
Thank you, for some reason old map used path: dpad instead of Vector2, even tho i've tried to change it few times in inspector
void OnShoot(InputValue value)
{
if (value.isPressed)
{
if (isauto)
{
}
else
{
shoot();
}
}
} can some tell me like whow to make the function spamble i mean like wehn i keep holding it keeps shooting
Use Update if you want to do something every frame
Can someone help me understand how to use this? Like dm me or just send it right here? Because im trying to start my dream project but I need to learn basics first 😭 I just want to know if I use InputAction or InputActionMap for movement and what not. Im desperate help me
an input action is an individual thing you can do, which has bindings
an input action could be something like movement, shooting, etc etc - each of them can have one or multiple keys bound to it
while an input action map is a collection of input actions, which you can toggle on and off, so you can have one for, say, walking around, one for when you're driving a vehicle, one when you're swimming, and so on
input actions are what you'd use to actually read input
Thanks. But like. How do I use it?
Like examplere yk?
many ways, the (imo) easiest is just creating some actions (double click the input actions thingy in your file system - should be there by default in newer versions), then in code you can serialize an InputActionReference, which lets you assign the correct action in the inspector
then, you can access the InputActionReference's .action property, which is the actual input action
that has events, like .performed, .canceled and some others
Sick
which you can subscribe to
Can I subscribe and turn on all notis for you? Cause thats well explained for me atleast
you can also use action.ReadValue<Type>(), which returns the value for it (the most common use case is when you have a composite (2d, like a joystick) action, for which the type would be Vector2)
wdym?
I was making a crappy youtube joke
Alright
Now I just need to remember this
i mean subscribe to the events, which means make a method get called when they're invoked
Yippee
I see
you'll pick it up quickly when you start using it
Yeah
Plus I need to remember how to make stuff from scratch
And other crap
a lot of the tutorials i've seen for it wildly overcomplicate it tbh
Yeah
I have a course in code4fun
But I just forget it all
Cause I dont practice
Im so good at this stuff ngl
the input actions also have other properties and methods, which you can read in the docs
Yeah
I tried reading the documentation
Too many words
And, well, im a dumbass sooo
reading docs is pretty much essential to almost any form of programming, so it's definitely something you'll have to learn at some point
i believe in you
Thank you cookie
Do people really keep the "Use Physical Keys" setting on? Because how can you tell people which key does what if 'q' does not always map to q - it is just the key to right of tab?
physical keys is the only way to guarantee your mapping works as intended on all locales. you can make the reverse-mapping in UI for display purposes.
Is it possible to create a SmoothDamp Processor? Or some kind of damping effect to the input system itself? I can do this easily in a movement script, but I'd have to manage different damping for different control methods where it seems logically better for the input system to handle this.
you can make custom processors
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.15/manual/ProcessorTypes.html#writing-custom-processors
you probably cant use them for a smoothdamp though because they need to be stateless
yeah by how to make this void in updatee ?
mouse input should not be multiplied by deltaTime
if OnShoot is supposed to receive messages from a PlayerInput, you aren't supposed to call it yourself
i want to be able to hold itl ike when i hold it prints when i stop it stops
set a press & release interaction, then in the message, you can check if it was pressed (you'll receive a message when it's released too) to update a state accordingly
i did buw when i try to change them in the setting it keeps getting bask
back
here
that's not the interaction i said to add
what to add
the hold interaction makes it do a different thing once it's been held down for a period of time
i mentioned it here
a press & release
i only have press and sme problem
i only have press
i want to be able to hold it
that's what press & release will let you detect
i found it but now
i wanna change this but i can't
when i press enter it return to defult
do you get me
i do not
i am working on shooting system and i want to when i hold it keep printing
what do you think press point does
it's unrelated to detecting holding a button
it's just for analog inputs, it's the threshold to consider the button "pressed"
ok but i am aking to keep printing when i keep holding and that is not what i got
if you have it set to press & release, you will get 2 OnShoot messages. once when you press the button, and once when you release the button. you can check which one it is via the InputValue, with the isPressed field
then, based on those messages, you have to keep track of a state yourself
you could alternatively do polling for this action specifically, but that kinda goes against using the playerinput
pseudocode:```cs
bool held
Update() {
if (held) {
// currently being held
}
}
OnAction(InputValue x) {
if (x.isPressed) {
// was pressed this frame
held = true;
} else {
// was released this frame
held = false;
}
// you could also do
// held = x.isPressed;
}
Is there a way to use Left Trigger [Gamepad] and Right Trigger [Gamepad] as axes, like with the old input system? I tried setting the action to Value/Axis, but it only returns 1 or 0 when I try to get the value as a float.
^Nvm. My controller can switch between controller types, and it was in Switch mode which only outputs digital Triggers. Switched to Xbox mode and it started working as expected.
My play testers have told me that the standard Unity Character Controller feels awful. I need a kinematic one and have tried KCC in the asset store but I can't retro fit it into my game (which is FPS and the controller is setup as 3rd person). Anyone know of any other kinematic character controllers they would recommend? Many thanks!
https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131
KCC can be used for a first person game
The examples included are all 3rd person with 1st person as a special case
So? You're talking about a camera difference. The movement of the character wouldn't change
/ input change
What kind of game is this anyway
the idea of KCC is that you make your own "feel", the examples are just there to show you how to use the -Motor. Its not a drop-in replacement for the built-in character controller (though for basic needs the excample is servicable). Maybe you'd feel more at home with a more turnkey (not free) controller offering from the asset store.
First person coop builder.
Thank you. I expect you're right!
What functionalities do you need in your game regarding the controler?
Is it just walking, jumping, crouching and sprinting?
If so on my profile banner I have a link to youtube channel and one of the last videos is about FPS movement. I just don't want to spam videos here, but it literally shows step by step, in a short tutorial how to implement all of that using CharacterController component. While it is not handling crazy use cases for most FPS games it should be enough
Thank you, Piotr. I'll take a look. I'm currently using Unity Character Controller and my play testers have all independently told me that it feels awful. I will check your video out just in case I'm doing something wrong. Many thanks.
Do you have any specific feedback? Because saying the controller is 'aweful' is not really helpful - is it possible to try the game somewhere?
does someone know how to make my shoot action work like wehn i hold shoot it keep shooting when i stop holding it stops shooting cuz i am trying for a llike 7 days and i can't
Use Update
didn't I already tell you how to do this
hey guys, so Im just using the stock UI.Navigate (Pass throigh Vector2) Action and trying to navigate through a menu with that. Im binding to .performed and it works fine with keyboard and dpad.
However, when i move the joystick It fires like a million times. Huh? I could do something quick and dirty to handle it myself but there must be a way to make this work within the input system
.started and .cancelled seem to do nothing when its pass through
Maybe a dumb question but is there a reason you need to write your own menu navigation instead of using the default?
Correct, pretty explicitly PassThrough eliminates these
the default is kind of a pain
i just want a simple menu to scroll through
dont wanna deal with what happens when u deselect stuff or use the mouse
and ive had issues before with having to micromanage navigation connections
this is just a number that goes up or down
Is there a rason you need to use an event-based workflow here?
I would just use Update
how
wdym?
Only if you code it very naively
the default navigation handles this stuff, but yes you would need to inplement your own timers etc.
you will need to do that anyway
even if you're using the event based workflow
The event workflow is not well suited for all tasks
nah it performs exactly as documented
its for a little thing just thought maybe it would be something I missed
for passthrough it will fire every time the input device actuation changes
if we're talking about a joystick yeah that will often be pretty much every frame
maybe im looking at different documentation but the docs for input are super vague
it just says like
“performed it fired when the action is performed”
Pass-Through
Pass-Through Actions bypass the conflict resolution process described above for Value Actions and don't use the concept of a specific Control driving the Action.*** Instead, any change to any bound Control triggers a callback with that Control's value***. This is useful if you want to process all input from a set of Controls.
ok i just missed that
man where was any of this when I was trying to research
thanks
last question is there any way to use the default navigation system that isn’t using buttons being selected and setting up all the transitions individually
id just like to extract out the direction the user wants to move in
the automatic navigation mode works pretty fine.
but uh - if you're having trouble with the passthrough default action why don't you just make your own input action for it
not a button. As a Value/Vector2
i maybe wasn’t clear mean editing the input action was mostly what I was asking for help with
even after years I still feel like such a noob with this system
could you outline what the input action would be and how the script would handle it?
cuz idk what you mean just by that
i mean the script will depend on your workflow for handling input in the first place
but the action itself would just be:
Action Type: Value
Control Type: Vector2
bind it to whatever you want to bind it to
then would you read it or get an event or what
you would read it however you want
like I said it depends on your current workflow
then what are you suggesting even
To make an action like this instead of passthrough
since you wanted to rely on .performed etc
hold on lemme remind myself what value even means again
ok
changing it to value and using the started event does exactly what I wanted
no extra handling needed
it keeps to work forever
i am doing in a function
Update runs every frame. If you want to do something every frame, that's your best bet
i am suing value paramter in new input system so how
What do you mean by that
Show code
SEC
void OnShoot(InputValue value)
{
Debug.Log("shoot");
}
yeah so - you'll want to use update and a timer. Basically this:
[SerializeField]
float shotInterval = 0.2f;
bool shooting = false;
float timer = 0;
void Update() {
if (shooting) {
timer += Time.deltaTime;
if (timer >= shotInterval) {
timer -= shotInterval;
Shoot();
}
}
}
void Shoot() {
Debug.Log("Firing");
}
void OnShoot(InputValue value)
{
shooting = value.isPressed;
}```
all of this just for holding system
"just a holding system" is, when you think about it, actually a somewhat complicated thing.
i thought because the made the enw movemnt ezy they will nto make the hodling hard like
wdym by "new movement"
Remember the input system is a system for processing input
not for driving your game logic
You could make this simpler if you used a different workflow
but you';re using PlayerInput with Send Messages mode
so you have to work within how that works
For example you could read the input directly in Update:
[SerializeField]
float shotInterval = 0.2f;
bool shooting = false;
float timer = 0;
void Update() {
if (InputSystem.actions["Player/Shoot"].IsPressed()) {
timer += Time.deltaTime;
if (timer >= shotInterval) {
timer -= shotInterval;
Shoot();
}
}
}
void Shoot() {
Debug.Log("Firing");
}```
but most of this logic is here for the consistent timer for shooting over and over again.
which you will need no matter what
for some reason that is happening
i copied the first one but now it is looping forever
you probably mesed up your braces somewhere { }
you'd have to show your code
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
(not with screenshots)
IT IS ABOVE THE LIMIT I CNA'T SEND
here
Why did you just paste the HTML for the blazebin website here lol
I need to see your C# unity script
how to send it
And what behavior are you seeing exactly?
Btw completely unrelated but this:
float mouseX = lookInput.x * sensitivity * Time.deltaTime;
float mouseY = lookInput.y * sensitivity * Time.deltaTime;```
Is incorrect. You need to take Time.deltaTime out of there, or your looking around will be jittery
then
the printing keeps looping even that i am not holding
Try this:
void OnShoot(InputValue value)
{
shooting = value.isPressed;
Debug.Log($"Received shooting input: {shooting}");
}
void shoot()
{
// comment this out for a seconf
// Debug.Log("FIre");
}```
And tell me what it prints when you are pressing/releasing it
it working forever
Wdym? What is it printing?
i wnt when i hold it keeps printing hwen i stop holding it stops but now when i just press it keeps working forever
what does? Did you try what I wrote? If so can you show me what it is printing?
I'm aware of what you want
I'm trying to help you debug it
it keeps printing forever
ok you didn;'t follow what I wrote then
See here? I commented the "Fire" log out
oh i did back my you know in fos games when you hold it keeps shooting i want when i hold it keeps printing but now when i hold one time in prints and that is it
Show me what is printingnow
again I'm fully aware of what you're trying to do, I'm trying to help you debug
so we can get there
And if you press/release the shoot button?
it doesn't print anything else?
i did but is not like keeps printing in the log when i keep pressing
Can you show your input action asset
show how you set up the "Shoot" action
Ok this is why
you added this Press interaction and set it to Release Only
delete this whole interaction
By presing this "-" button here
next
once you do that, you should save the asset
and then you uncomment the "Fire" Debug.Log and it should work properly
tysm is it finally wroked
why all of this to fix a simple problem
Well you caused yourself a lot of problems with that Release Only press interaction
that is not there by default
like unity logic is cooked
nah, you just don't understand it
yet
But you messed with part of the system you don't understand (the Press interaction)
so you got burned
buddy ive told you what to do multiple times already
you can't go around blaming other stuff for failing to read instructions yourself
Nah bro Roblox studio logic is cooked unity is act really logical and nice to use
i forgot to teel you i tried yours and didn't work
and bro all of this for asking smth 2 times 💀
