#🖱️┃input-system
1 messages · Page 54 of 1
two scripts attached to the same GameObject?
Awake shouldn't run twice 🤔
Oh wow, it is twice on the same object, but since there's a bunch of other components in between, I didn't spot them together
Mystery solved 😄
hey guys, could someone help me out, this should be easy but its somehow elluding me, I updated my script to make the movement relative to the camera, and it works great, but the portion that alligns the character to the groundnormal no longer works. I bet a million people have done this before, it probably obvious, what am I doing wrong? oh and also, target rotation and cameraY only rotate on the y axis, I tried making the normal move the x and z axis but this never worked
I am making a fps game in unity using a rigidbody for my movements. I have also added a freelook cam for my game, but the movement isnt realative to the angle of the camera. Is there any thing that can help me? I used a tutorial by Plai but this never worked out for me.
@winged patio For camera i would suggest you use CinemaMachine. It haaave a lot of stuffs.
it have free look mode, follow target and etc.
To make movement related to camera you need to pass camera rotation to your movement script and add it there.
most likely you want to pass only y rotation
ohk
wait it still doesnt work :((
Hey!
I would like to add a NumKeys for the new input system but using only one map. How can I do this?
Someone ? 😭
above the querty keys
&é"'(-è_çà = 1234567890
just put Input.Getkeydown("(number or symbol that you wanna put)"){*insert code here}
yes but with the new ?
?
new input system
it should work
hmm no
it should ork nyways
can anyone help me with my camera?
why doesn't it stop when i move my mouse all the way down?
It goes upside down for some reason
can I see your script?
well how do you expect me to help you if you don't give anything
ok ok ill do it
wait a sec im logging on to unity
idk if u can fix it
i dont understand it
the problem
i dont understand teh problem
Because you're not clamping xRot at all
You should clamp it between -89 and 89 or something
ok
its xRot -= mathf.clamp(PlayerMouseInput * sensitivity) right?
or is it for playercam.transform.localRotation?
FYI, New Input System gives you errors if you use the static Input class methods.
im not using it
idk
but it doesn work for me
ok clamping isnt working for me :((
sorry but i have NO clue on how to clamp it
how do i make a button pressed even after i clicked the screen
?
when i click a button it changes color, as soon as i click the screen it changes back. i wish for it to come to its original color AFTER i click a different button
I know, but you were telling someone else to use Input. Just pointing out that wouldn't work 🙂
you never enabled controls
where
i copied and pasted my code into gdl forgot to add that bit
Why not just paste the whole script
hard to help without all the context
Also you never explained in what way it's not working
What are you expecting to happen, and what happens instead
I managed to fix it, its basically meant to be a button that resets the scene
Also why this whole complicated thing with Update etc
just load the scene in the performed callback
uh im p terrible at c# so i find this easier to understand somehow
what you are doing:
- when button is pressed, set a bool to true.
- every frame check if bool is true, and load the scene if it is
The simpler way:
- when button is pressed, load the scene
I cant find a tutorial that explains it like that lmao, this is the only way i have managed to get it to work, ill try and find a more efficient way of doing it tho if thats how its working atm
Try experimenting outside of exactly what tutorials say sometimes
They are only meant to be educational, not as the only way or best or correct way to do something
I have been trying haha, I spent a good few hours before just nicking this
i get what you mean tho
hey thanks :))
So, I did some reading, and it seems that the new input system is pretty useless for handling mouse clicks in the game world if there is any clickable overlay UI - because it will still trigger the input system click callback even if I clicked on a UI button or any element that blocks raycasts.
It seems that the workaround is to use an invisible full-screen UI button, and when that is clicked, treat that as a click in the world, bypassing the input system.
Is this right, or am I missing something?
No.. it shouldn't work that way. UI should block events on things behind them such as 3D objects
As long as you're actually using the event system
If you're using a manual Raycast or OnMouseDown it won't work properly
how does the "Send Messages" work?
I have a button action for jumping but if I define a OnJump() in the MonoBehaviour attached to the same GameObject as the PlayerInputcomponent, it doesn't get called
already tried to make it public void OnJump() or public void OnJump(InputValue value), both dont work
@austere grotto All I can say is that it doesn't work that way for me. UI works just fine but if I click on a Button it'll fire off an event via the input system too.
2 comments on the forum suggest I'm not alone in this: https://forum.unity.com/threads/preventing-inputsystem-callback-on-ui-click.1091101/
I just thought of something while playing another game that does not allow the user to bind actions to button combos or hold/toggle.
Is that going to be a possibility for me to implement in my own game using the Input System?
For instance, in the game I am playing:
I want to bind "Open Inventory" to holding Y while "Perform Takedown" is pressing Y.
And I'd like to bind "Zoom In" to RS-Click + D-pad Up, and "Zoom Out" to RS-Click + D-pad Down, while pressing RS-Click by itself is bound to melee attack.
Oooooh! 🤩
I applaud whoever designed and implemented that.
I haven't tried implementing rebinding and the combinations of keys that you're asking about may be somewhat more complicated than a simple redirect to a new key binding
but its definitely implemented with rebinding in mind
Yeah. I knew that much. I'm just really curious about combos and holding.
There are "modifiers"... I wonder if they do what I want...
I'm fairly certain you can construct whole InputActions at runtime, so as long as you can make your binding with the InputAction GUI you should be able to do it via code. It may just be very complicated.
Yeah.
processors and interactions do the kinds of hold things you're asking about
I don't think you can do key combinations built in, so you would probably need to implement your own layer to handle that (or a custom interaction, I guess)
If someone has a config menu that uses these in their project, I'd love to see it!
I don't recall seeing very many games that allow users to rebind controls to combinations or use hold/etc in the rebindings. I think it is probably just more dev-time than it is worth for most games.
Show how you set things up
Or wait are you just saying that a click is detected in general? Or that a Pointer click event is happening
Because just detecting a click in general as in listening for an input action bound to the mouse, then yeah, that part is completely unrelated to the UI event system
Because that's what that forum post is about
The input system is unrelated to the event system. The only thing that ties them together is the UI Input Module
Does anyone know if there is a way to trigger a button's Click event on an input action? For example, press A on a gamepad and have the button appear to have been pressed. I can invoke the OnClick event easy enough, but the button art doesn't respond as normal.
This is an event system question not an input system question. #📲┃ui-ux
thanks for the heads up!
Hi Everyone, I'm struggling with the OnGUI event vs. the input system. What I mainly want to do is to detect hold/press action and get mouse/touch position.
I've researched several tutorials and documentation, and it seems like they both work for my case?Any suggestions on which one to use?
OnGui should only be used for IMGUI stuff which is the oldest of Unity's 3 UI systems.
It's an archaic way of dealing with input
Got it! Thank you so much~
hello, i have an problem in movement character that use new input system. the character cant be stand as I want when I press joystick for controller. I'm new in new input system unity, i confused where's the source of that problem. The movement when I press joystick be like this
I want the character stay stand when I do movement
My input actions like this
any idea? please help
Thanks for the response, but let me take a step back and try to explain from a more general position:
Usually, an application or game engine would detect a click in exactly one place and then forward it to systems in turn until it gets handled, at which point it normally stops.
I want Unity to do this, in that I want clicks on a UGUI button to not also generate an unrelated event via the input system.
I don't know how this relates to the event system - that has always been very badly documented (https://docs.unity3d.com/2020.2/Documentation/ScriptReference/30_search.html?q=eventsystem gives no results, and https://docs.unity3d.com/2020.2/Documentation/Manual/30_search.html?q=eventsystem only gives irrelevant results)
@zenith ivy , don't crosspost. #💻┃code-beginner.
Hello someone know new input system for mobile ?
When i swept my finger on the left my character moves on the left, the same on the right. What is the parameter in the input system to know if I swipe left or right on my finger?
https://media.discordapp.net/attachments/763502300781477948/923378533307408394/unknown.png
How can I check a Vector2 arrows simulteanous key press (Left and Right)? It returns the first value (key) pressed. If I press the other, it doesn't change.
I understand what you want. I don't know how other game engines handle it but in unity the UI event system (the thing that handles detecting clicks on UI elements etc) is downstream from the input system. The "click" is first handled in the input system and gets turned into a UI event by the UI Input Module. But this doesn't "consume" the mouse click from the input system.
This is apparently on their radar though https://forum.unity.com/threads/have-ui-consume-mouse-click.840013/#post-5552542
If you want this behavior you'll need to use a workaround like the "invisible button" thing or the "is mouse over GameObject" thing, or something else.
Event system documentation is here https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/EventSystem.html
Can anyone guide me in how to have a cursor with a controller? I dont want to use the system cursor since im using splitscreen
Just use a UI Image
@austere grotto Yeah! I need that multiplayer event system, now im trying to learn how the virtual mouse input class works. Thx ❤️
Input.GetAxis("Horizontal") equivalent in Input System? I googled but it seems whatever I do it's the same thing (-1, 0, 1)
Well, doesn't exist. I simulated the same effect. It's a bummer...
How do I prevent the keyboard+mouse and xbox controller from interfering with each other? If my controller is off it's ok, but when its on keyboard movement is altered.
create an action map for each and control which action map is active based on which input device you're currently using
sorry, action map is not what I meant
control scheme
you mean default scheme?
upper left corner
All Control Scemes
You want to make a keyboard control scheme and a gamepad control scheme
Yeah I have both
and specify which bindings belong to which scheme
I have a weird behaviour. I have a Better Jump script (really known video out there). And when I long press when Xbox Controller is as default scheme, sometimes it jumps higher, sometimes it doesn't
I actually spam "long press" and jumps the lowest jump. Then it somehow decides to do several high jumps for each long press
Ok nvm, I feel stupid. It was registering also the down stick movement, making it jump less. 🤦♂️
Hi, under windows gamecontroller configuration i got a controller with a slider that works there, but the output isn't recognized in the input debugger of unity. Any idea how to add this slider?
I know that this specific controller and slider works in unity, as other games support it, but those used rewired which uses the old Input
hi, for some reason, even though i have set up my jump to be on my dualshock's x button and my look to be on the right joystick, the look is done on the left joystick and the jump is set on the right joystick, even though my actions maps are explicitly set to the right joystick and the x button. how can i fix this?
hi, I'm completely new to unity and in the process of learning, and I heard it's best to keep anything input-related in its own class. How exactly does this work- how would I make certain inputs invoke certain methods, and is there any example code I could look at?
look up a tutorial on youtube, or the Unity Learn tutorial pinned in this channel
For some reason, using the debug input shows nothing out of the ordinary in the actions tab, which makes this whole thing even weirder. Also, is the debug window supposed to open when you point the right joystick down?
I should also point out that I am using DS4Windows, if that makes any sort of difference.
Ive been reading the Documentation and i just dont get it, can someone explain to me how i can increase the accuracy of GetAxis("Mouse X") to more than 0.05 steps ?
why did they even change it, didnt it use to be how many PIXELS the mouse has moved ?
I guess what im asking is what is the preferred way to do a camera look script in Unity 2020.3 ? Cause it feels like theyre trying to make it as complicated as possible
Hello, I've been using the new input system and I'm having a remarkably specific problem. Basically I'm doing this:
return action.GetBindingDisplayString(bindingIndex);
In a function to get a suitable binding name to display in the UI. Perfect. Only problem is, for some reason it returns the name in Italian. I'm Italian, but I think I have Unity set up in English, so...
For most keys, this isn't a problem, but for example with the "Spacebar", instead of "Spacebar", that line returns "Barra spaziatrice", which is "Spacebar" in Italian. Is there any way I can change this language setting thing?
So i recently changed the input system to the new one and turns out i have no idea how to work with it yet and i just want to make a basic movement so how do I revert back to the old input system?
unless someone has a good tutorial about the new one
You can change which version you're using in Player Settings.
alr thanks
how can i make a input cancel right after occurring , i am trying to make a dash but i cant make it work (2D). My problem is if u keep holding down the dash button u would keep dashing forever and the dash cooldown would only start when you let go of the dash
Use a Boolean value which toggles true and false based on the dash. Don't allow anymore dashing while isDashing = true.
the thing is the way my player moves is
hMove = context.ReadValue<Vector2>().x;
and the way I do my dash is setting hmove to a value
so do i have to change that
hmove is a float
No, you have to add a bool to your whole movement logic. Before you change the value of hmove, check if you're dashing.
Then set it to false when it's not. When you press the dash button, don't set it to true if, say, the timer that handles the length of the dash is still ticking.
my Dash is a whole other action so when I am done dashing I cant set the context back to readvalue , I am having trouble putting them under one action
my dash keeps going unless i let go of it how can i make it so it stop after a certain time or after a certain amount of movement
whenever I try to add a binding to the Logitech Attack 3, it switches control scheme to all devices. I try to make Input System Listen to a button and doesn't recognize it
no events
I've been trying to get the mouse position with delta and it never registers when i move my cursor, does anyone else have this problem?
show your setup
Why do you have Delta piinter and delta mouse
those are redundant
same with right stick/right stick gamepad
Input System can get kinda buggy when you have a lot of different bindings on a single action
aight i got rid of the redundancies
Anyway how are you trying to read/listen for this action in your code?
- Did you enable your
playerControlsobject? - Did you try
Valueinstead ofPass Through?
Where did you enable it?
And what is playerController? Seems unrelated
So I have two classes, one I attached to the camera that manages tilting and following the player
and I pass the playercontroller into the camera to get where to follow
i enable the playerController object at the top
Can you show the line of code where you enable playerControls?
not PlayerController
ok thank you
So if you put a Debug.Log in this OnLook method what happens
it never runs?
nope, never
if anyone has any advice, id really appreciate it since i can't move the camera otherwise
I want to an instance of an input system generated class to only record and report input happening when it happens on an specific control scheme. How can I achieve this?
Currently it raises events and .ReadValue<>() gives a value for every input scheme, doesn't matter if its keyboard and mouse or controller.
I want an instance of the generated class that only raises events when I use the keyboard, for example.
I'm not using the PlayerInput component and hope I don't have to use it later either.
if someone has the freetime to review my player movement code and help me figure out why my dash is sometimes short and sometimes longer in distance that would be great, been trying to fix it for the past 2 days I need a different set of eyes to maybe spot a mistake.
cant find any tutorials that do it with the new input system
just tell me and I will send u the code
go ahead
should i DM it to u ?
sure
I installed the input system package, but my input settings are looking so:
That's the old input manager. It's not used/useful anymore when you use the new input system
You can ignore that section.
But i am getting these errors
Upgrade your packages in package manager and delete your library folder
NOT project folder oops lol 😅
Also looks like your project folder is inside OneDrive?
That's probably not a good idea
It will probably cause issues
there is nothing to upgrade here
Delete your library folder and restart Unity
ok
still getting these errors
What version of Unity are you on
I found my issue thanks for the help
Does anyone know why in 2021.2 I am not allowed anymore to use 2D axis?
Or is that called 2D vector now?
the new input system isn't working for me, this is my code (some irrelevant parts removed, its a simple script that moves the camera):
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraScript : MonoBehaviour
{
public Controls controls;
private void Awake()
{
controls = new Controls();
}
private void Update()
{
Vector3 pos = transform.position;
if (controls.Game.Up.triggered) pos.z += 15 * (float)Math.Sqrt(pos.y) * Time.deltaTime;
if (controls.Game.Left.triggered) pos.x -= 15 * (float)Math.Sqrt(pos.y) * Time.deltaTime;
if (controls.Game.Right.triggered) pos.x += 15 * (float)Math.Sqrt(pos.y) * Time.deltaTime;
if (controls.Game.Down.triggered) pos.z -= 15 * (float)Math.Sqrt(pos.y) * Time.deltaTime;
transform.position = pos;
}
}
the .triggered doesnt seem to work, it always returns false
no errors, it just doesnt do anything, the script worked fine before i switched over
You have to enable your map or all action maps. Something like this:
controls.Game.Enable() for enabling Game action map or controls.Enable() for all the action maps. Do it in Awake() or Start after creating new Controls() instance.
Also if you have Input System 1.1 or above you have similar api to old input system — controls.Game.Down.isPressed for GetKey, controls.Game.Down.wasPressedThisFrame for GetKeyDown and controls.Game.Down.wasReleasedThisFrame for GetKeyUp.
ill try that
it works but triggered only checks when its starting to be pressed, and it does not recognize isPressed/wasPressedThisFrame/wasReleasedThisFrame
Yep triggered is for start only. What version of new input system you have?
1.0.2
Those 3 checks are only for 1.1 and above.
Yep, upgrade to 1.1 or highest version you have.
i dont see the button to update it
Unity version?
2020.3.22f1
It should be there to update it. Can I see screenshot of your package manager?
Click See Other Versions under it, just for checking.
Alright
i guess its because the 'verified' version is 1.0.2 even though the latest version is 1.2.0
Oh yes, I forgot about that. You can upgrade to 1.2.0.
it works now, thank you!
Anytime 🙂
I'm having trouble with an event.
When the scroll actions are performed below, selectUpDownLoad isn't called. No error or anything.
Can you see anything broken in my setup?
playerControls = new PlayerControls;
void Awake()
{
playerControls = new PlayerControls();
}
void OnEnable()
{
playerControls.UICustom.ScrollUp.performed += selectUpDownLoad;
playerControls.UICustom.ScrollDown.performed += selectUpDownLoad;
}
void OnDisable()
{
playerControls.UICustom.ScrollUp.performed -= selectUpDownLoad;
playerControls.UICustom.ScrollDown.performed -= selectUpDownLoad;
}
void selectUpDownLoad(InputAction.CallbackContext context)
{
print("event happened");
uiAudioManager.UIAudioSource.PlayOneShot(uiAudioManager.navigation,0.7f);
print("should have played audio");
}
I'm stuck at this issue for a while so asking here. For my XR controller, if I set the control type to value, I get a loop of started, performed, cancelled repeatedly when holding the button down. I understand performed, but why is cancelled getting called in between when the button isn't released. Same behavior with thumbstick, a loop of actual input and a vector2.zero. the input debugger does not have this issue so I assume things are read from hardware correctly. Setting control type to button leads to nothing being called for release. Nothing happens even on explicitly setting interaction to release.
Everything works perfectly well for keyboard input and gamepad input though. It's just the XR controller
You never enabled playerControls
how can i change wepons when i scroll the mouse whell
- create an Action for change weapon in your InputActions.
- Give it a scroll/y binding and attach the scroll wheel to that binding.
- hook up your code that changes weapons to listen for that Action and run it when the action is performed.
im trying to have various gameobjects be "clickable", I tried following this tutorial https://stackoverflow.com/a/41392130/15157083 however, It doesn't print anything on mouse down
i have an event system object, the camera has the raycaster, im just not sure what im doing wrong
any help on this would be appreciated
Are trying to do this with normal GameObjects or UI?
What you linked is mostly for UI
normal gameobjects, I tried following part 7 which seems to be for 2d objects
I may be wrong though
probably a common question here but can someone send me a full guide on how to implement mobile touch inputs to unity 2d games i wanna make my first mobile project but not sure how to implement touch inputs
have you checked the sample projects that unity provides?
which ?
in the package manager
whats it called
what kind of input are you trying to implement? button, joystick, etc
👍🏽
hi.. I set up the input system and it works BUT when in the main menu it doesn't take input from my gamepad ... only the up/down/left and right ... it doesn't take select, start or one of the buttons on the right... any idea why that is?
i think that's related to the evnt system and the inputsystemUI Input module
but i dont know how to make it work
any help please?
after many tests ... none of the gamepad controls work for some reason... I dont know why or how
You have two different actions to start and stop sprinting?
How are they set up? What are they bound to?
And how are you calling ProcessMove()
Seems overcomplicated, you could just use one action and listen for started and cancelled
Can you move at all?
Anyway it doesn't seem like your ProcessMove code cares about the isSprinting variable at all
So not sure what you're expecting to happen
Forget all that
The main point here is that your movement code is ignoring the sprinting variable entirely
If you want it to do anything, you need to make the movement code care about when you're sprinting
You could just have the sprintpress and sprintrelease change the speed variable
Then you wouldn't have to change the movement code at all
So do that
That much is obvious ☺️
Hello I have a problem with the new input system. It works with the mouse on PC but doesn't work with touch screen on Android. Here is my config:
What does or doesn't work
How are you reading the input
I have an OnPointerPress method in my player entity
And you're using the PlayerInput component in Send Messages mode?
it is called when I left click the mouse button when running on PC when not called when running on android
Sorry I'm a noob. How can I chekc this point ?
Behavirous "send messages"
Are you using the PlayerInput component?
yes
Ok and what mode is it set to?
I just check it's a playerinput component with the behavior "Send messages"
Ok good thanks
Default scheme Any
Now is there a reason you need the "press only" interaction on your binding here?
yes I just want to get the "on press"
But you don't need that interaction for that
Read the message
It explains
Wait this again with the separate actions for press and release?
What kinda crazy tutorials are you guys all following today
I need to get notifications for press and notifications for release
Yeah I understand. That can be done with a single action
depending on the press and release position they are different kind of interactions
Oh, could you please tell me what is the correct way to do that ?
Just use one action and check in the CallbackContext whether it's started or cancelled
you mean I can get only the press action and depending on the callbackcontext I can see if this is a release ?
the problem is that currently on android, the pointerpress is never called at all
@austere grotto sorry but I probably missed something
I have a question, is there a way to make a global script that works across scenes for input? so it's not bound to an object, i feel like that would be better and safer for stuff like menu's
Which message ?
There's nothing stopping you from subscribing to events of Input Actions outside of a MonoBehaviour. You just can't use the PlayerInput component
Hello I have a problem with the new input system. It works with the mouse on PC but doesn't work with touch screen on Android. Here is my config:
https://pasteboard.co/KJcE9doPANAx.png
i have this code
defaultInput.Weapon.ChangeGun.performed += e => CG();
that executes function 2 tieme(idk why tho)
and there is the input thing
show your code
A sec
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I meant the code that has this
nvm I see it
missed it at first
Lol
How do you know it's being called twice?
I made it type smthin in debug log
& do you have any interactions on your action?
Cool, since you have a Debug.Log, can you add this?
Debug.Log("My instance id is " + GetInstanceId());```
Can't help you much rn then. Either you've got two copies of the script in the scene, or you've got an interaction on the action that causes it to be performed twice
Btw what does it do?
anyone know what this is / how to fix?
is this related to the input system?
what is the suggested way in receiving the input from the new unity input system? (Send Messages/ Broadcast Messages/ Unity Events/ C# events)
send messages if you want simplicity
hmm i heard it's better to use UnityEvents or the c# events any reason for that?
they provide callback context so you can get more accurate data about the buttons
takes a bit more to set up tho
hmm thats fine with me
im making a game where you mostly just drag and drop. (eg placing units and removing units)
and im using the new input system cause it's easy for changing platforms
Try restart unity
The name 'GetInstanceId' does not exist in the current conte
didnt expact anything else
@austere grotto
GetInstanceID instead of Id.
it says -1382
on both
@austere grotto u here?
can someone tell me where I can find the basics for the new input system?
look at the pinned posts in this channel
k thnks
heey
@austere grotto it say -1382 on both
so what shall i do
chceck if it dont have an interaction
btw the gameobject is child of prefab cant that be why?
when i put smhin in start (debug.log) it runs only one time (so the script isnt there 2 time (in scene)) but the action dont have an interaction either
so what shall i do
I'm trying to add d-pad support to my game. Right now for movement I'm using Input.GetAxisRaw("Horizontal") is there a way to add d-pad as an alternative to the joystick?
I'm using the old input system btw because that's what I'm used to.
Hey, i got a fire perform and canceled callbacks but sometimes (seemingly randomly) after just tap-firing, the firing bool is set to true even though doing debug logs shows it being canceled after a fire
private void Fire_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
if (fireDelay == 0)
firing = true;
else
StartCoroutine(nameof(ChargedFire));
}
private void Fire_canceled(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
StopFiring();
}```
and it being true basically fires as if the key is held
There is not enough code there for me to determine the problem, I would assume somewhere in the coroutine you are setting fireDelay within an if statement that relies on the button being pressed or something similar.
oh the problem isnt using a coroutine, thats the issue
debugging both methods show that they are being called in the right order always; even when the issue happens
hmm
Maybe run debug.log with different messages any place you modify the firing bool, making sure to mention what modification is being made.
literally the only place i set it to true
the do the same with fireDelay
and StopFiring has it false at the end
why?
ignore the if check, its always gonna call firing = true; on that weapon i tested the bug on
ok
private void Fire_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
firing = true;
}
private void Fire_canceled(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
if (gatling.gatlingStarted && gatling.isGatling && gatling.gatlingDischarge)
{
if (weaponAudioSource.isPlaying && gatling.forceEndSound)
{
weaponAudioSource.Stop();
}
weaponAudioSource.loop = false;
weaponAudioSource.PlayOneShot(gatling.gatlingDischarge);
}
StopCoroutine(nameof(ChargedFire));
gatling.gatlingStarted = false;
firing = false;
}```
here, made it better
are any errors being thrown in that script that would stop it running to completion?
no.
as i said, the bloody thing works just fine
but if i tap-fire rapidly the firing gets stuck to true
but not always
¯_(ツ)_/¯
:P where and under what circumstances is the Fire_cancled method being called
try this:
private void Fire_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
firing = true;
Debug.Log("firing set to true");
}
private void Fire_canceled(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
if (gatling.gatlingStarted && gatling.isGatling && gatling.gatlingDischarge)
{
if (weaponAudioSource.isPlaying && gatling.forceEndSound)
{
weaponAudioSource.Stop();
}
weaponAudioSource.loop = false;
weaponAudioSource.PlayOneShot(gatling.gatlingDischarge);
}
StopCoroutine(nameof(ChargedFire));
gatling.gatlingStarted = false;
firing = false;
Debug.Log("firing set to false");
}
make sure Collapse is toggled off on the console and see if the order of the logs matches the occurrence of the bug
my dude i told u 😄
ok
sorry, my brain says that is the likely culprit :P
I'll think of other possibilities ig
i have no bloody clue why its doing it other than maybe the input system being bugged
Then it sounds like the input system is working correctly and performing the callbacks in the correct order.
then why is my firing getting stuck 🤔
actually let me debug my actual firing method calls
firing = true
ive set it so if thats true it will fire
{
if (firing)
{
RemoteFire();//here is where we actually fire
if (!automatic)
StopFiring();
}```
OnUpdate just Update using a delegate instead of having multiple Update methods- supposedly for speed
so the logs are saying the firing bool is off, when it isn't?
no log said it called the StopFiring method
let me see if its still true if it gets stuck
yup, its true
so the logs are correctly determining when the bool is true when it shouldn't be?
or are you looking in the inspector?
AHHA!
hold up im onto something
i fired 3 shots that were fine, and then the next one got stuck
it seems it doesnt reach the end of the StopFiring()
could it be me spamming the StopCoroutine(nameof(ChargedFire)); even though im not using it?
if its a possibility, and checking is attainable, check it
I'd also recommend adding more debug statements within that method to determine exactly where it stops.
nope, i disabled the gatling-related code and just left the firing = false;
same issue
this is dumb....
so its probably an issue with where Fire_canceled is being called
or where its not being called 🤔
as i said and say it again; mouse up
perhaps if i use started instead of performed for my mouse down?
my only guess is the performed doesnt get called at the same order all the time
maybe it takes longer to perform for some reason
same issue
unfortunate
i think i know whats going on....
never mind, false
i thought it got stuck on firing only when i used my keyboard WASD to move
it wasnt that
Its probably either the mouse up is not being received properly or something is impeding the script that starts the Fire_canceled method? (edit: not the actual method the bit that calls it)
can I see that bit of script?
if this doesnt work then something prevents from the actual callback from being called
yup, it sometimes doesnt get called
hell...
ya, so can I see the place where Fire_canceled is called
I didn't know that method was called by the input system, never used it.
my dude, we are in the input system xD
how are you subscribing to the InputActions? Are you manually instantiating a copy of your actions? Using PlayerInput?
yup, C# generated code
GameManager.Instance.Inputs.Player.Fire.canceled += Fire_canceled;
{
get
{
if (_inputs == null)
{
_inputs = new PlayerControls();
}```
@spark pumice no clue why it sometimes doesnt do the canceled callback
can you screenshot your InputAction window w/ Fire selected?
I assume you're subscribing to all the events the same way?
i mean...yeah?
even the delegate ones i did
Is fire a Button?
is there any way to make the key a public variable?
@spark pumice idk what could be wrong with the callback other than it being an actual system bug 🤔
if i create a settings asset; i assume the default settings are how it is without the custom asset?
reading docs right now, trying to see if there's something subtle about when cancelled gets called
I assume so, but I don't know
im gonna have to sleep now since its 4 in the morning; ping me if u find something
any chance it happens when the game lags a bit? My only guess is that you're pressing/releasing/pressing before the system as a chance to process the state changes and cancelled is getting swallowed. It seems unlikely, but I don't have any other leads
framerate is a solid 89-90 (aka target framerate ive set) and only dips to 86 randomly, possibly because its in editor
idk unless someone more experienced in this shit pops in; might need to file it as a bug
i removed the coroutine breh; smae issue
private void Fire_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
firing = true;
}
private void Fire_canceled(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
firing = false;
}```
same issue
anyway bye for now
Neither "Key" from InputSystem nor "KeyCode" works as a variable for this.
Use Key. Then you can do kb[theKey]
Hello guys how are you doing, I hope you are doing well. So I want to ask about something. I have used the new input system with cinemachine and I have made the joystick of the movement. But for rotating the camera I used an image and On-Screen Stick and set the control path to Right stick and the cinemachine Input provider with the input action with action type to value, control type to Vector 2 and blinding path with Right stick. But the problem that when I test it with my phone, the right joy stick acts like a right joy stick so If I pressed and hold the camera will be spinning for ever until I release it and the camera movement isn't accurate. So do you guys have any ideas on how to solve this problem?
you could set the joystick to reset itself back to 0,0 when inactive
it isn't about the joystick. the movement with the joystick is working without problems but the right joystick is already programmed to be as a real right joystick of a controller so when you move the joystick to the right and keep holding it will keep moving the camera or spinning. that's why I want to remove the right joystick option but I tried to replace it with everything like touch, mouse but still not accurate and got problems too
I could use normal camera with script but I need cinemachine because it has great features which I really need
@spark pumice well i think its a unity editor bug , this callback thing- i made a standalone build and im not getting it 🤔
How can I save the place where the touch was, which I asked for with Input.Gettouch?
In a variable, naturally
sure but how because Input.Gettouch in a variable isn't a place
Wat
hey all, trying to setup an input-action that allows me to grab objects using the XR interaction toolkit, and am not exactly sure how to setup the bindings on the controllers --> can anyone point me in the right direction?
is it posible to detect if i scroll up or down on scroll wheel?
thx
how can i recreate this with the new input sytem : Input.GetAxis("Mouse ScrollWheel") > 0f
var mouse= mouse.current;
if (mouse== null)
return;
if (mouse.scroll.x > 0)
{
// 'Use' code here
}
It's always a MissingMethodException saying it can't find the method like OnDash but it is in my script so idk why this is happening.
it also shows some System libraries, here is a full error
MissingMethodException: Method 'InputReader.OnDash' not found.
System.RuntimeType.InvokeMember (System.String name, System.Reflection.BindingFlags bindingFlags, System.Reflection.Binder binder, System.Object target, System.Object[] providedArgs, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParams) (at <00c558282d074245ab3496e2d108079b>:0)
UnityEngine.SetupCoroutine.InvokeMember (System.Object behaviour, System.String name, System.Object variable) (at <e7c72e4b0bcb4085b636d7e8921f7453>:0)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
The error isn't really useful, i can't make up from this what is wrong
hey uhh im trying to learn the new unity input system and i was struggeling with the unity events. How do i read input when using the unity events? Like i wanna get the callback but when i add the callback in the parameters i can find it on playerinput discovery
In update?
nvm its resolved
Seems like you hooked up a unity event listener to a method and later changed the method signature or something
i am not sure, i am now trying a simple one with only movement and can't get it working. i want to learn how to properly use the callback context but i am not succesfull
Show your code and your input action(s) and how you've set up the PLayerInput component (if you are using one)
This is a very basic script i just made trying to get the callbackcontext working
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
[RequireComponent(typeof(CharacterController))]
public class Protagonist : MonoBehaviour
{
private CharacterController m_CharacterController;
private Vector2 m_MoveInput;
private void Awake()
{
m_CharacterController = GetComponent<CharacterController>();
}
private void FixedUpdate()
{
m_CharacterController.Move(new Vector3(m_MoveInput.x, 0, m_MoveInput.y).normalized * Time.fixedDeltaTime);
}
public void OnMove(InputAction.CallbackContext context)
{
m_MoveInput = context.ReadValue<Vector2>();
}
}
this is the setup
i am trying other settings for the messages too like c# events but none do the trick
and these are my inputs not much
I previously in did it using the InputValue but now want to try and use it with the callbackcontext
You don't have an OnDash function
that's what it's complaining about
If you use C# events you're supposed to listen to this event: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.2/api/UnityEngine.InputSystem.PlayerInput.html#UnityEngine_InputSystem_PlayerInput_onActionTriggered
It's a totally different approach
and if you use UnityEvents you're supposed to assign the callbacks in the inspector.
yeah, but that's what confuses me, not sure what i properly need to put in the code to make it work
Well if you stick with Broadcast Messages, you need to make an OnDash method
similar to your existing OnMove method
And an OnAttack
What's not working about it
public void OnMove(InputAction.CallbackContext context)
{
m_MoveInput = context.ReadValue<Vector2>();
}
public void OnDash(InputAction.CallbackContext context)
{
return;
}
public void OnAttack(InputAction.CallbackContext context)
{
return;
}
like now i have this
but my charactercontroller just doesn't move
Did you put a Debug.Log in OnMove to see if it's running?
but it also complains when i put send or broadcast messages that none of the OnAttack/OnMove/OnDash are found
You're supposed to use an InputValue parameter
not a CallbackContext
See the example in the link i sent
but i saw some projects using callbackcontext and would like to use it too since it added more checks like if an input is canceled or peformed
You can't use it with PlayerInput/BroadcastMessages
I would like keep using callbackcontext, i can change the behavior of my inputmanager if needed, i just would like to use the functionality of the callbackcontext
it's for different approaches
I know, i can change that
You need to change your PlayerInput to use UnityEvents
and then assign your functions in the inspector
Or skip using PlayerInput altogether and then there's a whole world of ways to do things without it.
How would you utilise the inputsystem without the playerinput component? would you generate the script from the inputsystem?
That is one option (generated C# class file from the Input Actions Asset)
Another option is to use InputActionReference, or a direct reference to an InputActionsAsset
if i used the generated input script how would i utilise the callback context from there
do i just implement the interface and it should work?
there's several ways
I believe you can implement the interface and then you need to instantiate your generated input class and register your object as a listener for it
I have done this right now, but it's not yet working any idea why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
[RequireComponent(typeof(CharacterController))]
public class Protagonist : MonoBehaviour, GameInput.IGameplayActions
{
private CharacterController m_CharacterController;
private GameInput m_GameInput;
private Vector2 m_MoveInput;
private void Awake()
{
m_CharacterController = GetComponent<CharacterController>();
m_GameInput = new GameInput();
m_GameInput.Gameplay.SetCallbacks(this);
}
private void FixedUpdate()
{
m_CharacterController.Move(new Vector3(m_MoveInput.x, 0, m_MoveInput.y).normalized * Time.fixedDeltaTime);
}
public void OnMove(InputAction.CallbackContext context)
{
Debug.Log("move");
m_MoveInput = context.ReadValue<Vector2>();
}
public void OnDash(InputAction.CallbackContext context)
{
return;
}
public void OnAttack(InputAction.CallbackContext context)
{
return;
}
}
m_GameInput.Enable() is needed
How is the input system meant to work in a networked multiplayer context? Tried searching stuff online but I can only find local multiplayer. Currently I'm having issues where the host of my multiplayer instance can look around no problem but any new clients cant. The player prefab has a player input and there is an event hooked up to my look function, it just never gets called on any client that isn't hosting the server as well.
I've disabled all other player inputs except for the local player, so I'm not sure whats up. I also checked that the reference to Player is correct for each client
public void OnLook(InputAction.CallbackContext context) {
Debug.Log("hi2");
if (!isLocalPlayer) return;
Vector2 lookValue = context.ReadValue<Vector2>() * Time.deltaTime;
if (looking)
{
float newRotationX = transform.localEulerAngles.y + lookValue.x * freeLookSensitivity;
float newRotationY = transform.localEulerAngles.x - lookValue.y * freeLookSensitivity;
transform.localEulerAngles = new Vector3(newRotationY, newRotationX, 0f);
}
}
The "hi2" message only ever appears for the host, other clients never have this outputted to console
My initial guess is it has to do with the fact that the host has the first instance of it, and there is something going wrong with there being multiple inputs
Go look at the PlayerInput during runtime on one of the clients
See if everything looks ok and all the components are enabled etc
Does anyone know why the xbox controller or mouse/keyboard doesn't work on xbox series x/s in dev mode? (On windows 10 the xbox controller works perfect)
I can't find any useful information about controller input on xbox. Please help
No idea, but would guess that maybe some SDK is required to extend support?
Thank can you tell me where to find more documentation etc?
No, just guessing. I would also try to check if there is any event activity happening in the input system
No idea how to access the lower levels of the input system either, but I assume there is a way at runtime to do something similar to what the input debugger does
Okay thanks. Someone also said I should use an sdk for ID@XBOX but I can't find any information anywhere
Hello, when I use the new input system I have a problem. private void OnPointerPress() is correctly called when the user press the mouse button but if I use "private void OnPointerPress(CallbackContext context)" I get an MissingMethodException error. Why I can't have a CallbackContext and how to get one ?
If you're using SendMessages or Broadcast Messages then the method takes an Input value parameter, not a callback context
ok thanks.
I have another question. Is there a way to get the "position" on a press event ?
You need a second Input Action for pointer position
and you just read from there
ok but when I "press" I need to know if this input is in the correct zone or not
yes... and?
You can also use the event system for this. Make a UI or game world object with IPointerClickHandler in the correct "zone"
The "onMove" (to get the position) callback is called before the onclick ?
No you get the position by reading it directly from the action inside the on click
myPointerPositionAction.ReadValue<Vector2>()```
Ok so to be able to read a vector2 I have a to set actiontype: value and controle type: vector2. Right ?
InvalidOperationException: Cannot read value of type 'Vector2' from control '/Mouse/leftButton' bound to action 'Player/PointerPress[/Mouse/leftButton]' (control is a 'ButtonControl' with value type 'float')
I get this error in the "on click"
void OnPointerPress(InputValue value) {
Debug.Log("TEST: " + value.Get<Vector2>());
}
(i'm using SendMessages)
Something missing ? Do I need another binding for this action ? a "mouse move" binding ?
@austere grotto could you please tell me how to get a position from an on click action ?
I have an error when I try to read the value
I already said you need to make a second action for the pointer position
You can't get position from the click
You also saied "No you get the position by reading it directly from the action inside the on click". So you mean read a variable updated from the onSecondAction method ?
Anyway I still have a problem. The OnMove is called AFTER the OnPress so I don't have a position value available for the first OnPress
Yeah it seems everything is in order. The client that needs everything has it all enabled, any extras for other players is disabled
no, not using an event, just reading from the second InputAction directly with the ReadValue method, as I showed in my example code.
I'm having a few issues with Input System Manager. I followed the Roll-A-Ball tutorial, which used the movement section, and it worked perfectly. But, I've tried to modify it for moving the camera using Look, but nothing happens.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class CameraRotate : MonoBehaviour
{
private Vector2 lookVector;
void OnLook (InputValue lookValue)
{
Vector2 lookVector = lookValue.Get<Vector2>();
}
// Update is called once per frame
void Update()
{
transform.Rotate(0, lookVector.y, 0);
Debug.Log(lookVector);
}
}
I should be getting back a vector of my mouse/right stick movement, or for the camera to rotate, but nothing happens. I've followed the same structure as my movement script, which works.
Here is the movement code, which works:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
public float speed = 0;
private Rigidbody rb;
private float movementX;
private float movementY;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OnMove(InputValue movementValue)
{
// Function Body
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
}
void FixedUpdate()
{
Vector3 movement = new Vector3(movementX, 0.0f, movementY);
rb.AddForce(movement * speed);
}
}
Hey
Btw is it detectin scroll wheel?
do you always have to declare a new Input Asset Pack when you use it in a script?
Like for my PlayerMovement I have to do playerActions = new PlayerActions(); and the OnEnable and OnDisable methods.
Do I also have to do the same thing for the CameraMovement script for example? Or am I just missing something really obvious?
Your code in OnLook is creating a new local variable which is immediately discarded
You should instead write to the existing lookVector member variable
Notice your OnMove is writing to the member variables movementX/Y
From a code perspective this means simply deleting the word 'Vector2' from the first line of code inside your OnMove method
This hasn't changed anything 😦
Log still says 0.00, 0.00 for every frame
Yet, if I swap OnLook into my movement script, that works fine.
public class PlayerController : MonoBehaviour
{
public float speed = 0;
private Rigidbody rb;
private float movementX;
private float movementY;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OnLook(InputValue movementValue)
{
// Function Body
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
Debug.Log(movementX);
}
This code works fine, and puts the value in the log every time I move my mouse left and right.
public class CameraRotate : MonoBehaviour
{
private float lookX;
private float lookY;
void OnLook(InputValue lookValue)
{
Vector2 lookVector = lookValue.Get<Vector2>();
lookX = lookVector.x;
lookY = lookVector.y;
Debug.Log(lookX);
}
```But this code doesn't do anything?
I FIXED IT.
The camera didn't have the PlayerInput component...
I'm working with my own inputActions asset and it's associated C# script and am trying to work out how to do an Input.GetMouseButtonUp(0) action. I'm a little confused tbh, can anybody provide clues? I can register to the performed event and read a bool value off the lambda, but that doesn't really let me know when it's 'released'. Am I going to have to code this myself? No real hardship, but it seems odd this isn't handled in Input...
I'd recommend glancing over this page, as it explains some things that I think the InputSystem docs don't explain well anywhere else: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Interactions.html#default-interaction
Basically there are different events for different steps in a control's lifetime; generally to listen for button up you will want to subscribe to the canceled (sic) event, but there are some subtleties depending on how you have your interactions set up.
There's also the WasReleasedThisFrame() method on the input action
As well as checking for the canceled phase on the action
So there's at least 3 ways to do it
Thank you, @hidden laurel and @austere grotto . I still find myself getting confused over the events, though I appreciate the page you've linked! I'm currently registering functions with these events in Awake - though they don't seem to be called in-game. Additionally, should I be deregistering in OnDestroy? Not sure if that still holds true for InputAction events... =/
inputActions.ActionMap.MouseButton0.performed += MBut0 => StartDrag();
Yes you should "deregister" in ondestroy but make sure you do this properly, for example it won't be possible to unregister with this syntax
Make sure you also call inputActions.Enable() at some point
? But presumably I can deregister with,
inputActions.ActionMap.MouseButton0.performed -= MBut0 => StartDrag();
...although I can see the lambda causing problems... =/
No you can't
Shucks.
Yeah, right.
Yep.
I couldn't seem to immediately register the StartDrag() function, however...
It needs an inputaction.callbackcontext parameter
To match the event's delegate type
Also, goddamn, I can't believe I forgot 'enable'. I will get the hang of this thing.
Oh, I know, but... rrrgh. =)
Meatbrains do be like that
Can you give me an example of the inputaction.callbackcontext parameter?
...
0_o
Ignore everything except the parameter of his function
That's what your function needs
So... I need to put this inside... a function which has a callback parameter?
So, not registering with the event at all?
You just need to add that parameter to your Start drag method, or another method that calls start drag
Then you'll be able to register that method directly to the event
OHH.
Instead of using a lambda
OHHHHHHHH.
OHHHHHH.
Yes.
Yes. Scales falling from my eyes.
I should have read the goddamn warning messages in Intellisense, in other words.
:P
Thank you for sticking with me in my moment of idiocy.
Like, I've seen all this before, but didn't connect it to this... context... =/
Sorry to bother you again, man, but... my function signatures now read as,
private void StartDrag(InputAction.CallbackContext context)
but Visual Studio is still not happy...
It's suggesting making a function that begins,
private Action<InputAction.CallbackContext> StartDrag()
which seems contrary to the example you gave me above. Confused...
When subscribing to the event you don't use ()
+= StartDrag;
You're not calling the function you're just registering it to the event
Fucking hell. I'm so sorry I'm wasting your time with this. =) Thank you.
I knew that. But there we are. =/
I clearly don't use events enough. Need to do some practice.
Guys my brain is melting about this one thing. I want to make split-screen co-op on my game, but I have coded the controls of my characters like this, for example (it is a separated code receiving input and signals):
But then someone told me that, in order to separate devices and what device will control which character, I have to use the "PlayerInput" component, which I do believe is this one
But then how do I reference this component and let the code know that the "_c" is this component? 🤔
Also, do I really need to use this component in order to do split-screen? Every hint and assistance would be highly appreciated ❤️
I've read the documentation a bit and it seems this component is used to invoke events, so I probably would have to change my entire code lol
Uh, I'm kinda fumbling around in the dark with this myself at the moment, @heavy aurora , but my suspicion is that if you Generate a C# class (as seen in the inspector in the attached image), you should be able to have a reference to it in each player control script, eliminating the need for the PlayerInput component.
As I can see in your first screenshot, you have '_c = new Controls()', so that should basically make that instantiation of Controls independent of the other player.
Yeah, I think this is what I have been doing, the thing that kills me is that I don't have a single clue on how to indicate which device will use which object hm :(
When I have two characters, every device I use control both of them
(Thank you for your reply btw, very kind of you!)
Hmm.
I'd like to dig into this, as I'm about to try and do something similar here... Unfortunately, I need to run before the shops close! I'll check back in later, @heavy aurora !
I'll do some tests and read a bit deeper into the documentation, I'll let you know if I discover something!
You're mixing up two completely different approaches. PlayerInput is one way. Creating a new instance of your generated C# class file is a different way
The PlayerInput component is what you should use along with a PlayerInputManager as that's the system designed for local multiplayer
Tldr get rid of your whole _c variable and set things up via the PlayerInput component
I see, very interesting and nice that Unity has now an "official" approach to local multiplayer, which I will for sure look deeper into it.
Thanks friend, that helped a lot!
This may look terrible but helps me a lot since I don't have to rework everything from scratch.
Though I'm not sure why, the keyboard & mouse is doing nothing, auto-switch is enabled but I can only play using my controller. Any suggestions on that?
...Whaaat, seriously? So... how would you set things up for something like Overcooked, which handles local and online multiplayer? What's the argument for doing things with the class, then? Sorry to trouble you again, @austere grotto , you just seem to have a great handle on this!
That's a good point, how would one handle online multiplayer while using this method?
If there's local multiplayer it's easiest to use PlayerInput.
For online multiplayer you would just only have an active PlayerInput component on player objects that belong to the local client
The other clients will handle their own input
Oh, true, you have only to sync input and other things
So everyone would send their own inputs to the server
Sure, no, I get that. But I'm confused why I should change methodology for PlayerInput - granted, I only have very little experience with the new input system. =/
I mean, you might do a duplicate InputAction or something for a different set of inputs, but surely once you've got them setup in the script, they shouldn't interfere with each other? No? Feel free to tell me to go research this myself, btw. =D
I'm sorry, I didn't understand your message completely, what do you mean to interfere with each other?
Ah, sorry - my impression from what you'd said earlier - hang on, I'll reply to it... Is that when you try to set up two different characters, you end up controlling both of them.
And what I'm thinking is that that makes sense as one set of InputActions is bound to a specific set of keys.
There's no reason to use PlayerInput unless you're doing local multiplayer. It's less flexible and more annoying to deal with in general
If you hit the same keys on character's that are using the same InputActions, then you'd get the same output on both of them, no?
Oh sorry, my bad haha. Now that I'm using the player input method this doesn't happen anymore, as I can set which character will use which controller in the component
Hmm, I get that's the workaround.
But - and I'm thinking aloud here - I was thinking you'd have different InputActions for each player, which would allow each individual player to be bound differently.
Then you'd get a reference to the correct InputActions at Start or Awake and then register to the correct events then or something.
That's pretty much exactly what PlayerInput/PlayerInputManager is doing under the hood
It takes care of linking different input devices to different input action assets automatically
Oh that's nice to know, it is kind of a shortcut/easy way to achieve that
Right. That's... fairly reasonable... I guess I need to study these more to work out what I'm more comfortable with.
I'd kinda resigned myself to using the class a while ago.
I'll probably go with the PlayerInput/PlayerInputManager for now as I am really focused on local multiplayer, I've tried online multiplayer for some time but it gave me a lot of headaches, a lot of things to learn.
PlayerInput really hates my mouse and keyboard though, I can only play with my controller now somewhy
Yeah, tons to learn. Thanks to both of you, btw, that was very educational! And please stay in touch, @heavy aurora , I'm going to be trying the input system with online multiplayer shortly and I'd love to hear how your local game gets on!
Thanks, friend! I'll surely keep in touch, showing progress. :) Unfortunately at the moment, the PlayerInput is giving me some headache, as the action asset is always disappearing from the component, even applying it on the player prefab.
Are you using PlayerInputManager?
Yes
(I'm sorry I'm spamming on new year's eve, please enjoy your day and reply when possible!!!
)
hey can i ask what is a good binding to like zoom in while aiming (right mouse button)
in need 2
like zoom in , zoom out
heey
can somebody explain this to me cs public Vector2Control scroll { get; }
Hey, so I wanted to make this feature for a project i'm working on where when you tap and then hold the movement keys the character starts running (normal holding = walk / Tap + Hold = Run) but i don't think it was working as i planned by using the current Interactions. I tried coding another one but it was a bit unreliable (it took a while to detect the input and sometimes wouldn't trigger imedeatly)
The best solution i came up right now is having a single "Tap" action whose method will trigger a bool that will timeout and become false again. If i start walking in the meantime the walk (by the normal hold interaction) It will just turn into running and set the bool to false.
Does anyone know a better way to do this with the new input system? Am I overcomplicating stuff?
I'm pretty sure that's how I achieved a similar effect while using the new input system on an older project, @still topaz . It seems straightforward enough - that said, I'd also be interested in hearing if there's a best practice for this sorta thing with the new input...!
Using NEW unity input system:
I'm trying to have the Running Audio STOP IF I'm still holding down shift (running) and then press c afterwards (crouching). (Both being hold down at the same time, but crouching would stop the audio from playing).
Movement script = https://gdl.space/pokutewaxi.cs
Input Manager script just in case = https://gdl.space/imakobagal.cs
Sadly there’s no implementation to do sequential input like this in the new input system.
So you need to do a custom logic. This is even trickier if you have 2 shortcuts
SHift+c and Shift+C+B (example)
Your second shortcut would also trigger the first one. You need to do some logic to prevent those kind of situation.
I think I still have a post on the forum about it. Let me check
might seem stupid but what mouse button would you use for firing and aiming a weapon. Keep thinking it is left aim and right shoot but not entirely sure
Traditionally it is right to aim left to shoot
Cheers
Was there an update to the new input system? I'm noticing differences in what I'm used to and I don't know what to do now
there's always updates. but you have to do them manually. so if you didn't, there shouldn't be
Such as?
The inability to add more than one pink sub bindings to the blue bindings
I want to do a simple WASD movement system but I don't know how to go about that
you have a 1d axis. you need a 2d axis
I get no option for that
You need to make your action Vector2 type
Then you'll get the option
Ok. What would a simple FPS input system look like? Does it even require those pink things?
nothing requires them
they are a very nice way to handle a 2D input vector
For an example check out the Starter assets
why are previews always collapsing again? that's what i'm curious about
I collapsed/removed it myself
how?
By pressing the little x
interesting
I’m making a 3ds fps character
Oh Ok
How can I have binds like "Shift+e" with the new input system?
make a binding for E and check if Shift is currently depressed inside the handler for it
how do i do that...?
which part
"check if Shift is currently depressed"
@austere grotto I have this
but thats just the E
not the shift+
wait what about this?
Oh wait yeah I forgot about that 😛
wdym
im trying to set up the controls for a friend
what are you trying to achieve
he doesnt like E/Q for strafe
he would like shift+E/Q
but those are in a vector3 composite
I don't think you can have composites with modifiers
I think this is all a little too bespoke for the input system
you'll have to build some of it yourself in code
what if i have each of the axes in their own binding
hmm but that still wont work cuz i need them as floats
thank u anyway though @austere grotto
@drifting lynx it's pretty easy extending / writing your own interactions. limitless potential
yeah ik, i was just kind of in a rush then
Hey, just as I said I'd keep in touch with @heavy aurora and @austere grotto gave me some great advice earlier, some code that seems like it'd be useful for local multiplayer if you're hellbent on doing it all yourself...
IInputActionCollection2[] iActions = new IInputActionCollection2[8]; // Ideally you'd set this up in the inspector.
iActions[0] = new Controls(); // 'Controls'-> some InputActions setup in Inspector. Again, add these in the inspector.
inputActions = PrepPlayerControls(PlayerEnum.Player2);
inputActions.Enable();
public Controls PrepPlayerControls (PlayerEnum playerNumber = 0)
{// Make '0' in the array a dupe of '1', so you can index by pl int (or enum)
return (Controls)iActions[(int)playerNumber];
}
Haven't got around to implementing this yet, but seemed potentially useful...!
Maybe this is already answered but can't find it:
Why it doesn't letting me add my Input system to my script?
so im here to get some help
im absolutely new to unity and code
and im trying to make an object move
how can I do this?
In about a million different ways.
Have you considered looking at some tutorials?
oh uh I dont need help anymore im watching a tutorial
What's not letting you add it to where?
Hello Guys, this is my first time posting here. I would like to seek help, have you tried the new input system with mobile touch? My onclick UI Button event is working when running on editor but on IOS device it is not trigerring. Thanks in advance
Is it good practice to have multiple Player Input component on any game object that needs to read input? I also have an in-game console that needs to know when tilde is pressed, not sure if I should dispatch an event for it using my event manager or just put the player input component on the in-game console manager game object, any ideas?
@sonic delta it's fine. to have multiple components. though the manual workflow can be much nicer
Quick question for yall, I am trying too add an attack key to the third person controller that unity includes in their package. I have felt like I have coded it in right, but clicking the mouse button ends up producing this error. Anyone know what I am doing wrong?
Parameter 'Hash 1331344109' does not exist. UnityEngine.Animator:SetBool (int,bool) StarterAssets.ThirdPersonController:Attack () (at Assets/StarterAssets/ThirdPersonController/Scripts/ThirdPersonController.cs:307) StarterAssets.ThirdPersonController:Update () (at Assets/StarterAssets/ThirdPersonController/Scripts/ThirdPersonController.cs:124)
It's fine.
however keep in mind that PlayerInput has an internal counter that counts how many PlayerInput component is present in the scene.
This news up the referenced InputActions map per counter.
So there are two instances of my input actions?
if you have 2 PlayerInput on a scene, that are referencing the same InputAction. yes. there's going to be 2 of them.
By manual workflow are you referring to using the generated classes?
Hmmm ok. Thank you!
I thought that was messier at first glance lol
why would it be messier
Bruh I installed the input system in unity cuz I wanted to add controller support but i changed my mind.So i uninstalled it and now I cant move at all can someone help?
Hey hi! Happy new year 🙂
I wonder if anybody knows about this:
On the old input system, i was using Input.GetAxis and using as input L (Positive) and M (Negative) on the Project Input Settings. This gave me 1 to -1 values.
How could i do this with the new input system using the mouse delta instead (-1 being left and 1 being right).
you need to reenable the legacy input backends
create an input action with that behaviour
Oh bruh I already fixed it lol I was so scared cuz my friends and I were working on it.
How i mean haha
If you use delta mouse the values are not normalized, and the normalize processor dont seem to clamp it.
It returns high values from 0 to 50.
if normalize doesn't work, write your own input action and use this
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Pointers.html
mouse delta is the difference in position since last frame in window space
I read that it also varies between systems.
Do you come to know what would be the propper to set my desired behavior?
digital works for mouse?
like i said. write your own input action and use it
just to clarify a little bit, do you want it to return -1 when you have the mouse on the left side of the screen, or when you moved the mouse quickly to the left?
when i move the mouse to the left
left** lol
okay well, use mouse delta and divide it by Screen.width or Screen.height
it should give you negative values. The normalize processor might have been breaking that
okay thank you 🙂
but this will mean that -1 is "I moved all the way from the rigtht side of the screen to the left in 1 frame"
Hello! Im trying to detect input from the new input system, and store the information into a scriptable object. My problem is that the performed call back is happening at the same time as the started one, so the ButtonClicked property gets overrode. I thought about making a timer that waits 1-2 sec but i dont think thats the best approach.
started and performed are only different for longer interactions. for a simple single click of course they are the same
and is there any way i can check for the started callback?
and to store it for 1-2 sec ?
i mean yeah you can cache them manually of course
Hi ... I'm moving an object with "playerRigidbody.velocity = movementInput * playerSpeed;". With gamepad it works smoothly but with keyboard it's like it's normalizing the input (I don't have actions processors set). In fact, if i change the above line to movementInput.normalized , the gamepad works like the keyboard. Any way to make the keyboard work smoothly like the gamepad ?
but im caching them into the properties, but in the performed callback, the ButtonClicked gets overrode @mortal ridge
when you say keyboard, you mean with WASD?
yes exactly
I also tried modes Digital and Digital Normalized .. both same effect
and Analog same effect too
so... that's the way a keyboard works. When you press A, it gives you -1. When you press D, it gives you 1. With a gamepad stick, you can have the stick halfway between center and right, so you can get 0.5.
What buttons would you like to press to simulate the stick being halfway between center and right?
right of course.... :/
but the right button can only be on or off. There is no halfway on.
i forgot it's just a basic switch
hmmm i'm doing a local multiplayer and the gamepad user will have an unfair (more accurate) advantage over the keyboard user
and i guess there's no way around it
besides maybe switching to a mouse
yeah, its a tough issue. You could force the gamepad to work like the keyboard, but that doesn't feel good for them. lmk if you come up with a brilliant solution!
sure thing... here it is... i'm switching to mouse instead of kb 🤣
yep, that's the best I've ever come up with. Though it does tend to cause the opposite problem, where the mouse is more accurate than the gamepad. But 🤷♂️ you can't win them all
delta is the one i want aye ?
Oh damn you weren't kidding... mouse is now like twice as fast
@mortal ridge previously i was setting the property like this ButtonClicked = Input.GetButtonDown(KeyCode.E); in the update, do u know why in this case it didnt override in the same frame?
no idea really
i asked this last year xd
btw somebody pls explain it
thats a property, its a field where u only can get or/and set the value
In this case public bool ButtonReleased { get; private set; } u can access the value from every class, but u can only set it in the base class where the field is
it's jus the name of the property
yeah but im trying to understand it cuz like when u scroll up i do something , and when u scroll down it do smthin else
yes
?
but like how can i detect where i scrool
when*
and where
so like
if(scrool.up){
type("loool")
}```
Is it bad practice to create multiple instances of the generated input actions class in different places?
It's a bit wasteful, sure
Is it better to put it in a manager object do you think?
More memory, more CPU usage, as each one will be processed separately
Yeah that's what I do generally, if using the generated class.
Using the singleton pattern?
the memory is neglectable tbh. there are more advantages to multiple instances than a manager
yes thats true. but mostly you only need subsets of an action map and then you can enable and disable certain parts of input on all your objects and then you have more granular control
Can I remap Fire1
Can someone help me with my mouse input manager? I would like to be able to move the camera around with drag
I have a working script but I refactored my entire camera controller and now got to combine those two
So this is the working drag script
private void LateUpdate() {
Vector3 pos = Camera.main.transform.position;
if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
{
Difference = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + CameraSpeed)) - pos;
if (!drag)
{
drag = true;
Origin = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + CameraSpeed));
}
}
else
{
drag = false;
}
if (drag)
{
pos = Origin - Difference;
}
if (Input.GetMouseButtonDown(1))
{
pos = ResetCamera;
}
pos.x = Mathf.Clamp(pos.x, -panLimit.x, panLimit.x);
pos.z = Mathf.Clamp(pos.z, -panLimit.y, panLimit.y);
transform.position = pos;
}
https://hastebin.cc/weyixohowi.csharp and this is my mouseinputmanager
basically under the movement section I already implemented something like "if the cursor touches an edge... move towards it"
The MoveInputHandler is just a public delegate void MoveInputHandler(Vector3 moveVector);
Hello Guys, this is my first time posting here. I would like to seek help, have you tried the new input system with mobile touch? My onclick UI Button event is working when running on editor but on IOS device it is not trigerring. Thanks in advance
Pretty sure it explicitly doesn't support Unity remote right now or something
Hello, i was wondering for topdown movement how i would best check if the mouse is currently being used or a different device like a gamepad.
I borrowed this code from the open project InputReader.
private bool IsDeviceMouse(InputAction.CallbackContext context) => context.control.device.name == "Mouse";
I was wondering if the mouse isn't being moved and you move the gamepad stick if it then will not say that the device is a Mouse but a gamepad?
Like it's mostly for aiming in topdown, if i have a mouse the character will go point to the position but if there is a gamepad then it will be pointing in the gamepads left stick direction
I mostly need to make the player aim depending on the current input, if it's the mouse it will use the position in the world to look at the camera and if it's a gamepad anything where the movement is with a joystick it will use the direction the player points it in
public void Move(InputAction.CallbackContext context)
{
horizontal = context.ReadValue<Vector2>().x;
}
``` This doesn't detect the input, I think I setup the Input Actions correctly
did you enable the action?
Depends what you mean by that
I made a Player Input on my player and assigned all properties with my Input Action, and made the buttons inside the Input Action
Show screenshots of your setup
void OnEnable()
{
input.Game.Enable();
}
I am not fully sure how you would need to do it but something like this, you need to enable inputs when using callback context
you dont need to do this when using PLayerInput^
oh yeah wasn't sure, i had this myself but i generated a custom class. I know that Inputvalue also works if you use that instead of callback context like this
void OnMove(InputValue value)
{
moveVector = value.get<Vector2>();
}
something like this
Any reason it wouldn't work then?
Have you put Debug.Log inside the Move method to see if it's being called?
Neither are being called not Jump or Move
try checking the names of your inputs when it's on a component
like what methods it says
check if the name matches
could be you need to say OnMove not just Move
Can you show a screenshot of your player object in the scene?
ideally showing the hierarchy, with it selected and the inspector
ok dumb question - you're in play mode? You started the game?
Yes
Can you try clicking on the game window to give it focus?
could it be they do need to do the enable somewhere?
Clicking didn’t do anything
also can you show a screenshot of your console window while playing
and after you did some input
It's the same nothing changes or happens
You mean Default Map? Default Scheme only has Any
I put Default Scheme to any still nothing
I'm not really sure
I think it might be something with the Input Actions but I have no clue what
seems like it should work
I followed a tutorial so I'm thinking it should work too
maybe you can temporarily try a different way of handling inputs if you don't mind
Sure
You can use the send messages method to handle inputs like this
so for move it would be
public void OnMove(InputValue value)
{
moveVector = value.Get<Vector2>();
}
if i am correct something like that should work with the send messages method
yes that should work with SendMessages
if you don't need any extra checks this method of handling input should be fine
Doesn't work unless I did something wrong
check if the playerinput is on send messages and if it shows methods like OnJump and OnMove
Hoenstly try a fresh scene
ANd maybe a fresh Input Actions Asset
with an empty GameObject with your script and nothing else
something fishy is happening here
I made this project the other day added my player, today I switched to input system and made the script nothing else
if you use the inputvalue this should be your setup, where my red arrow points at you need to see the 2 extra methods OnJump and OnMove
Yeah I did see that
also the methods right
So I have this.
public void OnMove(InputValue value)
{
horizontal = value.Get<Vector2>().x;
}
``` And this
normally that should work
no Debug.Log?
i guess you can try what Preator said, i don't think there is anything else that you need if you use inputvalue than this and it should work
Doesn't show in console
where did you put it
Under the horizontal = line
and no errors in console? And errors are enabled in console?
No errors, they should be enabled
The issue is just the input system, everything has worked in other projects with normal input, I don't think it would be anything with the script or the project
What are the default steps? Import, create Input Actions, make a script do the callbacks, assign them in the Player Input component then it should work? This is what I did
Dumb question but
Project Settings -> Player -> Active Input Handling
what is it set to?
Input System Package (New)
Try restarting Unity?
Is there no other steps like enabling the input actions or anything?
Restarting didn't work either
I myself use a generated class where i implement the interface from
i always need to do this for my inputs
private Input m_Input;
private void OnEnable()
{
if (m_Input == null)
{
m_Input = new Input();
m_Input.Gameplay.SetCallbacks(this);
m_Input.Gameplay.Enable();
}
}
Here input is my generated class, and gameplay is my collection of actions (action map)
I have that too or something similar
I mostly took code from the open project since it looked like a good way to implement inputs
I am wondering about something myself now, i want to make my player rotate towards my mouse or if my gamepad is being used towards a sticks direction
But i am not sure how to properly handle the check if one or the other is currently being used