#🖱️┃input-system
1 messages · Page 18 of 1
The direct 1:1 equivalent of Input.GetKeyDown would be Keyboard.current[Key.A].WasPressedThisFrame for example
not recommended though since you cannot rebind it
you should use input actions
How can I do that?
That's basically "How do I use the new input system"
Just find/follow tutorials for getting started in the new system
any benchmarks about inputs, systems, event system, unity event, getkeychar, and other selectable soultions, message que all devices cpu costs?
I’m creating a first person controller with the input action system. I’ve got everything working with gravity, movement, jumping, and sprinting. I’m happy with it but the sprint action(shift) works for all WASD keys. Isn’t it standard to just have W and Shift as sprint? Can anyone shed some light on how I should approach this, whether in the Input Action controller or in code. Right now I use OnSprint to toggle a bool to set sprint speed, if that helps. Again, very new to the input system, so appreciate any help
handle this in the code
Just have Sprint be a separate action
in your movement code you can easily have somthing like:
if (movementInput.y > 0 && sprintAction.IsPressed()) {
speed = sprintSpeed;
}
else {
speed = normalSpeed;
}```
Awesome .y > 0 is what I needed. That canceled out the ability to sprint backwards or sideways, but can still sprint diagonally using WD or WA. I’m trying to remember if that’s normal in games. Time to load some up
Thank you!
If you don't want that then add an additional check for movementInput.x == 0 for example
or e.g. Mathf.Abs(movementInput.x) < 0.1f
Perfect everything works. Thanks again @austere grotto
I'm trying to use the on-screen stick on an android mobile. It does work in the editor perfectly, but it does not work in an android build, even though I can see the joystick moving and being pressed
Any ideas what I'm doing wrong?
I updated the input system package
now it does not work at all lol
Is the "new" input system very useful for a one button game where the time around the pressed button and other stuff related to the position of the character in the level ?
Or should i just keep the default stuff
It's useful if you wish to be able to rebind that one button or do local multiplayer, or if you wish to do event-based input handling.
same as the benefits of the input system in any game.
can you give a link or some examples for event-based input handling. ?
pretty much any input system tutorial covers this
there are several approaches
ok ty
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/Workflows.html this helped me a lot
how do i make a local multiplayer in which players are controlled using a single keyboard
so this happens when i click generate c# class from the editor
When you say "this" you are referring to?
the errors?
Question. With InputActionMap for fields. If I assign a custom generated ActionMap to it, is there a way to get my custom map or verify that a specific custom map was assigned(so I am not trying to pull values that aren't there?
what do you mean by "custom generated ActionMap" exactly?
InputActionAsset
Cannot implicitly convert type 'PlayerActionAsset' to 'UnityEngine.InputSystem.InputActionAsset'
It should have a .actions property
that returns the wrapped InputActionAsset
or perhaps .asset
forget what it's called
InputActionMap has a .asset, but still I can't assign that to a PlaterActionAsset
I am pretty sure that just gets the InputActionAsset related to the map. And I can't convert InputActionAsset to PlayerActionAsset
I'm not sure I understand what you're trying to accomplish here
PlayerActionMap is a convenient wrapper around an InputActionAsset with nice names
that's all it is
So I can access actions by string with InputActionAsset, but by fields with the generated PlayerActionAsset. (forget the map part, that was just terminology messing me up).
I can assign an InputActionAsset through the editor, but not a PlayerActionAsset.
I need a way to turn InputActionAsset into the PlayerActionAsset.
Currently I just am adding A static service field since the generated ActionAsset script class is partial.
Maybe assigning it through editor is just the wrong approach as it isn't like the normal InputActionAsset, and won't have multiple versions.
I need a way to turn InputActionAsset into the PlayerActionAsset.
There's no way to do this without manually modifying the generated class or using reflection.
Basically you'd have to make this writable
and/or assigned in a constructor
Yeah, just calling a static reference works for now.
I am trying to use ReadValue<Vector2> to get the mouse position each frame. But it is only returning the same value over and over. Can you not get it like that, and only through the delegate?
Okay pretty sure it just isn't getting the mouse position properly. Not sure how to fix that
You might not have enabled the input action / input action asset
{"x":0, "y":1, "z":-10}
or
[0, 1, -10]
is all I am getting
Tried both virtual and non-virtual mouse position
Also tried ReadValue and Performed
Restarting Unity as sometime that helps
And my dislike of the new input system continues...
are you using a virtual mouse?
Read my messages
this
Ok i think you meant to say "non-virtual"
but you said "none" so I thought you meant you bound it to nothing
Ah see the confusion
you want either Mouse position or Pointer position
I tried Pointer position also, same thing
you're debugging ScreenToWorldPoint
debug the actual input value
ScreenToWorldPoint is giving you the camera's position {"x":0, "y":1, "z":-10}
Ah good catch
well, that isn't the only issue.
Debugging the read value just is giving {"x":0, "y":0}
which which binding
yea sorry been at work, whenever i hit generate c# class it generates with all those errors
And the errors are?
Show one example
everything in red, im just curious why it generated like that
sec let me show a tooltip
I'm asking for the error message
well there are many but here is the first
Assets\InputControls\PlayerActions.cs(518,19): error CS0542: 'PlayerActions': member names cannot be the same as their enclosing type
Assets\InputControls\PlayerActions.cs(520,32): error CS0523: Struct member 'PlayerActions.PlayerActions.m_Wrapper' of type 'PlayerActions.PlayerActions' causes a cycle in the struct layout
Looks like perhaps you named your input action asset PlayerActions but also named one of your Action maps PlayerActions
the PlayerActions C# script is whats generated. are you telling me I just need to change the asset name ?
try it
I think you might have hit a weird edge case in the code generator
it probably takes your Action Map name "Player" and adds "Actions" to it to create the name of a struct holding its actions. So it ends up naming something PlayerActions which happens to be the name of the asset itself
hence the naming collision
so renaming it worked. it generated the same name of the asset again but no errors
thanks
New project and suddenly NIS isn't working. I'm using is just how I have in the past but suddenly it's not working. It's enabled properly, I've tried public methods, NIS does recognise input through the input debugger just not through the actual game. Any clue what's going on. Same version of unity as projects with working NIS, just new projects have this issue.
Could be a control scheme issue
I notice you have a scheme just called "Control scheme"?
Oh? Schemes are new to my knowledge, I didn't remember interfacing with them before. Do they need to be named in certain ways?
did you change the hierarchy of your scripts that your player input is attached to ? I think send messages only looks at current object. I don't think it will find your functions if its nested.
They need to be... set up properly. It seems like you set up some control scheme stuff possibly by accident?
I just made a new controls asset and ignored Scheme, seems to work fine now. I had sworn it prompted me to make the scheme, my bad.
Thank you!
Is there a way to detect if the application is running on a device that supports touch?
I ask this as I see there are platform dependent compilation that you can say, if iPhone or if Android, but what about the case with Windows 8 tablets and touchscreen computers? I have a microsoft Surface pro that supports full Windows 8 Pro and has a touchscreen. If I made a desktop version of a game, the pro theoretically could support touch ...
Just use google man. It's the first link that popped up and already solves it
and it's not what I want
don't judge what someone wants before you're sure
this is not compatible with the new input system
SystemInfo.deviceType is also not compatible with webgl
just go answer questions you know about
You didn't mention the new input system
or webgl
btw we're in the input system channel? did you notice?
I wouldn't be rude if you wasn't rude first
I wasn't rude
This channel is the Input System channel
I know
"just google" sounds rude to me because that's my everyday job as a developer
Which refers specifically to the new input system...
anyways, I found a way to solve the problem
I can do InputSystem.GetDevice<Touchscreen>() and check if it's there
I'm still using the old input system. I can ask it in here
Best to ask in #archived-code-general or #💻┃code-beginner for that. This channel is for the new input system only
It's kinda confusing the naming scheme unity used, but the old input is not called the Input system
In my ears you basicly asked "How can I eat".
I answered: "With your hands"
The reaction "I'm eathing soup, I'm not going to eat soup with my hands."
just forget it
I didn't know you used webgl or used the new input system.
I should've just ignored you in the first place
That is a wildly innacurate reduction of what happened. This channel is for the new input, so it was definitely the new input. But this is off-topic now. Stop
I'm too busy for that
sheez. I just tried to help. A lot of beginners ask in this server before googling, cause it gives more direct answers. A lot of beginners (who use the old input system) think that this is the place to ask a question.
I didn't know you were an everyday developer. Sorry if I sound rude in your ears, but I wasn't.
Like someone would ask "Can I get some help" and someone send the "dontaskjustask" link. That isn't rude at all. Just giving advice what they should do.
And yes Aethenosity. I'll shut up now. Even though you're not a moderator
ok, I know beginners do that and this is what enraged me the most, I only ask questions after a lot of research and personal tests
Alright, Now I know I don't need to react, thinking everyone here is a beginner.
You're shutting me up for no reason. You're saying that this is off-topic, but it isn't. I'm here a 'lil longer than you, so I know when something is off-topic. It's still related to the misunderstanding in communication about the input system.
And now it's fixed can i shut up
So that means that you can also stop reacting to my messages. If you wanna say smt, then do it in #💻┃unity-talk or via dm
<@&502884371011731486>
I have two functions (https://hatebin.com/zrakphakzc) that are very similar and both rebind controls but the one thats supposed to work for composites(the second one) dosent run the On complete part of the PerformInteractiveRebinding but the first function runs perfectly fine.
Hi guys, I've set up my player this way (https://paste.ofcode.org/zRB768qdpGbt4hButptX56) but for some reason I can't figure out why there is no way the event .started calls the DoBuzzle function even if everything seem to be assigned correctly in editor and in game.
When are you calling InitializePlayerInput()?
Hey guys, im using the new Input System.
Let's say I have an Action called "Jump", and underneath, I set it so that on keyboard, spacebar is jump, and on controller, X is jump, etc.
How do I find, in code, find out what key is to perform "Jump"? Given the device I'm on
I got to the point where I can print out:
"<Keyboard>/Spacebar"
"<GamePad>/X"
But given that, is there no easy to just check:
if (this running device matches the first part of that string), then use "Spacebar", etc.
I feel like having to do some heavy string manipulation of splitting those strings by "/", and then trimming the "<" and ">" and then STILL comparing the "keyboard" string to detecting if a Keyboard is plugged in, all feels like messy code.
My aim here is that:
if player approaches a treasure box, it says "press Spacebar to open" or "press X to open" based on device automatically.
So my first thought is to allow the player to set a layout to keyboard or gamepad and store that in prefs or something (so you know which device terminology to use). I believe you can check the gamepad using GamePad.current to see if one is loaded.
Oh I don't need to worry about player setting the layout, i dont let player change the controls mapping in this game.
I just want to be able to see "press {key} to Interact" without checking if ("keyboard" && device.Keyboard == true) for example.
Is that really the cleanest way?
There's no way Unity released such a big Input System feature, and everyone brags about it, but such a common feature, seen in literally every game, is not easy to do
We know Unity can detect device, cause as soon as I plug in a GamePad, X is now jump.
So if Unity knows which devices are plugged in,
why can't I just ask like string = "Press " + player.Input.Interact.key + " to Interact!"
And that variable in the middle is whatever button is mapped to Interact based on the current device active.
Unity should just give me "Spacebar" if keyboard is detected, or it should give me "X" if GamePad is active.
sorry i dont mean a layout like changing the controls, im just saying that if a game pad is detected to just default to using that terminology
Why do I have to detect if a GamePad is plugged in tho?
Do we, developers, have to detect if a GamePad is plugged in when we decide X vs Spacebar to perform Jump? No, Unity's InputSystem does
on the InputSystem Mapping menu.
i see what you mean now, you mean regardless of what device consumed the action you want a clean way of knowing what device it was
Yes, I just want Unity to tell me what to display based on Unity knowing what device is being used
If I have to do the whole:
If (device == keyboard)
// code
else if (device == gamepad)
// code
else if (device == mouse)
// code
else if (device == something else)
// code
If we have to do this ^ messy thing, then that's not good.
but, if you are showing a message like "press X to open the chest" is assumming no device event has been triggered yet
Yes, cause I am telling Unity I want to know the key for Interact action.
If you see the image above, I have either E or Select
but can't Unity tell me to display the one, of the device, that was most recently active?
Basically, if this new Input System by Unity is good, I should just be able to do this:
string = "Press " + player.Input.Interact.key + " to Interact!"
and Unity should, in that variable 'player.Input.Interact.key' just replace it with 'X' or 'Spacebar' depending on most recent active device, or active device.
for me, i wouldnt expect unity to figure out which key to use if you havent told it what to default to
when there are multiple bindings
Does Unity not know what device is active?
i believe to do what you are looking for is to use control schemes and listen to device changes. but to me that is overkill if you are only really looking for changes between gamepad and keyboard/mouse
Are you suggesting this is the best idea so far?
But how is Unity System all that modern if this messy way is the best way?
And in the future, if I add another device as support, I have to not only modify the InputSystem action map
There may be some better way that I do not know of atm, someone else may have some better input (pun intended) on this
but ALSO, all the places I have this messy if-condition in
This is messy to me, and also repetitive, and devs would have to come back and change this every time a new device is added
you may need to go back a little but here https://youtu.be/Yjee_e4fICc?si=nNqgqT2_i2xHUefN&t=1474
✅ Get the FULL course here at 80% OFF!! 🌍 https://unitycodemonkey.com/courseultimateoverview.php
👍 Learn how to make BETTER games FASTER by using all the Unity Tools and Features at your disposal!
👇
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Gam...
I'm calling it when the match is starting (the player is pressing 1 on his keyboard)
^ still can’t find the reason behind this
But where in the code?
i subscribed my toRun action as seen here in the start() function but when i press the ToRun button i get no input registered. Why?
Local multiplayer input system
When having the same key on different action maps how does the rebind work? So for example Action Map A has a action with the "M" key and Action Map B has also the "M" key. When rebind the "M" on Action Map A to "N" does it work automatically for Action Map B aswell?
hi, i made some little code, and it works only when the Point action is in Movement action map, and doesnt work when it is in the Grapple action map. i think it may be caused by the Movement action map set as the default map, how do i force the game to use both action maps?
You rebind a particular action. Only that action will be rebound
You can enable/disable action maps as you wish just by calling Enable() or Disable() on them. Is there a good reason those should be in different action maps though?
i wanted to sort them more, but it isn't necessary to keep them in different action maps i think. thanks for help anyways
Hi everyone, I have player Input component attached to my player which is taking a Xbox Controller scheme by default at runtime, it’s not detecting my keyboard and mouse.
Can anyone help me resolve this?
It says Keyboard/mouse is the default.
Also it would be a lot more helpful if you used the screenshot functionality on your computer. People really hate seeing phone photos because it looks unprofessional and it makes it less likely for you to receive help.
Hi, is there a good way to share a canvas like a character roster screen in a local multiplayer setup where each controller has a virtual cursor ?
Like in Super Smash Bros. Ultimate.
Hi, I'm trying to use the input system to get the camera to orbit my character. I want to basically use a click and drag to move the camera, but I want either mouse button to work. For each binding, I'm using mouse delta with a mouse button modifier. When I have only one binding, it works as expected. However, when I have both bindings, only the second one works, and the first stops working. Am I misunderstanding how multiple bindings work? Any help would be appreciated.
I would just get rid of the modifiers completely. Put the clicking on a separate action and just use an if statement in your orbit code
This is too cute by half
I would expect it to work fine, though.
Oh wait, I misread that
but I'd still expect it to work. Maybe the second one consumes the mouse delta? I'm not sure how that works...
does anyone know why it isnt working?
Define "isn't working"?
One thing is you should not be multiplying mouse input by DeltaTime.
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
It is not configured either
this is the first time im using c# and i watched a tutorial for this and now it doesnt do anything
Was the tutorial from Brackeys? Maybe that Dave guy?
I would recommend doing unity's tutorials before anything else (other than a straight up c# course like https://www.w3schools.com/cs/index.php)
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
yeah dave, do you think i could still use this script with some changes or should i start over?
You could use the script sure.
I dunno what the issue is because it could be many things.
Do you have the script attached to anything?
yes, to the player
Can you screenshot the inspector for the player?
It seems like it should work.
I don't think this is the issue, but do you have any rotations constrained in the rigidbody component?
do you mean this?
that i should set the y to 0?
where's the camera? You need to show the hierarchy and which components are attached to which objects etc
the camera is completely unrelated to the player
so none of this code is going to affect it
you've made it a separate object
you should probably see how the tutorial did it
and follow that
What Praetor said is the issue, but no, I meant the rigidbody component which is right above your MouseInput component on the Player object.
But that is irrelevant now
i have a script in cameraholder that connects to camerapos
And how does MoveCamera know when to move?
If I remember that tutorial it is based on it being moved by the player, because it is supposed to be a child
seems like important information to have included
i have no idea, i just followed the tutorial. i probably messed something up
You could share that script?
this only move s the camera's position. Doesn't do any rotation
so of course it won't rotate
So yes. CameraHolder needs to be a child of Player
this is good right?
like this?
also the CameraPos object is not even being rotated according to what you've shown either.
I don't see why you need this proxy layer
just make the camera a child. There's a reason you have an object called PlayerCam
that should be the camera
Are you trying to mix two different tutorials or something
nope, he said that it wont be buggy when use it
My recommendation is just to start the tutorial over and follow it more closely
you seemingly have just done things differently from the tutorial
and therefore it's not working
https://www.youtube.com/watch?v=f473C43s8nE i really dont think that i did something wrong to be honest
FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial
In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.
If this tutorial has helped you in any way, I would really appreciate...
but ill watch a different one
Yes
If you are going to something else, I strongly suggest not using youtube
Use unity learn first, then move on to YouTube
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
i only see thing with movement, nothing with looking around
Don't pick and choose.
Go to the pathways and do the unity essentials, then the junior programmer paths
Come back to what you want to do when you have a foundation under you
as a side note:
Unity tends to prefer transform.SetPositionAndRotation(camTrans.position, camTrans.rotation);
over the other approach for optimization purposes.
does there anyway to detect which device connected to pc in Unity with new Input System? Like keyboard, dualshock or xbox gamepad?
you might be looking for InputSystem.onDeviceChange
You need to switch the Navigate action to "Value" mode from the "Pass-through" mode. Since the default action asset comes from the Input System package, you'll need to make your own copy (or just copy the UI action map into your own asset)
I just learned about this and oh my god it was so annoying
let's spam some keywords for the search: steam deck d-pad, d-pad steam deck, steam deck, dpad, d-pad
Hey guys, quick question. does anyone know how to WRITE any data on an existing input action for the new unity input system?
I want to make a FixedTouchField for my mobile and pc fps controller but I can't find how to write a value(for this case a vector2) inside one of the existing input actions called Looking
Using the new input system, I want to let the player use the d-pad to navigate a menu whilst still using the joystick to control their character.
Both the joystick and the d-pad are bound to the Navigate action
and the EventSystem is using that action for navigation
I guess I need to make a separate action, and then switch which one the EventSystem is using?
Maybe I can just disable the joystick binding, but that looks a bit icky
I am currently using the old system for quickly setting something up but i was wondering where i can find a document showing all axis and which one i need to select for the right joystick horizontal and vertical movement
i found it
need to use x axis and y axis joystick number 1 or 2
only need to figure out the correct way to set my deadzone cause it doesn't seem to work properly currently
ok so i figured out the sensitivity and all that it works fine with a joystick but it's not the correct one
i right now have the left one working and it can rotate my camera around etc but i actually want it to be the right one doing this
i have tested all 16 and none of these is connected to the right joystick anyone know how to do it?
How can i check if an InputActionMap has a specific processor?
i have a rebinding system that generates multiple ui fields for each input action inside a map, but some inputs i dont want to be rebindable (such as Escape for pausing). I thought best way to implement this was with a processor that did nothing and was only for marking the action to not be rebindable
all i see however is the processors property, which retuurns a string
Why not just make a list of the rebindable or non rebindable actions
Either with InputActionReference or just a string name or something
because i dont want to spend time filling that list and updating it if i add a new action
regardless, the protperty just returns the name of the processor, so i just compared strings and called it a dday
is the Input System Actions package broken or is my install borked? because in every dialog like this it tries to show a search bar on the top, and I can't click on any item
just noticed that it's also creating this warning
that's a bug in the package :)
you can still pick them with arrows on keyboard
aw! got it x3
yeah i think it switches the two mouse buttons around i can always select it with the right one instead of the left one when it happens
this bug has been here since the 2022 version
I'm implementing the new Input System on my camera controller script but I get a jittery look movement, how can I smooth it?
I just solved it by adding a scaling preprocessor on the inputaction and scale the vector of something like 0.1f
Is this supposed to be grayed out?
And how to block clicks under GUI objects but not on the terrain, 3D objects etc.
I'm setting up the new input system for the first time and I have some questions.
I'm making action maps for each state the player can be in. mainly exploration, combat and UI and I turn these action maps on and off from my state machine.
combat and exploration are close to identical in the actions they have but with some differences.
now that I'm making my player movement script I'm not sure if I need to subscribe to both the Exploration.Move and Combat.Move or if there's a better way to do it.
I can't get a mouse click event to fire no matter what I do.
public void OnClick(InputAction.CallbackContext context)
{
Debug.Log("OnClick fired");
}
Why is it never firing?
It's a bit unclear what the input module has to do with it
PlayerInput is completely unrelated to the input module
Also a bit confusing that you named your actions asset "PlayerInput"
But you'd have to also show how your asset is set up
I got it to fire, I had to add devices apparently, but now I have a worse problem that I can't detect if player clicks GUI or not
Late answer, but yeah, the same is happening to me
in the new input system the gamepad sticks are not yet delta time affected right?
Hey I have a question I will rework my game for the new Inputsystem ..
m_Vehicle.SetSteerInput(Input.GetAxis("Horizontal"));
How do I get this float Value ?
Is this correct ?
Input is input. It's just going to tell you how actuated the stick is, between -1 and 1. There's nothing framerate related about it
If you want to translate that to movement per frame _ or something, some adjustment will need to be done at some point
But it would make no sense to do it at the input level
yeah, it's for my camera rotation to apply delta time so that it is consistent
For example if you wanted to use it to set a velocity it would be counterproductive to premultiply DeltaTime
just trying to figure out how i can best do a check for which device is giving input to apply delta time only when needed
You mean like mouse vs joystick
yeah, i found something i think by using the devices
private void UpdateDevice()
{
if (playerInput.currentControlScheme == "Keyboard&Mouse")
{
currentDevice = DeviceType.KeyboardAndMouse;
}
if (playerInput.currentControlScheme == "Gamepad")
{
currentDevice = DeviceType.Gamepad;
}
}
This is what i have found on a forum, i think it works pretty well and am using it for now but maybe there are other ways that also work well
private void OnLook(InputValue value)
{
lookInputValue = value.Get<Vector2>();
lookInputValue.y *= -1.0f;
if (currentDevice == DeviceType.KeyboardAndMouse)
{
lookInputValue *= 2.0f;
}
if (currentDevice == DeviceType.Gamepad)
{
lookInputValue *= 2.0f * Time.deltaTime;
}
}
This piece of code uses it to apply deltaTime only when it's a gamepad
Does PerformInteractiveRebinding() need any special code to complete the rebinding? I have it linked to a button, and when i press that button and then do some sort of input it does everything it needs to except rebind the button. Like I have time paused (will probably remove later, currently doing testing) and I change the text, and it does successfully do all that stuff but it doesn't actually rebind my input, jumping (which is the input im trying to rebind) still activates when I press space (what I have it on initially) rather than whatever I pressed last while trying to rebind. I've tried doing multiple things such as setting my jump variable (which other scripts reference when I want to add or remove something) to Player.Jump; setting my jump variable as a get to Player.Jump; adding something to jump with playerControls.jump += _ => Jump() (or whatever other code I have here); setting jump up in Behavior on my PlayerInput to InvokeUnityEvents and linking them there in Player; and some weird thing with dictionaries that I don't know how to explain because nothings been working even though it did work in the videos/scripts/tutorials ive watched
Is there any way for the Input System to detect any key/gamepad button press? Something like the old input system:
Input.anyKey
Keyboard.Current.anyKey
That will only be for keyboard though
Debug.Log("[CLIENT] Setting up skill inputs");
void OnSkillOne(InputAction.CallbackContext _) => skillMechanic.Skill(0);
skill1.action.performed += OnSkillOne;
SignalStream.GetStream(StreamId.Player.Disconnected).OnSignal += (_) =>
{
Debug.Log("[CLIENT] Removing skill input events");
skill1.action.performed -= OnSkillOne;
};
I am trying to unsubscribe performed events here but it just does not work and I have no idea why. Any idea how to clear the performed callback list? skill1 is of type InputActionReference
Is this unmodified code? In what function is all this from?
What is SignalStream
Sorry for adding additional framework logic.
My main question is how can I properly clear out performed callbacks. Like completly prune all callbacks of it without having to use the -= operator stuff
-= is correct.
And for gamepad or touch controls?
I found a helpfull answer on the forums for the bug in the UI you can have with the input system.
If you get the warning
Unable to find style 'ToolbarSeachTextField' in skin 'DarkSkin' Used
UnityEngine.InputSystem.Editor.InputSettingsProvider/<>c__DisplayClass14_0:
you can just double click on it and make sure that the word Search in the strings are written with an r.
The script this is in is the AdvancedDropdownGUI.cs script.
13 #if UNITY_2023_2_OR_NEWER || UNITY_2021_3_28 || UNITY_2022_3_1
14 public static readonly GUIStyle toolbarSearchField = "ToolbarSearchTextField";
15 #else
16 public static readonly GUIStyle toolbarSearchField = "ToolbarSearchTextField";
17 #endif
one of the two is accidentally written as Seach which causes the UI to have this bug and get a warning
wait long enough after adjusting the string too sometimes it changes back because it is still loading i think
You can find it here: Packages > Input System > Editor > Internal > AdvancedDropdown > AdvancedDropdownGUI.cs
is there a way to get the name of an action map when accessed through the c# class?
I tried it like this
void SetInputListeners(InputActionMap actionMap)
{
switch (actionMap.name)
{
case InputManager.Actions.Exploration.name:
//subscribe to Exploration inputs
break;
}
}
but the Exploration.name isn't a thing
What is InputManager.Actions?
it's a reference to the c# class generated by the file
rn I'm trying to bypass needing that name by just using an enum
but if there's a better way to do this I'm open for input xD
can you share your generated C# class? I'm trying to find an example of my own 😆
possibly the wrapper exposes a reference to the actual InputActionMap it wraps
what's the site again to share large blocks of code? xD
!code
📃 Large Code Blocks
Use 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 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.
Can you do Inputmanager.Actions.Exploration.Get().name
basically, I have an event that invokes when I change actionmaps, and I want scripts to listen to it and subscribe to actions that are now active, and unsubscribe from everything else
ok that works, but not in a switch case for some reason
oh a switch case wants a constant value...
I guess I'll just try with the enum ID getting passed along in the event
indeed. Maybe do case nameof(PlayerInputActions.Exploration)?
you could also directly compare instances, or just use an if/elseif chain instead of a switch
nameof doesn't give any errors. lemme test the code rq
ok it works
nice
thanks a lot xD been struggling with that one for a while
Is there a built-in way to detect mouse/pointer clicks? Meaning, down and up on the same point (within some threshold) or do i need to track that myself?
Like for UI elements?
In my case for world interactions, ideally using InputAction. For UI i can use IPointerClickHandler
Hello, I'm currently converting my PlayerController to the new input system. When I rewrite my lines I have the problem that with the old input system the tires move "slowly" to the left and right. When I use the new input system they are completely left or right depending on which direction I press. What is the problem or do I have to figure it out?
' m_JeepVisual.SteerInput = Input.GetAxis("Horizontal");`
m_JeepVisual.SteerInput = Input.GetAxis("Horizontal");
` private void HandleInput(Vector2 driveInput)
{
// Verwende die MovementInput-Informationen, um die Fahrzeugsteuerung zu aktualisieren.
if (m_Vehicle == null) return;
// Du kannst beispielsweise die X-Komponente von MovementInput für die Lenkung und die Y-Komponente für die Beschleunigung verwenden.
m_Vehicle.SetSteerInput(driveInput.x);
m_Vehicle.SetAccelerateInput(driveInput.y);
}`
So I posted a question in #💻┃code-beginner and I'm not actually sure that was the right place to put it (also it got ignored) (it's def a beginner concept but my level of general coding knowledge seems less beginner after seeing some of that chat) the concept also fits this channel, is it cool if I 'break' the no posting to multiple channels rule and move the question over here
What do u need ?
My behaviour is like "GetAxisRaw" is there a way for a "filter" with the new Inputsystem ?
Let me know if you want me to move the code blocks over but basically I'm trying to bind jump to "up" instead of a button, but for some reason the physics dosn't like it (or the way I'm doing it) and sends me to space. I've tried a few things but it's either slightly better or worse
Is there a "Interpolation Filter" for the New Inputsystem ?
ok maybe I do belong in beginner
Cause I have absolutley no idea what that means
You can use IPointerClickHandler for world space interactions too
As long as you have a physics Raycaster
Yes, but that's not what i'm looking for, it inverts the kind of control i try to implement. I don't want the objects to be reactive, but need the input action dispatching to be conditionally targeting different potential receivers, and for that i want to detect the kind of click independently of what was clicked. I saw that there are modifiers or something like that which allow input actions to have a perform-time (i.e. 0.5s mouse button held down), so i hoped that there was something similar for a sequence of down-up, that models the normal, expected pointer click behaviour.
But now that i wrote that out, i see that these are called 'interactions' and that there indeed is 'tap', which is kind of what i want.
hi, for some reason out of the blue on startup my game is throwing this:
NotSupportedException while resolving binding 'Navigate:<Gamepad>/rightStick/right[;Gamepad]' in action map 'DefaultInputActions (UnityEngine.InputSystem.InputActionAsset):UI'
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnEnable () (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:1453)
NotSupportedException: Control count per binding cannot exceed byte.MaxValue=255
UnityEngine.InputSystem.InputActionState+BindingState.set_controlCount (System.Int32 value) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Actions/InputActionState.cs:3305)
UnityEngine.InputSystem.InputBindingResolver.AddActionMap (UnityEngine.InputSystem.InputActionMap actionMap) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Actions/InputBindingResolver.cs:391)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnEnable() (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:1453)
I dont have any right stick input mappings in either my UI or Player actionmaps. Any idea what i might have done? It was working fine!
maybe I should restart the editor, its been a good few days 🙂
lol yea that was it
restart unity more than every five days
I have a small question i would like to use callback context with the playerinput component but i had an error from the playerinput component saying it can't find the OnLook method.
private void OnLook(InputAction.CallbackContext context)
{
LookInput = context.ReadValue<Vector2>();
}
First i used the InputValue but for checking the device the input comes from i would like to use callbackcontext since you can use it to check
i found it i forgot you need to change the playerinput events
hey so im trying to leanr the new input system and im kinda confused so this is how my old movement keybinds where how would i make that in the new input system
smth like this maybe
and then this to get that value
horizontalMove = value.ReadValue<float>() * m_Speed;
Probably worth following a tutorial or two to get your bearings
there are several ways to use the new system
yeah im trying its just i really dont wanna remake my whole player controller
this new input system is really weird
This might be a good place to start too https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/manual/Workflows.html
and confusing
it's confusing mostly because there are multiple ways to use it
it might also be confusing if your C# is not that strong and you aren't familiar with events for example
yeah i guess its just i was used to only needing 1 line of code for it instead of adding all this other stuff
i guess i will watch a tutorial then
and just somewhat remake my character controller script
why does theres have the calback context thing but mine doesnt
Probably just a different version
ok
how should i do movement properly because right now its really horrible
private void FixedUpdate()
{
m_Rigidbody2D.velocity = movement;
}
public void Move1(InputAction.CallbackContext ctx)
{
Vector2 inputVector = ctx.ReadValue<Vector2>();
movement = Vector2.SmoothDamp(m_Rigidbody2D.velocity, inputVector * m_Speed, ref m_Velocity, m_MovementSmoothing);
}
you never stop moving it seems and all around bad
Could you explain more in-depth for that I’m confused
does anyone know why OnPauseGame() does not work?
the brake one works and its the same type
Sorry, just seeing this (I was taking an exam)
Basically, the most reliable way I've found is to make a bool and set it to true or false based on the CallbackContext state
It passes a .started state when you first press the key/whatever, a .performed state two or three times during it (from what I understand) and a .canceled state when you stop the input.
So, where you get .started, set a bool called moving to true
When you get .cancelled, set it to false.
If moving is true, move based on the vector you would get (your code already stores that, so i won't go more into that part)
Aight thanks
Hello, I'm trying to add mobile input for the frist time. I'm using the new input system with "On-Screen Stick" & "On-Screen Button" Components. They are working fine independently, but cancel each other out when I try pressing both the stick and the button at the same time.
I set the "Action Type" to "Pass Through" but that didn't resolve it
Is is completely necessary to create a custom script to get this working? Or is that not necessary and I'm doing something wrong?
Did you hook them up to the same action or something?
I set the stick to gamepad left stick and the button to gamepad right trigger
This is what I'm currently using for my keyboard and Controller input.
Should this also work for mobile?
I hope that answers your question
Hello. I'm having an issue where the new input system isn't able to process inputs from a common peripheral players my target audience are likely going to use
When using the C stick on a gamecube controller, the inputs are processed through the RZ and Z axiscontrol fields
However whenever I try to pull up those values in the new input system plater actions, they don't show up
(Everything ebove here on the menu is buttons 1-9)
Does anyone know how to force input actions to accept certain types of input from the input debugger
not sure but... does anything show up if you press listen and move the stick?
Ran into an interesting problem. I named a class InputSettings. This broke the Input System Package menu..
It looks OK now that I've renamed my class.
I've seen some tutorials where a script instantiates a new InputActionAsset for a controller in Awake/Start but the PlayerInput component also has a reference to one of these.
If my game has multiple controllable actors (where only one is controlled at a time) is it wiser to access the same reference to the asset belonging to PlayerInput rather than each instantiating their own? or is the difference negligable
if I should reference PlayerInput.actions: How can I cast this to my own asset type? e.g. my map asset is called "PlayerControls" so how can i cast actions (which is type InputActionAsset to PlayerControls") or should I change any references to reference a general InputActionAsset and find actions within like [""] instead?
Another thing to note is I reference the control asset when subscribing my inputs, would it be wiser to only reference maps instead?
Sorted it, switched to referencing maps instead of the asset and all is fine
Is there a go-to way of mapping input system axis values to a different range? Or do you guys use Lerp for that?
Just a remap function https://forum.unity.com/threads/re-map-a-number-from-one-range-to-another.119437/ (Lerp is a remap function for the input range 0-1, which many input types satisfy).
Okay, Ill look into that then. Thank you.
If two actions use the same input does it only trigger one? I am using space for the y+ for my movement, but also for jump, but jump isn't getting called for some reason.
I see it working for the y+ movement though
And yep, if I get rid of the space on move now jump is working... Is there anyway to have both?
i think it will trigger one by actions done by the user
from what i tested
Yeah, once I removed it from the movement it was working for jump. I think I saw some setting for this somewhere but no clue.
This is working for now
I have been struggling with element focusing using a controller for a while now.
All I want is, when the Start or Select button is pressed and the UI canvas appears, 'Focus' an element where I can contineu my navigation form using a controller 🥹
using
EventSystem.current.SetSelectedGameObject(initialSelectedObject);
Actually selects the button. I want to simply focus 
Selected is the only form of "focusing" the system supports afaik
I've left this message on general but I'll also leave it here in case anyone has any idea. I've been experiencing issues after moving to new player input system. When I'm just moving with A/D around an object or corner or anything looks smooth but if a move the camera and press A/D it's becomes really jittery. I'll attach a video below. If anyone has any ideas, I'll hear them out happily. Thank you!
Doubt it's an input system problem. Probably a common character controller pitfall like using Rigidbody motion and rotating the Transform instead of the Rigidbody
Yup just figured out 10 mins ago i should rotate the rigidbody not the camera
I know i have to change the last line but idk in what to
rb.rotation *= Quaternion.Euler(0, Mouse_X, 0);
Ty man, with a little twisting I got it fixed! I owe you a beer ❤️
Hi, is anyone free to help me go through some issues im having. I am using the new input system and using the rebindUI sample from it but the keybinds aren't being preserved across scenes.
I have a mainmenu with a settings gameobject where the rebindUI is set up, but upon saving it, it doesn't seem to change the controls when i start the game and move to the next scene
that will depend on the details of how you're managing input and how you are managing the instances of the input asset in your game
The basics are that rebinding applies only to the exact instance of the inputactions asset that you apply them to.
Any other instances will not be affected
If you are using for example the generated C# class, every time you create an instance of that with new(), that's a totally separate instance.
Hey, Is it necessary to write this here?
Hey, so I have this code reading the state of a button:
ButtonOne.performed += ctx => _buttonOneValue = ctx.ReadValue<float>();
which works fine. How can I have that call a function also?
What do you mean by How can I have that call a function also?
So, I want to run a function within this class when the button is pressed, as well as saving the value of that button. Eg I want to:
set buttonOneValue
and run ButtonOne();
I'm new to " =>" and don't really know how it works, can I insert running that function in there somehow? Very nooby soz
Aaah okay
So from my perspective (Webdev) the ButtonOne.performed has a type of void which is used to execute pieces of code, and it also gives you the context, like you named that variable
I'd rather not monitor the value of buttonOne for changes then call of the function like that
The += value just gives you the value of the action, and the part after the => is the callback part, where you can use the left hand side variable(s), in this case the context, to execute commands.
So in your case, you want to store the value and also execute a function.
You could make another function that handles all that, or put the set buttonOneValue, into your ButtonOne() function to handle.
(I'm still learning this system, so if my explanation is wrong then feel free to correct me :D)
I mean, if you dont want to monitor it's value, there's no way you'd know when does it change
In my implementation, I made a variable that tracks the state of said button, and in the Update method, I just call the function that handles the logic with that variable
So like:
_inputController.PlayerMovement.Movement.performed += i => _movementInput = i.ReadValue<Vector2>();
}
Update() {
FunctionThatHandlesMovementInputStuff();
}
FunctionThatHandlesMovementInputStuff() {
if this then go forward
}
ok, I was considering doing it like that but thought maybe there was a clearer way to call that function from within the event as well as setting the value
rather than setting the value in the event and checking that value for changes every frame
Well, in this case, the inputController will automatically update the value
That's why I dont call a function inside the performed =>, but a variable change
ok thanks, I'll do it like that
Hey, I just finished doing my rebinding system with the new input system. However, when i'm with my controller, and when i'm selecting any rebinding button with my joystick, when i'm pressing A (buttonSouth), it opens my rebinding panel, and selects instantly the A button for the input, i really need to just take the A to open, and press again A input, if i want the A to be the input. So my question is, how can i fix that?
Oh hi @boreal ruin , I'm here exactly with the same issue XD
lmao i know that feeling, i've another one but i think i can fix it by myself
Here's the code I call in LateUpdate just after rebiding:
InputSystem.Update();
foreach (InputActionMap actionMap in UI.InputControls.actionMaps) {
foreach (InputAction action in actionMap.actions) {
action.Reset();
}
}```
But that code doesn't fix the problem, right ?
you should also call this after 'RemoveAllBindingOverrides' and 'LoadBindingOverridesFromJson'
it fixes gamepad issue for me
but I just found out that I get similar behavior with 'Esc' key when leaving the binding menu and this code doesn't fix this issue
nah, not my issue
aw okay
I don't think the code u gave just before could fix mine as well tbh
there's no link between loading from json and the issue i got
it's because for 'Esc' I'm closing the menu and restoring the state (user canceled) with either 'LoadBindingOverridesFromJson' or 'RemoveAllBindingOverrides'. This causes the 'Esc' key to repeat
oooh ok i see, well tbh i'm not a pro with input system 😂
the same as when rebiding gamepad keys repeats them
yeah probably
the Input System is nice, and even the rebinding mechanism is relatively easy to implement, but there are bunch of small issues like this input repeat
And it's in 1.6.3 and 1.7.0. I don't know how they missed it.
Yeah idk too, but i think some people on this server know that system better than us and could save us lmao
i hope
Do you know if this channel is monitored by someone from the Input System team?
i don't really know but actually i saw in the past that people answered people's questions
'kay, so now we wait I guess 🙂
@boreal ruin 'kay, so my 'Esc' problem was my own. It triggered only when rebinding functions were called on exit, but was not connected to Input System. So I guess my piece of code works then.
probably yeah x)
However, other issue is that 'value' type inputs on gamepad (sticks, triggers) get repeated on rebind no matter what. It's kind of by design, because after rebind the state of all input actions gets cleared and then value inputs are read on reinitialization and generate new event. It's an issue when you use value inputs as buttons (triggers), or for navigation in menus.
U mean that if u rebind the button east of the gamepad, u cannot go back again with button east when u navigate the menus? i don't really understand
If I rebind UI/navigation/down to <Gamepad>/leftStick/down, then just after rebind the UI will move selection down.
If I rebind UI/navigation/submit to <Gamepad>/rightTrigger, then just after rebind UI will trigger another rebind on the same action.
oh really?
wtf
I'm not using UI navigation rebinding tbh, i let it as it's given by Unity directly
I think it's common in every game
I want to use same input for ui navigation and movement, more user-friendly IMHO
I think like if someone with disability wants to rebind all inputs to one side of the gamepad. It's nice if this works for UI also
Hi, how can I create a Text Input action in the new Input system?
what does "Text Input action" mean?
it means I want to create an input action which takes in TEXT
how would that work?
I ask it for a string value and it gives me the characters entered on the keyboard on the current frmae
something like that? if that exists in this system
or a list of Keycodes maybe
I don't see how the old input system would help you
This is my recommendation
Hi
Exist a function similar of "KeyDown" in the new input system?
.WasPressedThisFrame
Ok
Or you can use .started from CallbackContext
You're gonna need to disable your own bool from that though
How am I know this device is using in this moment?
You generally don't need to
I have a question... with the new Input System can i use controller buttons and joystick to simulate a virtual touch screen? i made this terrible doodle with the Playstation 4/5 Controller as touch inputs for visuals, because that might be helpful to kill 2 birds with one stone!
But i need it
The image looks like you want virtual joysticks and buttons using a touchscreen, which is the opposite of your question. Which is it?
ah my bad for the explanation, my question is... can i use the controller inputs like the joystick and buttons and convert it to virtual joystick and buttons as touch screen because few mobile games use "controller virtual inputs" lemme find a pic of a game
@verbal wolf you want to create a separate mobile app that would trigger touch inputs in other app, based on controller inputs?
not really? imagine this.. few tablets got a keyboard support like the iPad for example yea? that support keyboard inputs in that game for example, so i've added the keyboard input first, then the last 2 device controls are left, touch and controller inputs in the same game, so i was wondering is it possible i can kill 2 birds with one stone to merge touch as virtual controller inputs and controller inputs altogether to save time? but when a controller connects to that game, the touch hud goes invisible, that is my question, also side note: i'm pretty new to this input system, just watched one of Samyams video about it and also taking a break to take info slowly
also the touch input works exactly as the controller
basically a cross-input game support EDIT: sorry if the message is rushed, my head is all over place due to over learning unity
So I would assume (never did it myself, I'm more of PC/consoles guy) that the touch interface (like from the screenshot) is done using UI buttons and such. Those buttons trigger some logic in your game, and this is almost entirely outside of the Input System (only the raw touch input comes from it). What you probably want to do is just trigger the same logic based on controller inputs coming from the Input System. There will be some additional code needed, but not much, and probably a lot less than trying to trigger UI buttons based on the controller input, especially if those buttons will be disabled/hidden (because this is what you want to do when you detect a physical controller).
ah i see now, so i need to add it's own control scheme like the touch input itself without relying on the controller scheme? if so thank you for the answer 🙂
oh yea i forgot to mention, i'm focusing my games mostly on the apple ecosystem, So that's Mac (Keyboard), touch devices but some people might want a controller support
so, I am trying to make a 3rd person controller with cinemachine and input system, but, it's not working, could anyone help?
hey i saw your code, yours is similar to my FPS controller from SamYam tutorial but the [SerializeField] private InputActionReference variables is a thing i've never seen before but i can give you the code without worrying it 🙂
public class PlayerController : MonoBehaviour
{
[Header("Jump and Gravity Setiings")]
[SerializeField] private float playerSpeed = 2.0f;
[SerializeField] private float jumpHeight = 1.0f;
[SerializeField] private float gravityValue = -9.81f;
private CharacterController controller;
private Vector3 playerVelocity;
private bool groundedPlayer;
private InputManager inputManager;
private Transform cameraTransform;
private void Start()
{
controller = GetComponent<CharacterController>();
inputManager = InputManager.Instance;
cameraTransform = Camera.main.transform;
}
void Update()
{
groundedPlayer = controller.isGrounded;
if (groundedPlayer && playerVelocity.y < 0)
{
playerVelocity.y = -0.1f;
}
// Our Player Movement!
Vector2 movement = inputManager.GetPlayerMovement();
Vector3 move = new Vector3(movement.x, 0f, movement.y);
move = cameraTransform.forward * move.z + cameraTransform.right * move.x;
move.y = 0f;
controller.Move(move * Time.deltaTime * playerSpeed);
// if (move != Vector3.zero)
// {
// gameObject.transform.forward = move;
// }
// Changes the height position of our Player!
if (inputManager.PlayerJumpedThisFrame() && groundedPlayer)
{
playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
}
playerVelocity.y += gravityValue * Time.deltaTime;
controller.Move(playerVelocity * Time.deltaTime);
}
}``` i know this is a FPS controller but it should work atleast with the third person due to cinemachine
also have a input manager script maybe this will work?
{
private static InputManager instance;
public static InputManager Instance
{
get
{
return instance;
}
}
private PlayerControls playerControls;
private void Awake()
{
if(instance != null && instance != this)
{
Destroy(this.gameObject);
}
else
{
instance = this;
}
playerControls = new PlayerControls();
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
private void OnEnable()
{
playerControls.Enable();
}
private void OnDisable()
{
playerControls.Disable();
}
public Vector2 GetPlayerMovement()
{
return playerControls.Player.Movement.ReadValue<Vector2>();
}
public Vector2 GetMouseDelta()
{
return playerControls.Player.Look.ReadValue<Vector2>();
}
public bool PlayerJumpedThisFrame()
{
return playerControls.Player.Jump.triggered;
}
}```
also have you made your "WASD" controls with these composite
Yes I have, I’ve gone to work so I will try your solutions when I am home, thanks a bunch 👍
no probs!
You can use OnScreen controls. It's a built in part of the input system
Is that like a script component if I remember correctly?
Yep just saw the docs thanks
I’ll check that tomorrow, thanks for the info tho!
How can detect the button of the device that pressed?
Hey, how can I detect in another script, when a rebind is complete ? Because i cannot add an other script in "RebindActionUI" script
hey, ive been stuck on this for a while now, i really cant seem to figure it out. basically i want to add on-screen controls to my game, and they just aren't working right. in this very simple example i have an on-screen stick that is for the left stick on a gamepad, i have a gameobject with a simple script that moves it based on the move action in the defaultinputactions. EventSystem is also set to defaultinputactions
when i try dragging the stick it seems to be constantly switching control modes on the object, so turning auto-switch off makes the stick work, but it doesnt control the object anymore...
Hi
Why i can't play with a gamepad if this is connected?
The schemes the controls is the following way
Please
how to add the 3rd on screen stick, apart from left and right gamepad sticks, i am using android stick but somehow not working, what am i doing wrong?
How does making a Run Control work? i've added a Shift and Press Left Joystick to make the character run but didn't work, it says "Cannot Read Vector2 because control is a Float" here is the script, i'm basically copying the Move method to the Run method, here is the script
```private void PlayerMove()
{
// Our Player Movement!
Vector2 movement = inputManager.GetPlayerWalk();
Vector3 move = new Vector3(movement.x, 0f, movement.y);
move = cameraTransform.forward * move.z + cameraTransform.right * move.x;
move.y = 0f;
controller.Move(move * Time.deltaTime * playerWalkSpeed);
}
private void PlayerRun()
{
// Our Player Movement!
Vector2 movement = inputManager.GetPlayerRun();
Vector3 move = new Vector3(movement.x, 0f, movement.y);
move = cameraTransform.forward * move.z + cameraTransform.right * move.x;
move.y = 0f;
controller.Move(move * Time.deltaTime * playerRunSpeed);
}```
then the input manager script
{
return playerControls.Player.Movement.ReadValue<Vector2>();
}
public Vector2 GetPlayerRun()
{
return playerControls.Player.Run.ReadValue<Vector2>();
}```
Also the original script belonged to the Unity Docs of CharacterController.Run lemme find a link for the script
https://docs.unity3d.com/ScriptReference/CharacterController.Move.html
anyways the regular Movement i forgot rename to walk is Vector 2 Value and Run is a button, but i don't want my character to run all the time, i want to add a toggle to run and then walk again.
Run is a button action in your setup, why are you trying to read Vector2 from it?
public bool GetPlayerRun() {
return playerControls.Player.Run.ReadValueAsButton();
}```
it's a button, it's either pressed or not pressed
Oh I see, I’m trying to a make toggle run
okay i've checked the code you've given me somehow there isn't "ReadValueAsButton" somehow in the InputManager Script? i might aswell give you the whole script for full context. this is the Input Manager Script for the gameObject to make our inputs work ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InputManager : MonoBehaviour
{
private static InputManager instance;
public static InputManager Instance
{
get
{
return instance;
}
}
private PlayerControls playerControls;
private void Awake()
{
if(instance != null && instance != this)
{
Destroy(this.gameObject);
}
else
{
instance = this;
}
playerControls = new PlayerControls();
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
private void OnEnable()
{
playerControls.Enable();
}
private void OnDisable()
{
playerControls.Disable();
}
public Vector2 GetPlayerWalk()
{
return playerControls.Player.Movement.ReadValue<Vector2>();
}
public Vector2 GetPlayerRun()
{
return playerControls.Player.Run.ReadValue<Vector2>();
}
public Vector2 GetMouseDelta()
{
return playerControls.Player.Look.ReadValue<Vector2>();
}
public bool PlayerJumpedThisFrame()
{
return playerControls.Player.Jump.triggered;
}
public bool PlayerInteractedThisFrame()
{
return playerControls.Player.Interact.triggered;
}
public bool PlayerTriggeredThisFrame()
{
return playerControls.Player.Trigger.triggered;
}
}```
and this code reference to the PlayController script on top but with it's variables had to make the code small due to nitro...```[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
[Header("Walk and Run Settings")]
[SerializeField] private float playerWalkSpeed = 2.0f;
[SerializeField] private float playerRunSpeed = 6.0f;
[Header("Jump and Gravity Setiings")]
[SerializeField] private float jumpHeight = 1.0f;
[SerializeField] private float gravityValue = -9.81f;
private CharacterController controller;
private Vector3 playerVelocity;
private bool groundedPlayer;
private InputManager inputManager;
private Transform cameraTransform;
private void Start()
{
controller = GetComponent<CharacterController>();
inputManager = InputManager.Instance;
cameraTransform = Camera.main.transform;
}```
What do you mean there isn't "ReadValueAsButton"?
I was saying to rewrite your GetPlayerRun like this: #🖱️┃input-system message
i just typed in the exact thing unless i haven't saved my input in a rush... lemme double check
You're still trying to make it a Vector2 which makes no sense
and... what happened? Where did you type it? Show your code and errors if you have any.
here's the text info it's saying and highlighted red
checking the input actions and it's main script now.
oh my bad apparently that's only on CallbackContext and not InputAction, I swear it was there. Anyway you can do this:
public bool GetPlayerRun() {
return playerControls.Player.Run.IsPressed();
}```
thank you i'll let ya know! trying it now EDIT: okay the input manager script is happy but imma sleep now thanks Praetor
changed it to a better version.
Hi
Question
The new input system is compatible with the webgl?
With the games of browser?
yes
it works with all platforms
ok
{
// Our Player Walk!
Vector2 movement = inputManager.GetPlayerWalk();
Vector3 move = new Vector3(movement.x, 0f, movement.y);
move = cameraTransform.forward * move.z + cameraTransform.right * move.x;
move.y = 0f;
controller.Move(move * Time.deltaTime * playerWalkSpeed);
}
private void PlayerRun()
{
// Our Player Run!
Vector2 movement = inputManager.GetPlayerRun();
Vector3 move = new Vector3(movement.x, 0f, movement.y);
move = cameraTransform.forward * move.z + cameraTransform.right * move.x;
move.y = 0f;
controller.Move(move * Time.deltaTime * playerRunSpeed);
}```
Okay day 2 of this problem, Input Manager script is happy which is good.
But the Player Controller script is not happy i've tried to replace all Vector2 and Vector3 with bool within the PlayerRun() method but still not happy also it cannot convert bool to Vector2.Unity, here's the thing i'm confused about, and here how i think my run method should be.. My run method should be the same as PlayerWalk() method but with double speed which i'm confused about plus it is in the 3D space so Vectors make sense really for this?
i'm gonna re learn vectors again...
also the tutorials i've used are SamYams by the way but i've twisted into my own, from what i've Known via learning Unity Courses.
You seem to be massively overcomplicating and or overthinking this
yea this is my first time to think and create my code from my knowledge without relying on tutorial hell
You should have two action:
The movement direction action which is a Vector2, and the run actions which is a button aka bool
All you need to do is take the move direction and multiply it by your current movement speed
The movement speed is different depending on whether the run button is pressed or not
E.g.
void Update() {
Vector2 moveDir = inputManager.GetPlayerWalk():
float speed = InputManager.GetPlayerRun() ? run speed : walkSpeed:
moveDir *= speed;
// then do the movement
}```
Walk and run should not be totally separate functions like you have
Not even sure how that'd work
alrighty i'm gonna try that soon or something i'll let ya know, also how do i "learn" C# by using Unity Docs or watch basics video to learn but not to follow?
I think learning c# through this is better if you purely want to learn C# https://dotnet.microsoft.com/en-us/learn/csharp
thank you praetor once again!
UI dpad on Steam Deck
for the new input system how do i tell if a controller is being used
hey man i've figured and deciphered your code as a challenge and using youtube references, it works THANK YOU MY MAN!
I still would like help on this if anyone knows
Hey there I have a small question about the new input system.
So my game has JumpStarted and JumpCanceled methods which get called by respectively pressing and releasing the jump button, through events using the new input system. This works fine in most cases.
However, let's say I am in the pause menu and then release the jump button which calls the JumpCanceled method and then unpause the game. As I've already released the jump button, the code from the JumpCanceled method will not be called. Is there anything I can use to fix this using the new input system?
A few possibilities...
- don't disable the jump action when paused, simply check if the game is paused in the performed handler
- make and subscribe to an unpause event from the jump handling script
It kinda depends on what happens inside JumpCanceled
Alright, I'll try it out. Also, is there any way to check if a button is being held down using the new input system?
Sure. IsPressed() on the InputAction
Thx
Anybody know if there's something like InputActionReference that works with addressables?
Wdym by "works with Addressables"?
InputActionReference uses a reference to the asset itself, but if the InputActionAsset is stored with addressables you'll get a separate asset than the one stored in addressables, hence why addressables have AssetReference.
But if I use AssetReferenceT<ActionInputReference> I don't get the nice selector that InputActionReference has:
I don't think AssetReference<KnkutActionRefence> would even make sense because InputActionReference is not an asset
The actual asset is the InputActionAsset
You could probably write your own custom struct or class pretty easily that consists of an AssetReference<InputActionAsset> alongside a actionmap/action name path
Wouldn't be hard to write a simple custom property drawer for it that gives you a nice Dropdown
yea, that's what I was thinking too, but figured I should check if there was something built in for it first
Not that I know of
I got this problem, i've copied this code for making a head bob script and adding the new input system but it say's no object references about it, but somehow it works with the legacy input system which is odd?
here is the script paste bin with comments and the error code line image with the player triggers and player camera components.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
You have this inputManager field that is private and you never assign it anywhere
Naturally such a field will always be null
ah i see welp time to make it public
When you try to access this null reference, you will of course get NullReferenceException
I would expect such a thing to probably be a singleton or something
speaking of it is a game object singleton since i watched one of samyam tutorial if i remember
lemme find the tutorial
Learn how to use Cinemachine and the new input system to make a First Person Controller in Unity!
ᐅGet the full Source Code Bundle to my Unity Tutorials 🤓
https://sam-yam.itch.io/samyam-full-source-code-to-all-videos
**DO THIS ► There is an easier way to override the old input system values in cinemachine using the Cinemachine Input Provider (...
Then access it via the static instance reference
gotcha
That's the point of it
thank you once again Praetor, but now i feel like a kid where the teacher guides me ha ha ha!
Let's say map like this:
_playerInput.actions["Game/Toggle Console"].performed +=
GameServices.ConsoleKeyInputsTemp.InputToggleConsole;
How can I clear all .performed first?
_playerInput.actions["Game/Toggle Console"] has no setter so I'm not sure, can't just overwrite it
whatever.performed = null; should work, no?
Nah, that's the thing, no setter:
that's by design, c# events don't guarantee much about the implementation of the event except that you can subscribe and unsubscribe, so you just have to make sure you unsubscribe everything you subscribe yourself
if you want it to act like a list, you can make your own list of delegates and invoke those when peformed happens, then you can clear it whenever you like
Ah okay, so I guess the best way to go about this is just have an OnDestroy that unsubscribes and that's it?
advantages vs disadvantage between both?
Those derive directly from what it says in that picture
Whether they are pro/con in a particular situation is for you to decide
I have a specific case where I want to update my scene on a different interval than the display interval, so I've moved all the logic from my "Update" to "FixedUpdate". Is there a way to make the input system work this way? A way to make it gather the input press and delta values between "FixedUpdate" calls so we can read them normally on "FixedUpdate"?
Nvm, I guess I just found it
Hey all,
I was wondering how one might be able to set up the Switch Pro Controller to swap the A and B buttons within setup. Since the A button is on the East side and B is South I would like to accomodate that on PC. I tried to set up a specific control scheme for the Switch Pro controller but it falls back to the Gamepad configuration. Is there a way to check and force it to the Switch Pro configuration?
Edit: Found my issue. In my PlayerInput component for the prefab it was set to default to Gamepad. Yesterday when I was trying to set it to Any I would get a null reference issue. I'm not sure why I was getting that but I did revert my changes and try to re-implement. Once I re-implemented and set the the PlayerInput to Any it now works as expected.
if I have this set up to allow the user to drag the screen around, is it possibly interfering with other touch events?
I have this other component that isn't receiving mouse clicks or touch input, but the other UI buttons in it are
public class TextWordClick : MonoBehaviour, IPointerDownHandler```
Unrelated
Probably something is blocking it
it looks like I didn't need the press event at all, getting rid of it made no difference, sweet
is there a good way to check what's blocking it?
The press interaction is useless yes
Quick way is disable everything and slowly enable until it works again
Or vice versa
You can do some tricks with the event system too
kk, cheers
I'll try to figure it out
odd, but this was the only thing that worked in the end:
void Update()
{
if (!gameObject.activeInHierarchy)
{
return;
}
if (Input.GetMouseButtonDown(0))
{
int linkIndex = GetLinkIndex();
if (linkIndex != -1) // Was pointer intersecting a link?
{
Debug.Log("Link index: " + linkIndex);
}
else
{
Debug.Log("No link");
}
}
}```
and once it had a camera it works 😄
macOS Sonoma 14.2 and 14.2.1 Clicks on window not working at all, does anyone know how to fix this? I have clients complaining 😦
Hey there, according to the Unity Documentation for the New Input System, Input events get called right before the Update function. This also means they're called after the FixedUpdate function. Is there any way to change it so they happen right before the FixedUpdate?
Thanks!
for anyone else having this updating to the latest LTS reemoved the issue
Does anybody know what to do with issues with the new input system on mobile where it constantly swaps between control schemes? (e.g. Touch and Gamepad with On-Screen controls)
I probably wouldn't bother too much with control schemes for a mobile game
The issue is that it's interfering with the input, I'd have loved not to bother with it 😅
Control schemes aren't added by default. I would remove all control schemes you created
To clarify, I'm referring to what is displayed here at the bottom, when I define buttons for the player I have to define what devices I intend to use, which I have specified to be Gamepad and Touch. The issue here is that even when I use the Gamepad it constantly swaps between Touch and Gamepad
@austere grotto
if i wanted to use one script to detect an input from the player that isn't on the player how would i do this?
You can use events, not sure whether this is best practice or not but you can invoke them from within your player's input function.
I'm very new to this input system so ty
e.g. Define a UnityEvent variable and invoke it in the player script. Subscribe to that event wherever you want and add a listener to it, then define a new function that will be called when you would invoke it.
I'll try this and get back
Well it looks like your PlayerInput is disabled. You should enable it.
no dw about that, im working with netcode and i have a whole system setup, some stuff should be disabled by default and they get enabled upon instantiation. The rest of the input system works but the pause menu
What exactly isn't working?
pausing?
yea
there's no Pause action here #archived-code-general message
If you don't have that action map enabled it's not going to work
You have Player as the default map
how do i switch it through code?
you have that here _playerInput.SwitchCurrentActionMap(pauseMenuUI.activeSelf ? "UI" : "Player");
I feel like you would want a pause action in BOTH maps though,no?
You want to pause from the game and unpause from the pause menu
true...
lemme try adding it to the player map
Alright so there's progress
now the pause menu is repeatedly getting turned on and off ("HandlePausing" function is called from Update)
fixed that, but pressing the pause button from the pause menu doesnt unpause
My previous problem's been fixed, now how would i replicate the functions of GetButton, GetButtonUp, and GetButtonDown using the new input system, i have a script that uses all three of these and I'm not sure on how to implement it
My console is also getting bombed with thess errors which doesn't make sense to me:
InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
UnityEngine.Input.get_mousePosition () (at <963c3a1707f0469aac8b8356a8d18b5d>:0)
UnityEngine.UI.MultipleDisplayUtilities.GetMousePositionRelativeToMainDisplayResolution () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/MultipleDisplayUtilities.cs:40)
UnityEngine.EventSystems.BaseInput.get_mousePosition () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/BaseInput.cs:75)
UnityEngine.EventSystems.StandaloneInputModule.UpdateModule () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/StandaloneInputModule.cs:178)
UnityEngine.EventSystems.EventSystem.TickModules () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:452)
UnityEngine.EventSystems.EventSystem.Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:467)
InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
UnityEngine.EventSystems.BaseInput.GetButtonDown (System.String buttonName) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/BaseInput.cs:126)
UnityEngine.EventSystems.StandaloneInputModule.ShouldActivateModule () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/StandaloneInputModule.cs:227)
UnityEngine.EventSystems.EventSystem.Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:474)
Click on your EventSystem GameObject in the hierarchyand look at the inspector for your Input Module component
ty for that, do you have any fix for my first problem?
It depends which workflow you're going with https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/manual/Workflows.html
if you're using the PlayerInput component your simplest option is to put it in "Use UnityEvents" mode. Then set up your events and you can add listeners like this:
bool isPressed = false;
public void MyListenerFunction(InputAction.CallbackContext ctx) {
if (ctx.performed) {
// this is like GetButtonDown
isPressed = true;
}
else if (ctx.canceled) {
// this is like GetButtonUp
isPressed = false;
}
}
void Update() {
// You can use a bool variable here set from the above things
if (isPressed) {
// This is like GetButton
}
}
Another option is to directly do things in update:
void Update() {
// OR you can directly check things here:
if (myPlayerInput.actions["ActionMap/ActionName"].IsPressed()) {
// like GetButton
}
if (myPlayerInput.actions["ActionMap/ActionName"].WasPressedThisFrame()) {
// like GetButtonDown
}
if (myPlayerInput.actions["ActionMap/ActionName"].WasReleasedThisFrame()) {
// like GetButtonUp
}
}```
if i were to use the second option, instead of doing myPlayerInput.actions, could just use InputActionReference?
yes
Just make sure if you do that you enable the action
ok ty
nvm I'm still a bit confused on how to aplly this to my code specifically, here it is:
public IEnumerator JumpCo(float spriteHeightForce, float heightForce)
{
isJumping = true;
float jumpStartTime = Time.time;
AnimationCurve startingspriteHeightCurve = spriteHeightCurve;
AnimationCurve startingHeightCurve = heightCurve;
while(isJumping)
{
float jumpCompletionPercentage = (Time.time - jumpStartTime) / jumpDuration;
jumpCompletionPercentage = Mathf.Clamp01(jumpCompletionPercentage);
if(Input.GetButton("Jump"))
{
spriteRenderer.transform.localPosition = new Vector3
(0, startingspriteHeightCurve.Evaluate(jumpCompletionPercentage) * spriteHeightForce);
entityHeight = startingHeightCurve.Evaluate(jumpCompletionPercentage) * heightForce;
}
if(Input.GetButtonUp("Jump"))
{
break;
}
if(jumpCompletionPercentage == 1f)
{
break;
}
yield return null;
}
isJumping = false;
}
Just like in my second example (or like that but with the InputActionReference)
the thing is, it says action contains no definition for IsPressed()
what version of the input system are you using?
1.0.2
ooh - why that's super old
in that version you would have to do .ReadValue<float>() != 0
that's weird why that was the option that came up
for the version
what's the latest one?
what version of Unity are you using
the latest version is 1.8
well 1.7.0 realistically
1.7 should be available on anything past UNity 2019.4
ah you're on an old tech stream release
You should upgrade to 2021.3 LTS
will i have to change my project in any major way?
shouldn't have to
ok ty
i do this in unity hub right?
yeah - install the new version then open the project with that version
Do i restart unity hub when the blue bar is full?
i's still greyed which makes me think it's not finished but it's been like that for a minute and the blue bar is full for installation
Wait till the editor version finishes installing then you change the editor version for the project from this dropdown
If i restart unity hub will it restart the download progress
looks like this
and i am now also realising i have an ancient version of unity hub too
ok updating unity hub made it download properly
my code doesn't seem to be working
i think it might be because of this
I wasn't sure what you meant by this
how would i do it?
call .Enable() on it
show the code
public void Update()
{
if(jump.action.WasPressedThisFrame())
{
Jump(false, spriteHeightForce, heightForce);
}
}
public void Jump(bool isExtreme, float spriteHeightForce, float heightForce)
{
if(!isJumping && onFloor)
{
StartCoroutine(JumpCo(spriteHeightForce, heightForce));
}
}
public IEnumerator JumpCo(float spriteHeightForce, float heightForce)
{
isJumping = true;
float jumpStartTime = Time.time;
AnimationCurve startingspriteHeightCurve = spriteHeightCurve;
AnimationCurve startingHeightCurve = heightCurve;
while(isJumping)
{
float jumpCompletionPercentage = (Time.time - jumpStartTime) / jumpDuration;
jumpCompletionPercentage = Mathf.Clamp01(jumpCompletionPercentage);
if(jump.action.IsPressed())
{
spriteRenderer.transform.localPosition = new Vector3
(0, startingspriteHeightCurve.Evaluate(jumpCompletionPercentage) * spriteHeightForce);
entityHeight = startingHeightCurve.Evaluate(jumpCompletionPercentage) * heightForce;
}
if(jump.action.WasReleasedThisFrame())
{
break;
}
if(jumpCompletionPercentage == 1f)
{
break;
}
yield return null;
}
```
ok
!code
📃 Large Code Blocks
Use 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 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.
a powerful website for storing and sharing text and code snippets. completely free and open source.
Ok and show the inspector for your script?
ok
make sure the input is being detected
but the rest of the code is running?
Let me check, it's hard to tell without the jump.
it actually isn't
it's not working properly
which is weird
Again, in the screenshot your script is not actually enabled
so I would guess it has something to do with that
maybe your system for enabling them isn't working
that was just me being an idiot lmao, i had the script disabled because i thought it was what was bombing my console but i figured that problem out
Do you know one example project using Input System and UI Toolkit ?
I want to control my UI with gamepad, I can't figured it out.
The navigation seems to work (focus change on buttons) but "click" doesn't work
Is it possible to set a binding to only trigger on press once (as opposed to multiple times when it is continuously pressed)?
Triggering only once is the default behavior
Yea, I now think I just probably addressed that wrong in my code, thanks for the heads up!
Only the panel receives the SubmitEvent. The button, although it is the target of the event, does not receive it.
Do i ask questions about steamvr plugin inputs here?
I dont think unity is recieving input from it despite following everything in a guide
I am using steam link for quest
How do I make a virtual cursor that exactly matches the hardware cursor's behaviour 1:1? While keeping the hardware cursor locked and hidden.
I want the end user to feel like they're still using their mouse, but I have to keep the real mouse locked and hidden
Ive made virtual cursors, that part is easy, but I cant get it to replicate the 'gamefeel' of how the real OS cursor behaves (or at least my win10 one behaves)
is there any way to poll the OS or something for that data?
A quick question:
Has Unity fixed the Copy and Paste of actions/control schemes etc in the InputActions editor window?
I believe it was broken with the introduction of the project wide actions and the new UI they made/changed for it.
Should be fine, I dont have any issues copying duplicating moving or deleting actions, though im not sure which version that may have been patched on
For general functionality like left clicks, mouse delta, scrollwheel, etc you can use Mouse.current: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Mouse.html - though if a player disconnects their mouse for whatever reason, then that class could return null, alternatively you could also set it up through a input asset, unless your referring to something else when you say "game feel" - if the mouse is locked, even polling the OS would probably give you the same position, so youd likely need to work with delta/change in offset from the locked position and use the local or screen space position of some UI that represents your "cursor"
I have a action in the input system
type = value
control type = vector 2
with 1 binding:
Delta mouse
Im trying to use to get the mouse position using the input system
but when ever i try to debug log the vector 2 for this action it always returns (0,0)
I have also tried: mouse pos, pointer pos, and pointer delta and still all vector2's still read (0,0) no matter how much i move the mouse in the game scene in play mode.
if i put a binding for for other stuff like gamepad joystick under this action the debug log shows numbers correctly
what's the problem? am I doing something wrong?
I'm making an FPS type game for a number of systems, and I noticed that Cursor.LockState = CursorLockMode.Locked is not being respected on ChromeOs.
at some point Input.GetAxis("Mouse X") returns 0 because the cursor is at the edge of the screen so you can only turn left and right for as long as the cursor isn't touching the edges of the screen.
Does anyone know how to properly lock the cursos in ChromeOs?
yes, I turned off "Chrome Os Input Emulation".
Sounds like you didn't enable your input asset / input action
And if you want mouse position you should bind it to mouse position
Not Delta
Report it as a bug
Hi all. I listen to the mouse movements but I use it to move a virtual cursor and I perform my own raycast from that cursor. Is there a way I can disable the extra built-in raycast of the Event System that I think I have no use for (without completely disabling the mouse)?
Remove the event system or the raycasters
I would recommend using the event system though rather than building your own
I use the event system, just not the actual cursor built-in cursor which I lock at the center of the screen and hide. I can have up to 4 virtual cursors (local coop couch game). The mouse moves on of the virtual cursor and extra controllers the other three.
So for each "virtual" cursor I do this:
@austere grotto my input asset is in the scene and my action works fine with other bindings just not mouse ones
It's possible this is not the right way to do things but as it stands I have no use of the automatic raycast of the Event System from the cursor locked and hidden at the center
Input assets can't be in the scene.
They're assets
You'd have to show your code
And how it was hooked up to the input actions
my bad I was thinking about the input component
public class InputManager : MonoBehaviour
{
public static InputManager instance;
public Vector2 PointerPosition { get; private set; }
private PlayerInput _playerInput;
private InputAction _pointerPosition;
private void Awake()
{
if (instance == null)
{
instance = this;
}
_playerInput = GetComponent<PlayerInput>();
SetupInputActions();
}
private void SetupInputActions()
{
_pointerPosition = _playerInput.actions["PointerPosition"];
}
private void Update()
{
UpdateInputs();
}
private void UpdateInputs()
{
PointerPosition = _pointerPosition.ReadValue<Vector2>();
}
}
//in different script
private void Update()
{
Debug.Log(InputManager.instance.PointerPosition);
}
Show your PlayerInput
Also could be a control scheme thing
do you mean this?
for example my "Move" works just just fine i am just having trouble getting the "Mouse Position" binding under "PointerPosition" to work. If I put other bindings like a gamepad stick under "PointerPosition" instead, the debug log reads fine. but "Mouse Position" always reads as 0,0 with the debug log no matter how much i move my mouse while in playmode game scene.
It's because of your control schemes
Looks like you probably only include the keyboard in the scheme
I didnt realize you had to add mouse to the control scheme list... I thought keyboard meant kb + mouse....
that fixed it.
Thank you so much dude.
Hi Folks -
Total noob question here - apologies in advance, first time Unity user, long time 3D tools users.
Just trying to get my first 3D app running - I created a 3D scene and added a FirstPersonController for navigation. When I “play” my scene, I get only a grey background and I can’t seem to navigate around to find any of my simple (sphere) objects in the scene.
Recommendations? Troubleshooting steps? Resources for basic navigation? I'm doing something simple wrong I’m sure but this should “just work”.
Screenshots of my scene versus 'game' view in Play mode, is it obvious what's wrong?
Where's your game camera?
The game view sees out of your game camera
also unless you added some code or component to control the camera, the camera isn't going to move magically
I deleted the camera per a YouTube tutorial, doesn't "FirstPersonalController" replace that?
No?
You need a vamera if you want to render the game
What is "FirstPersonalController"? Does it have a camera as part of it?
FirstPersonController is a Unity package, per the instructions and description in this tutorial:
Let's make a beautiful open world in just 5 minutes! In this tutorial, we make a 3D world in Unity from scratch using the built-in terrain system.
····················································································
Unity Asset Store Links:
Modular First Person Controller: https://assetstore.unity.com/packages/3d/characters/m...
so it's some random asset
@austere grotto , thanks for your help. I added a camera but still same result - grey screen. I'll move it around in attempt to troubleshoot but its right at the center of the scene.
Just trying to create a very basic scene that I can navigate around, open to suggestions on the easiest/simplest way
It's unclear what's in the prefab
Added a cmaera to what?
Why don't you just open scene view when the game is running
to my scene
look at where your camera is
how would that make it controllable? It's just a camera floating htere
presumably you have a camera already but it was just not anywhere near your building
open Scene view when the game is running
and just look at where the camera is compared to the building
is this while the game is running?
Yes
ok looks like it can see the building
running, switching between view
as per the thumbnail there
Well if you added a second camera that one is probably rendering on top
Show your camera settings?
this doesn't seem like an inoput system problem btw
(agreed, if there's a better channel, lmk)
Only 1 camera AFAIK, here are the settings
there's no way there's only one camera
you have one inside your first person controller
you can type t: Camera in the hierarchy window search bar to find them all
Success! You were right, @austere grotto , I think that FirstPersonalController added a camera which screwed things up
Success! I can at least view the scene.
well I presume you want to use that First Person camera. It just wasn't in the right place. And you don't appear to have a floor/ground so it may have just fallen when the game starts running
True, I should add a basic ground. Would love your next steps/recommendations to do very basic navigation - just move around the scene on desktop and then Oculus/Quest. Thought that the FirstPersonController was the thing, I guess not.
Anyways thanks @austere grotto, appreciate your help in getting a noob over the learning curve.
You've enabled the events but not disbled them.
Depends on how you have it set up. Generally the OnDisable or OnDestroy if the object where you enabled them
It will be disabled, then destroyed, every time you change scenes (unless in DDOL or additive scene, which it sounds like you're using), and quit the application
I'm not saying YOU should disable or destroy it
The compiler doesn't know it.
Not really relevant. If OnDestroy isn't called, it isn't called.
The compiler just wants to see you've properly handled events
No one uses OnDestroy or OnEnable except unity itself.
They are Unity methods like Start, Update etc
Should, but I think you may have an issue with that null coalescing operator in OnEnable. Not positive though.
No reason using On destroy AND On disable
It's fine in this case because that's not a unity engine object
Ok, thanks for the correction
Keep disable
Advices before diving into InputSystem for my game
I can't figure out why won't this work
void OnWalk(InputValue value)
{
Debug.Log("Move Input");
moveTo = new Vector2(transform.position.x + (value.Get<float>() * Time.deltaTime * moveSpeed), transform.position.y);
if (value.Get<float>() > 0) transform.localScale = new Vector3(-1, 1, 1);
else if (value.Get<float>() < 0) transform.localScale = new Vector3(1, 1, 1);
}
as example the move code is this
I was using the old input system and at first wrote the code in unity 2017
when I got the project in unity 2022 character moved kinda messy but it was decent in unity 2017
and when I changed the code to the new system it won't even get any input
yea sorry I did that but didn't include in the text
I better edit
Hello, so I have a retry button on my game, at first it can only be clickable by mouse click, but after clicking it once, I can now trigger the same button with Spacebar, is it because I highlighted the button upon first clicking it?
Apparently switching between the game window and another window then going back to the game window fixes the problem
yes
you probably have keyboard navigation on, but maybe don’t have keys bound to actually move from one UI element to another
wot
check EventSystem. Not InputSystem
Ahh okay okay thanks
Does anyone know how to make the steamVR plugin work correctly? Im using Steam Link for quest 2 and i can map the inputs i made, but they dont actually function in runtime. Ive been struggling with this for a while, so any help would be appreciated
I need to be able to dismount a horse (Malbers Horse Animset Pro) using a button on a vr controller. I am using the XR Toolkit and plugin that unity provides and I am able to control the horse with the VR controllers but in the MInput component I see the dismount and the mount things and they are set to keys. If I switch the type to input and try putting in the name of the reference to the button on the controller it just tells me it has no idea what I am refereeing to. I am not trying to use the unity input system but instead the XRI Defualt Input Actions which allows you to use the VR controls in unity. I have spent hours upon horus trying to do this and I am new to unity and basically everything so I only kind of know what I'm talking about.
Hello everyone! Did anyone experience issue when changing the animation from mixamo to other mixamo animation and got warnings that the bone length does not match the position? I've switched from my idle animation to a new one, both from mixamo but I can't figure it out why I'm getting warning only for the legs. I've did this long time ago and as far as I remember, I did not have this issue. Now all the idle animation I use from mixamo i get this:
public void OnMouseOver()
{
if (EventSystem.current)
{
if (!EventSystem.current.IsPointerOverGameObject())
{
if (GetGamePlane())
{
if (!IsHovering)
{
IsHovering = true;
OnInteraction(InteractionState.BeginHover);
}
if (Input.GetMouseButtonDown(0))//Left click
{
OnInteraction(InteractionState.LeftClick);
}
if (Input.GetMouseButtonDown(1))//Right click
{
OnInteraction(InteractionState.RightClick);
}
if (Input.GetMouseButtonDown(2))//Middle click
{
OnInteraction(InteractionState.MiddleClick);
}
}
}
}
}
public void OnMouseExit()
{
if (GetGamePlane())
{
if (IsHovering)
{
IsHovering = false;
OnInteraction(InteractionState.EndHover); //This just invokes the event passing this and the state
}
}
}
I'm switching to InputManagerSystem on my prototype. It's an rts and these to method are handling the hidden hexgrid below the plane of the game. Right now it is working with the old input system but I have to think about a way to make a controller work. Since I either add a pointer that you control but that doesn't sounds intuitive for gamepad, or these methods are only viable for mouse and the controller user can only select 4directional input to navigate the plane. Any suggestion? Hope I was clear. Is EventSystem.current.IsPointOver working with new Input system too or should i find an alternative?
this just seems like you're recreating built-in Event System functionality
My recommendation is to delete this entirely and just use the built in event system and corresponding events
and for entering and exiting gameobject with mouse do IPointHandlers?
and handle gamepad differently?
As long as you have an event system in the scene and a PhysicsRaycaster, and the object in question has a collider, you can use the IPointerXXX and other event system interfaces, yes.
For GamePad I would use a virtual cursor from the new input system
I need to check it
which will work directly with this same system
Maybe I can use it for now, like a virtual mouse icon. But probably change the feel of the game
Kinda depends what behavior you want
I have to get a feel for it on the go i think. I'll go with virtual so both behave the same for now 🙂
with the new input system how can i tell if a controller is being used
because i setup a virtual mouse and i only want to activate it if a controller is being used
Hello, I have a problem with the InputAction.CallbackContext, it's in my script, but when I try to choose it on unity, there is not here, someone know why ?
You're asking about your function, not CallbackContext
The first thing to check is the console window to see if you have any compile errors
I don't have any
Problem solved, I was in the wrong event window
Hi, I have a strange problem with the new input system, if I touch rapidely the screen, it just set the press to 1 and then get stuck like this.
anyone know for this
If my eyes are seeing correctly, it look like there is some frame dropping right before the input is getting stuck
Anyone have an idea?
it also seem to affect only the editor, not in the build
i got an onclick event on an image - i have enabled raycasts for the target image and disabled all raycasts of children, but no event seems to be fired when i click an image... does anyone know why?
also there's nothing drawn ontop of the triggering image, i'm kinda clueless now
Do you have an event system in the scene?
Show the console window and the inspector for the event system
the method thats called on click currently only debug.logs a test message but isn't called at all
Ok I recommend leaving that event system inspector open while running the game and see what it says when you mouse over the image
ohh i just saw there are dev tools under the event system
yup that solved it
tyvm!
Is there a way to get these key names as int values through CallbackContext? I've tried ReadValue<int> and <float> but I only get 1 as a return;
input.Player.Hotbar.performed += ctx => Debug.Log(ctx.ReadValue<int>()); // How can I get 1, 2, 3?
I found it, ctx.control.name or .displayName
Hi, any idea about this? it's happening even on an empty project
Lots of people go down this rabbit hole for a while before settling on just making multiple Actions, one for each hotbar button. It will be much simpler
I see. Normally, this is exactly what I would do but it just seemed clunky. I’ll do this next time as it’s working for me
When you think about key rebinding and displaying key tooltips etc you'll understand 😜
Ahh I see. This is just for a game jam, so quick and dirty is fine, but I will defo keep that in mind
does anyone know why the new input system (version 1.3.0 on 2021.3.4f1) stops reading inputs when a script compiles? I don't like having to restart the scene when I make edits to my scripts. when i check the input debugger, it says input is still being recorded, but when I try reading it from a script it just stops working. also, the old input system still works (at least the mouse position reading does)
I want my game to properly support the Steam Deck. This means I need to be able to combine both joystick and gyro input.
the Deck is providing gyro input as mouse movement
If I make both Delta [Mouse] and Right Stick [Gamepad] part of the "Gamepad" control scheme (which includes a required gamepad and an optional mouse), I can indeed use both the mouse and the joystick in game...but it's not a great experience. It's very jittery.
I'm getting that input by doing action.ReadValue<Vector2>().
I already have the Delta [Mouse] binding set up to use cinemachine's DeltaTimeScsaleProcessor, which divides by unscaledDeltaTime so that I can scale both mouse and joystick input by unscaledDeltaTime later
(so that's not relevant)
I guess I'm just wondering how I'd sum up these two separate inputs properly. It looks like I'm only seeing one binding's value at a time when using ReadValue
I do need to do some testing though.
I could just use two actions, if all else fails
ah, actually: if I hold the joystick steady, then move the mouse, no joystick input comes in at all
only after the stick moves does it start turning again
This is working pretty well, but it's a nuisance!
I wonder if you could create a composite that combines the inputs from two bindings...
Im trying to use the virtual mouse cursor package example included with the new input system to make my own virtual cursor
but I cannot make heads or tails of Unity's code
what is critical that allows their virtual cursor to interact with canvas UI and how do I extract that into my virtual cursor?
their raw class is massive and full of comments that make it completely opaque and impenetrable, nothing just says what it does in a way that something dumb like me can comprehend. I need help
im not experienced enough to know what does what or what is neccessary and what is not, and ive tried to blindly delete my way through it, strip out everything until it only does the one and only thing I need to take from it, but it just keeps breaking long before I get there
and tutorials online didnt help to make a virtual cursor either
here is unity's code with most of the opaque comments stripped out
still trying to find JUST the parts that do what I need
it doesnt help that theirs is trying to multiple things all at once, like support both hardware and software mice
so I cant even tell what is related to which of the two mice
I cant even test any of it easily because it ONLY works if you use analog sticks, it wont react to the UI if you just drag the cursor object over top of the UI element
so I cant even remove any of that confusing code either
there's just too much shit in there making it impossible to understand, even though almost none of it relates to what I need or am trying to do or get from it 😿
I've glanced at that code and decided I'm going to look into it Later
and the game is a 3d game so im not sure if that has anything to do with it
any help is appriciated
I'm having trouble with my events not getting invoked depending on which other actions are active. In the worst case I found, I'm unable to walk diagonally forward-right (all other diagonal directions work..) and crouch. The event itself for the crouch action is never invoked at all while walking forward-right. This is the callback from the auto generated interface, no intermediate layer I might have messed up. It also works fine when I'm walking forward, or right, or forward-left or backward-right. Just not when walking forward-right. On the flip side, I'm also unable to walk forward-right while I'm already crouching (but I can walk in all other directions). What's the issue here?
I am trying to debug stuff related to the input system
but visual studio cant find any of the code related to the input system for some reason
when I hit F11 to advance in the debug, it brings up this frame not in module error
and its making it really hard to figure out why the code isnt doing what I think it should be doing because I cannot trace its full path
how do I fix the path/access/whatever is going on here?
I am extremely stuck trying to code this virtual cursor
ive started over from scratch fives times
ive boiled down every variable to the absolute minium essentials
and its just not working, nothing works as expected, it keeps doing all kinds of insane shit
and I dont comprehend any of it
and i desperately need help
and I feel like if anyone who was as desperate as I am for help came to me, I would drop everything and help them in an instant
but I dont ever command that kind of authority, that kind of human kindness in anyone else
ive never once felt like I can ask for help and am treated as a human being, I am treated as a nuisance, I get help only begrudingly, because I am annoying and they want me to go away, because I am saying or doing hurtful things
its so fucking frustrating to be stupid and useless and to KNOW im stupid and useless but still have dreams and goals and try my fucking hardest to achieve one tiny little flicker of greatness and nothing ever works
I really really really just need your help, you, your help
please help me with this
all i can do is beg and grovel and put myself down and do everything i can to deserve to be helped, to ingratiate myself
I need a virtual cursor, I need a cursor that is not the system cursor, that otherwise operates like a real cursor, in every possible way
i cannot get that to work
ive tried packages, ive tried the unity example asset
it just is wildly unstable, it suddenly stops working, it suddenly remaps itself
no actions are set yet it fires off actions
Once again, please stop going on these long monologues, you've been told this before.
If you're struggling with something, take a break. Try to find a tutorial. Try to clearly explain what you're doing, rather than posting Unity's own code. You shouldn't need to be diving into their locked scripts to use their features.
Have you tried any of these tutorials?
yeah the top one is the one I most heavily pulled on
And what's the actual issue, it's not moving? It's not registering clicks? It's throwing errors?