I'm confused, with the Player Input: I use 2 Schemes UI and my Own. If i preset the Control Scheme to Any both working, but if i set them to mouse & keyboard, only the UI Scheme works and the custom one doesn't. Any Idea what i missed ?
#🖱️┃input-system
1 messages · Page 26 of 1
Is the entire composite also marked as being part of the Keyboard&Mouse control scheme?
Hey, I'm still having issues with my button not detecting hovering/clicks
My Event System is set up like this:
Does anyone know of any guides on building a combo input system? Specifically, I'm running into an issue of animator triggers not interrupting exit transitions from the current animations, making combos very sluggish feeling
I have a script that increments a currCombo int. At a specific point on each animation clip, there's an event that plays which calls SetTrigger based on the currCombo value
However, if you press the combination at speeds less than instantaneously, the transition to the next attack seems to be ignored in lieu of the transition to Exit
Even though each Exit transition has an interruption source of the Current State
Click on one of the states and check the order of the transitions
if Ordered Interruption is turned on (which I prefer!), a transition higher in the list can't be interrupted by a transition lower on the list
I checked, and the transitions from attack to attack supersede the transitions to Exit
Yet the actual transitions to Exit won't get interrupted by the next trigger
Can someone please explain to me why the camera isn't rendering?
Because luigi too fast to be caught
Target Display isn’t even appearing in the camera component
wrong channel lol #💻┃unity-talk
Hey, I'm experimenting with the new input system to understand it better. And I'm trying to test this:
I set up my actions like so
But when I do Shift + A, both actions trigger
What am I missing in this case?
I am subscribing to all actions on the Input Actions Asset (easier to test) by iterating over them and adding to (among others) the .performed event
But the same behaviour is present with PlayerInput component and Unity Messages
Update: Solved
Turns out this behaviour is not enabled by default and the documentation does not mention it
Isn't it doing exactly what it says would happen in the documentation?
No, according to the documentation only one of the two should trigger.
And it does that, if I enable the toggle for it in the input system settings
That's not what it says at all. it says both will trigger.
which toggle are you referring to?
Oh, my bad. Copied the wrong fragment of the docs
Project Settings -> Input System -> Somewhere at the bottom
I still cannot fix this. I also created a topic here with more informations (https://discussions.unity.com/t/inputs-works-with-any-scheme-but-no-with-keyboard-mouse/1569864) I'm glad for any help
Stupid question, that I believe has been asked to death over and over again - how do I properly implement a button where it checks if it's being held down?
if you think it's a common question, have you tried googling about it?
anyways, what do you mean by "checks if it's being held down"?
like, do you want do something each frame it's held down or something?
Oh, did try googling it, and asking ChatGPT (unpseakable, I know), but pretty much every answer I got is me needing to use InputAction.CallbackContext, which it doesn't really work for me
In the Player Input component, I have set the behavior to Send Messages, and it has worked well for translating Vector2 values into movement and simple buttons where you only need to press once. But for some reason, I just can't properly wrap around my head on how to check whether the button is being held down, or alternatively, where you change the boolean values
wait by "button" do you mean like, ui button, or a physical input device button
Physical input, I think? By pressing/holding down a button, I mean an action created in the Input Actions Editor, where the Action Type is set to Button (rather than Value or Pass Through)
ok, i thought you meant a ui button at first lol
basically, I added an action of button type instead of value
how to check whether the button is being held down
by this do you mean you want to have an action for holding down the button (as opposed to a tap & release), or to just have a function to get whether or not the button is currently held?
Umm... Is there difference?
the former would be an action triggered when the button gets held
the latter would be some method to query in some arbitrary frame, whether the button is held or not
Is the former being only called once? Whether it recognizes that it's held down or released?
yeah
Then I'll go with that one, I think
like, if you press it and release it, it won't trigger
if you press and hold it, it will
in that case you can just add an interaction in the action properties pane
Oh,
Then in that case I'll switch my decision then
(to be clear; im asking because im not quite sure what it is you want from the description, if you could explain what you're trying to do that could help)
I want to add a button that will let the player run in the 2D plane by checking the boolean, where if the button is being held down, the boolean would be set to true, and if not - vice versa
Previously I managed the holding of the Run button by setting it's action type to Value, and by setting the threshold manually in script, but I thought that was counterproductive since "why do I need to reinvent the wheel when Unity provides me with that option already" - but for some reason it created more problems than solutions
ah ok
button type actions only trigger when they're pressed, not when they're released, so pretty sure you do just want a value here
Really? Aww man...
actually seems like it is possible: https://gamedev.stackexchange.com/a/208260
but given the kind of, i guess, "intent" of button vs value, i think value would make more sense here
buttons are like, triggers to perform some specific action
rather than a modifier, which you're going for here
Ah okay, gotcha
doing it with a value would be pretty straightforward
Anything else I should know about the new input system? I feel like I've been fumbling the bag when it came to implementing it properly
uhh not in general, i can't think of any general tips for transitioning
that's kind of a broad question
Okay, how about umm....
When do I need to use Interactions/Processors when mapping an action?
have you tried adding them to see what they are?
No, I did not - I'll look into those myself. Thank you for the help.
Does anyone have problems with rebinding actions using the current InputSystem (1.11.2) in Unity 6? I've tried the Rebind UI sample that comes with already written code in order to rebind a specific action but even there, it says it's rebinding but it really isn't. Did anyone else encounter this issue?
What makes you think it isn't rebinding?
The most likely issue from your description is that you are rebinding a different instance of the actions asset than you are using elsewhere in the code.
I guess i'm doing something wrong. I've got it to work in an older project using Unity 2022 something. Now i just opened a freshly new project with Unity 2022 again and tried the same thing with the sample again. Still doesn't work. Now i at least know i'm the problem😂
Well i mean it's possible there's a bug. But most likely your code is the problem.
Yes i will check that out again tomorow. It's driving me crazy when you know you got it one time and the next time it doesn't work
hello, I would like to ask or some help. I have webgl application and have some weird touch behavior with input,
I have full screen webgl (black rectangle) then zone 1 which is just webgl and then zone 2, where HTML UI is. When webgl focus is lost, I disable input on webgl, and return when it gets focus again. Everything works as intended as long as there are one finger on the screen 1 or two finger on screen 1. However if another finger touches screen two, glichiness begins. It return me values and keeps alternating between them;
example:
mouseDelta keep alterating between** (-42.00, -867.00) -> (42.00, 867.00)**
When mouseDelta values with one finger looks more like this (-3.00, 0.00).
I wonder if anyone seen this behavior and knows how to fix it or have workaround about it.
public void OnLookRawInput(InputAction.CallbackContext context)
{
Debug.Log("context:" + context);
if (isRotating && !isPinching)
{
Vector2 mouseDelta = context.ReadValue<Vector2>();
ProcessLookInput(mouseDelta);
}
}
Is there the possibliy that, if i spawn the player-Prefab. That it's own Input system isn't subscribed to the Input-Controller? Because none of my input work with the player
mouse delta is probably not the right type for touch input.
sounds like when you have 2 touches, the delta alternates going between those 2 touches
Hi, my Unity UI input doesn't seem to work. I am using the new Input System. When I am using Arrow Keys and/or Enter nothing happens. Any clue why this is happening? I am trying to fix this for over an hour.
- Is there a good reason you're using a custom action map for the input module?
- did you make sure to Enable() the asset?
I initially used the default one.
However when I noticed that it didn't work
- are we sure the arrow keys and enter are hooked up to the appropriate actions?
I changed to test
Yes
What wasn't working about it
Same thing I am describing in the message. No input in the UI works.
What are you expecting the arrow keys and or Enter to be doing that they're not doing?
I would definitely switch back to the default
the problem likely lies in your scene setup
Using a custom asset is adding more uncontrolled variables. We know the default one works under normal circumstances
Well, I just changed to the default one. In my scene with the Visualize button it shows the arrows correctly
So button selection should work with arrow keys
sure that assumes you have a button selected in the first place
I do
YOu would need to do EventSystem.current.SetSelectedGameObject(playButton);
yeah for whatever reason that First Selected thing has never worked
in the last 10 years I've used Unity
I don't know what its deal is
Hmm, interesting. I remember it used to work, however that may have been when I was using the old input system
Hmm, this doesnt work at all for some reason.
I also tried the Select() method directly on the button but it still doesnt work?
OOOOkk nevermind
I had a thing that messed things up in the update function
Thanks a lot for your help!
Would this be the equivalent of the Axis in old input system?
Where you could use GetAxis("Horizontal")
axes
As long as the type of the "Horizontal Movement" action is Value, with a control type of Axis
oh whoops misread the question
but yes
you could make it have multiple axes as well
Ayup that`s what I did
I assume you don't just use GetAxis with the new input system
Gotta search how to do that
Right. You get the value of the Horizontal Movement action
The new input system gives you a lot of ways to access this. It can be a little overwhelming at first.
Good thing I already have coffee then
personally, I like to use a PlayerInput component to handle turning on the actions for me, and then I use InputActionReference fields to refer to specific actions
an example:
[SerializeField] private InputActionRefrence horizontalMovementRef;
void Update() {
float input = horizontalMovementRef.action.ReadValue<float>();
}
and then you just slam a Player Input component somewhere in your scene (probably on the player object...) so that your actions get turned on
Oh I didn't knew that PlayerInput component existed
Is it just a pre-built Input Action?
It's not an "input action", no
It's a component that manages:
- Turning input action maps on and off
- Calling methods when input values change
You can have it call a method when a button is pressed, for example
Can't say I'm not confused about the difference
An input action is just a definition
This is an input action called "Zoom"
It has two bindings -- the scroll wheel and the d-pad
This does absolutely nothing on its own. It's strictly a definition of a kind of action.
This is the Player Input component. You give it an input action asset. It handles enabling/disabling groups of input actions. It will also call methods for you when the action values change.
Aah
I still gotta move my Input Action to that component
So it knows about it
It looks like you're editing an input action asset here.
You'll assign that asset into the PlayerInput component.
The asset stores action maps, and action maps store actions
I created a new one for that
I have different groups of actions for different situations. I can have any combination of these enabled at once
In your case, though, you'll probably just have one map
I see, thanks
Do I have to generate a new C# for every Input Action Asset I create?
you don't have to generate any of them
I couldn't use it in code without generating it tho
Was I doing it wrong?
Obviously if you wish to use the generated C# file in your code, you must generate it
I was simply commenting on the fact that the generated C# file is never mandatory to use. It is a convenient helper.
Ah ok
Hey all, im trying to setup input for VR, and i will need 3 sticks in order to handle everything, as most controllers only have 2 analog sticks in total, i plan on having it so that when you hold in the stick, it acts as a modifier key in order to make it do a different action, I've tried setting it up in the input manager, but for some reason the only option i can see for "binding" is the simulated input, is this fine, or am i doing something wrong? I suppose i could always handle it in code instead, but if it's possible to handle in a neater way outside of code that would of course be preferred, thanks
Question:
I have an Input System set up here, and I am trying to write code to detect if the player is taping, holding, or releasing the Key. However, the line "Hold" only shows up once, even though I am holding the jump key. Does anyone know how I can fix this?
{
playerControls.Player.Enable();
playerControls.Player.Jump.performed += Jump;
playerControls.Player.Jump.started += Jump;
playerControls.Player.Jump.canceled += Jump;
}
private void OnDisable()
{
playerControls.Player.Disable();
playerControls.Player.Jump.performed -= Jump;
playerControls.Player.Jump.started -= Jump;
playerControls.Player.Jump.canceled -= Jump;
}
public void Jump(InputAction.CallbackContext ctx)
{
if (ctx.started) {
Debug.Log("Tap");
}
if (ctx.performed)
{
Debug.Log("Hold");
}
if (ctx.canceled)
{
Debug.Log("Released");
}
}```
You only get callbacks when the state changes
consider this
if (playerControls.Player.Jump.IsPressed()) {
}
That's how it works, there's nothing to fix
If you want to run code every frame, you can use Update
Note that your "tap" and "hold" labels are pretty misleading here
because Tap and Hold are built-in Interactions you can apply to your actions
Tap performs if you press and release the button quickly enough
Hold performs if you press and hold for long enough
I guess you are right... English is not my first language. I should just use the word started, performed and Cabceled.
Thx, I change my code to this and it work like a charm now
void Update()
{
if (playerControls.Player.Jump.WasPressedThisFrame())
{
Debug.Log("started");
}
if (playerControls.Player.Jump.IsPressed())
{
Debug.Log("performed");
}
if (playerControls.Player.Jump.WasReleasedThisFrame())
{
Debug.Log("canceled");
}
}
any reason ur using the new-input system when ur polling for inputs anyway?
for binding? for multiple players? just genuinely curious
Sorry, what do u mean by "polling for input" ?
the new system is designed with multiple ways to use it, there's nothing wrong with doing that
Oh is he asking me why I hard code the input system?
polling like checking per frame in update rather than the other methods like subscribing to events or whatever
like normally
if all ur doing is polling in Update
I have function like this that I need to know the Action Phase of the Key
if(Input.GetKeyDown(KeyCode.A); for example
I can't get the action phase if I use other behavior, And it is easier to change the key bind if I use the new input system
aight thanky 🙂 i debating on changing out my project for keybinding reasons
just wondering ur reason
I'm experimenting with EnhancedTouch and I have some odd behavior ...
For instance the floating joystick is display on its former coordinates one time out of of two
And buttons that i use are triggered also one time our of two
Floating joysticks and buttons sound like OnScreen Controls, not enhanced touch
Hey, I'm still experimenting with the new Input System and I tried to create a simple scenario of sorts to check some features.
I made a simple "state machine" player that can either be in a fighting mode, building mode or can drive a car. And I wondered how I could handle the input for those modes, as the inputs obviously overlap.
In the end I went with 4 input maps, and toggled them based on the state. Here's that approach visualised
You can see which input maps are enabled based on the opacity, and you can see how the events are triggered
I'm curious how you all would approach the same issue? Is there some nice and clever way to handle those kinds of "hierarchical" input mode switching better?
Put the "shared" actions in a separate action map
You can enable more than one at a time
Yeah, that's what I am doing as seen in the demo above. I have "Common" for things that are shared between the fighting and building modes
That's how I would do it
Although I also don't see the harm in having separate actions for the move in the different modes for example
The only reason to keep them on one action is if you want rebinding to automatically be the same for them both, but likewise it prevents you from having any different settings on the action for the different movement styles
Wouldn't that be awful for maintenance? Any time you are making changes to those actions you would have to remeber to copy paste them to other modes
That depends heavily on how your game works
I have no idea how similar those things are
If they're really always going to work the same way then sure keep it how you have it
I'm imagining walking around vs driving, which are usually quite different
In this case it's a purely abstract scenario... think Grounded, Raft or something like that
Yeah, that's why those I have in a completely separate maps
Well it's fun to think about purely abstract scenarios but eventually you will make an actual game
Yeah, of course. That's why I'm learning how to use the input system properly, because my current way of gathering input does not scale well
I'm talking about an abstract scenario because I just picked one that sounded like a "complex enough game mechanic to warrant a bit more complex input map setup"
As at this moment among the games I made, I don't have a concrete example that forced me to implement those systems
Alright well I would recommend what you have here. I'm not sure what wouldn't scale about it
I'm not sure what wouldn't scale about it
Oh, I mean my previous solution in the projects I already made. Those where I did not yet use Input Actions
(For context, previously I used either the old input like so Input.GetKeyDown(KeyCode.W) or I used the new input system in a similar way by doing Keyboard.current.wKey.wasPressedThisFrame)
so I should somehow save touchId or some other identifiers and ignore all other touches? However context don't return any id of new input systems.
public void OnLookRawInput(InputAction.CallbackContext context)
{
}
I tried to capture the identifier but without luck. Currently i just ignore values that are too big from expected and it works.
Thank you for your answer, if you have idea how to get context id to help ignore unnecessary data it would be great.
ignoring large values could mean fast swipes on slow devices don't get registered
or quick swipes wont be triggered as well. Well it is better than nothing. What about
Vector2 mouseDelta = context.ReadValue<Vector2>();
if (Touchscreen.current.primaryTouch.delta.value == mouseDelta)
This way I ignore values of secondary touches. As long I assume that primary touch does not change. Building right now to test it. Could it work?
Nwm. It seems primary button keeps changing as well and don't fix the issue.........
have you changed the input type?
you mean action type? action type-> pass through and control -> type button.
yeah control type
sorry wrote wrong info. its Delta [Pointer]
which should work with mouse or touch the same
that's the binding path, i do mean the control type on the action
Yea, but just tested it does not fix problem either.
ok with control type delta, try setting a separate binding for touch control scheme that uses Primary Touch/Delta instead of Delta [Pointer]
Nope. Still the same behavior. It really seems more like a bug when HTML element is introduced to touch rather than setup problem 😦 as pinch controls works perfectly.
I found some approaches that use EnhancedTouch to display the joystick where the player touches. You said that there's another way?
Yes, OnScreen Controls in the new input system
Thanks, I'll look that up
While experimenting with input rebinding I ran into an interesting issue. Mouse input
Typically I can guard my functions using EventSystem.current.IsPointerOverGameObject(); for every action that would typically use mouse buttons. But I want to allow the user to rebind the keys I essentially have to do that check for every single event and input poll (as in .ReadValue.
It's doable but seems a bit annoying, is there a way to add some sort of middleware to the input actions instance? Something like this
playerInputActions.Middlewares.Add((next, ctx) => {
if (ctx.control.device is Pointer && ...)
return;
else
next();
});
I can't see anything like that in the docs tho
I wonder if you could use an Interaction for this
Interactions can change when an action is started/performed/cancelled
existing Interactions include things like "Tap" and "Hold"
In theory I could, assuming there is no extra data I would have to pass there (likely not)
I could probably do it in code (as in, injecting interactions into the new instance) to avoid a mistake of forgetting to do it in the editor. Would that handle the input polling tho? I would assume so
If not, I guess processors are able to handle the polling part
Are these for interactions where you're e.g. clicking on something in the scene?
Yes and no. It could also be a top down shooter with clickable UI elements
It's more likely to be the latter actually. For the former I would probably use the event system directly or I would lock the mouse to be non-rebindable (for consistency with UI)
Right I was going to suggest using the event system for everything instead of the EventSystem.current.IsPointerOverGameObject() hack
you can do that even for a top down shooter for example
I've made custom raycasters in the past to make that easier (with Plane.Raycast)
Yeah, I made my own casters too. Tho my preferred method was to have a low priority caster that always reports a hit and passes it to whatever I wanted
But in some scenarios I found that approach to be rather annoying
Especially for clicking on 2D objects... but that's a discussion for a different channel :v
I'm exploring the internals of the PlayerInput to understand how it handles the actions asset itself. Any clue why it applies binding overrides like that?
it's done as part of InitializeActions method called somewhere in OnEnable (I think)
PlayerInput.cs:1204 for those who want to see the context
I was looking at this very recently, actually
(but I also didn't get the point of it)
Looking into this code is... scarring. I don't get at all what's the point of this overriding. After all, the maps should be identical due to Instantiate.
And I cannot grasp why the decided to pass parameters to the PlayerInput component via static variables and not something like an Init method
-# And at this point I'm kinda terrified of the idea of diving into local multiplayer support next
Okay, I'm looking all over the place. Is there a way to find the first binding in an input action that matches a specific device?
I'm trying to do a simple rebind of a key, and at this point I am here
var action = actions.Main.A1;
var matchingBinding = action.GetBindingIndex(path: /* ... something here that matches the keyboard */ );
var wasEnabled = action.enabled;
action.Disable();
rebindKeyboardButton.interactable = false;
action.PerformInteractiveRebinding()
.WithCancelingThrough("<Keyboard>/backspace")
.WithControlsHavingToMatchPath("<Keyboard>/*")
.WithTargetBinding(matchingBinding)
.OnComplete(op =>
{
Debug.Log($"Rebound '{action}' to '{op.selectedControl}'");
op.Dispose();
if (wasEnabled)
action.Enable();
rebindKeyboardButton.interactable = true;
})
.OnCancel(op =>
{
Debug.Log($"Cancelled rebinding '{action}'");
op.Dispose();
if (wasEnabled)
action.Enable();
rebindKeyboardButton.interactable = true;
})
.Start();
If there is any better way, do let me know. Basically I want to grab the first binding matching a specific device (Keyboard/Mouse/Gamepad) and want to interactively rebind it
I see MaskByGroup, is that really the only option?
Is it recommended to use Vector2 value for 2D movement?
That's what Unity 6 has by default here
What else would you use?
anyway - the defaults are just examples
pick whatever makes sense for your game
I was using a 1D axis with a float value, and adding rigidbody force using said float value
that's not 2d movement then
that's 1d movement
Regardless, use whatever makes sense for your game
ok
Just to confirm OnScreen Controls is just to display control on the UI
But I already have a joystick on my game. Now I want to improve it so it is "floating' meaning it is hidden when there's no finger on the touch screen and I want to display the joystick where the player pressed
EnhancedTouch is convinient cause it fires different calbacks with the coordonates where the player touched the screen
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerControls : MonoBehaviour
{
[Header("Player Settings")]
[SerializeField] private PlayerInput playerInput;
[SerializeField] private int playerIndex;
public Vector2 MoveInput { get; private set; }
public bool JumpPressed { get; private set; }
public bool DashPressed { get; private set; }
public bool AttackPressed { get; private set; }
public bool CounterAttackPressed { get; private set; }
private PlayerInputActions inputActions;
private void Awake()
{
// Create new input actions instance for each player
inputActions = new PlayerInputActions();
// Get the PlayerInput component
playerInput = GetComponent<PlayerInput>();
// Set the player index based on PlayerInput
playerIndex = playerInput.playerIndex;
// Switch control scheme based on player index
if (playerIndex == 0)
{
playerInput.SwitchCurrentControlScheme("Keyboard", Keyboard.current);
}
else if (playerIndex == 1)
{
playerInput.SwitchCurrentControlScheme("Gamepad", Gamepad.current);
}
}
private void OnEnable()
{
EnableAllInputs();
}
private void OnDisable()
{
DisableAllInputs();
}
private void EnableAllInputs()
{
inputActions.Player.Enable();
inputActions.Player.Move.performed += OnMove;
inputActions.Player.Move.canceled += OnMove;
inputActions.Player.Jump.performed += OnJump;
inputActions.Player.Jump.canceled += OnJump;
inputActions.Player.Dash.performed += OnDash;
inputActions.Player.Attack.performed += OnAttack;
inputActions.Player.CounterAttack.performed += OnCounterAttack;
}
private void DisableAllInputs()
{
inputActions.Player.Disable();
inputActions.Player.Move.performed -= OnMove;
inputActions.Player.Move.canceled -= OnMove;
inputActions.Player.Jump.performed -= OnJump;
inputActions.Player.Jump.canceled -= OnJump;
inputActions.Player.Dash.performed -= OnDash;
inputActions.Player.Attack.performed -= OnAttack;
inputActions.Player.CounterAttack.performed -= OnCounterAttack;
}
// Input Action callbacks
private void OnMove(InputAction.CallbackContext context)
{
MoveInput = context.ReadValue<Vector2>();
}
private void OnJump(InputAction.CallbackContext context)
{
JumpPressed = context.performed;
}
private void OnDash(InputAction.CallbackContext context)
{
DashPressed = context.performed;
}
private void OnAttack(InputAction.CallbackContext context)
{
AttackPressed = context.performed;
}
private void OnCounterAttack(InputAction.CallbackContext context)
{
CounterAttackPressed = context.performed;
}
}
I'm trying to set the controls based on the playerIndex
but it's giving me this error
InvalidOperationException: Cannot set control scheme 'Keyboard' by name on user #0 as not actions have been associated with the user yet (AssociateActionsWithUser)
UnityEngine.InputSystem.Users.InputUser.TryFindControlScheme (System.String schemeName, UnityEngine.InputSystem.InputControlScheme& scheme) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Plugins/Users/InputUser.cs:520)
It wouldn't matter because your inputActions object that you're subscribing everything to is not associated with that PlayerInput component at all anyway
basically PlayerInputs are going to grab a set of input devices to assign themselves to, you can't really change which devices manually when dealing with a local multiplayer situation
you need to either go all in on PlayerInput/PlayerInputManager or don't
how tho? can you explain?
On that note, as I will likely be diving into that soon.
I assume there's no way to "inject" a set of actions into the PlaterInput component for it to handle all the device assigning, local multiplayer and stuff.
What's the recommended way to get something close to static typing when working with PlayerInput? Last time I checked it was a bit annoying to handle
I assume there's no way to "inject" a set of actions into the PlaterInput component for it to handle all the device assigning, local multiplayer and stuff.
Nope.
static typing with PlayerInput
you don't
Oh, so I have to either accept that it will be all strings (awful) or I have to recreate the behaviour of PlayerInput component on my own?
If so... that kinda sucks. And I'm surprised the API does not account for it
PlayerInput can also use UnityEvent mode or Send Messages mode
But the PlayerInput component is really only intended for local multiplayer and rapid prototyping
How to make multiple PlayerInputs work using the same device?
My PlayerInputActions are setup like this:
Then I have a PlayerInputLogger prefab with a PlayerInput component using my PlayerInputActions asset and my PlayerInputLogger component:
Here's the code for PlayerInputLogger component:
public class PlayerInputsLogger : MonoBehaviour {
public InputActionReference Action1;
void Start() {
Action1.action.performed += _ => Debug.Log("Action 1 performed");
}
}
Then, I have PlayerInputsSpawner object and the component in the test scene. Here's the code for PlayerInputsSpawner component:
public class PlayerInputsSpawner : MonoBehaviour {
public GameObject PlayerInputLogger;
void Start() {
PlayerInput Player1 = PlayerInput.Instantiate(PlayerInputLogger, controlScheme: "KeyboardP1", pairWithDevice: Keyboard.current);
PlayerInput Player2 = PlayerInput.Instantiate(PlayerInputLogger, controlScheme: "KeyboardP2", pairWithDevice: Keyboard.current);
}
}
When I start the game, here's how the scene looks like:
It logs only when I press on the G key and not Numpad1 key
When I switch the control schemes on the spawned objects, it logs when I press numpad1 key but not the G key
Only the first instantiated object is working.
I'm trying to do it this way, because it was recommended to do it this way in thoses threads on the forum: https://discussions.unity.com/t/2-players-on-same-input-device/762490
https://discussions.unity.com/t/multiple-players-on-keyboard-new-input-system/754028
Apparently, the problem is that I use InputActionReference. Once I changed it to just SendMessage and defined OnAction1 on my PlayerInputsLogger:
public class PlayerInputsLogger : MonoBehaviour {
PlayerInput PlayerInput;
void Start() {
PlayerInput = GetComponent<PlayerInput>();
}
void OnAction1() {
Debug.Log($"{PlayerInput.user} Action 1 performed");
}
}
It started working on both game objects.
yeah if you're using InputActionReference that is NOT using PlayerInput
that's a totally different workflow
That's just what I've started using when I started using the new input system, I learned it from one of the YT videos or something.
Wha about C# events?
I see it has option for C# events, how could I make that work?
Do I need to define the delegate and the event myself on the PlayerInputsLogger component?
Similarly to how I defined the function OnAction1?
What about it?
You can use any mode of operation you want on the PlayerInput component
No - the C# events mode uses this event: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.11/api/UnityEngine.InputSystem.PlayerInput.html#UnityEngine_InputSystem_PlayerInput_onActionTriggered
Well actually it uses all of these
But even when I use this InputActionReference, I still need to have the PlayerInput component on that game object and need to have the specific input actions asset selected in it, and then I have to drag the specific action in the editor onto InputActionReference to make it work.
Yeah, I'm just surprised that there's no API like
myInputActions = MyInputActions.CreateFromInstance(playerInput.actions);
```or for example
```cs
public class MyComponent : PlayerInput<MyInputActions>
```(the latter would be really cool)
The PlayerInput component on each player creates its own instance of the InputActionAsset
This is what I asked them for
it would be lovely
I assume you can implement split screen without using that component to still have the static typing benefits, right?
It will just be a tedious work of reimplementing stuff
Yes, you would have to manage the player device mapping stuff on your own, which is annoying
you can still get static typing with UnityEvents mode, but not autocomplete
WAIT, the generated class uses the asset internally anyways? Why didn't they add it already then, it seems like a simple change.
Also, great minds think alike 😉
But with UnityEvents you instead get "annoying drag and dropping in editor" when adding new actions and such
indeed
At the very least I would welcome some constants so I can do
playerInput.actions[MyInputActions.Paths.Common.Move]
It would be... bad, but better than nothing
Ok. So what's the way to get InputAction objects of the current PlayerInput object?
Docs show: PlayerInput.actions["fire"]. I guess I can do it, but I thought that's what InputAction reference was for. If I do it manually in the code, if I rename it in the asset, I'll have to go change it in code too now.
Yes you can do it that way if you want, but the more standard way to use PlayerInput is to NOT get the InputActions at all and use the modes provided:
SendMessages
UnityEvents
C# Events
I want to be able to get access to performed and cancelled events
Not just when it's triggered
Is there OnAction1Cancelled message then?
UnityEvents provides that
It gives an InputAction.CallbackContext from which you can read the phase
I guess UnityEvents would be protected from renaming... right?
Because the other two will run into the same problem, I think
Depends what you're renaming
On a different note, adding that functionality seems trivial. You think they accept PRs?
I don't think so. You can try - but a like/comment/bump on that thread might help too.
Looking at your example code, do you even need ValidateAssetConformsToJson(existingAssetInstance);?
Wouldn't throwIfNotFound: true solve it already?
I will throw my suggested change into the comment
Reading through the code... I started to wonder how hard would it be to just not give the PlayerInput an asset 🤔
So instead of letting the PlayerInput handle the asset, we would just do
actions = new MyInputActions();
playerInput.actions = actions;
```did you try that before?
playerInput.actions is not writeable
also I think that messes with the device assignment?
oh it is yeah, sorry I think it breaks the device assignement stuff though
try it out and let me know though!
though i think it would need to be:
actions = new MyInputActions();
playerInput.actions = actions.actions;```
actions.asset
ah yes that
Just tested that :v
hmm this is slightly promising though?
I have to test it later fully, but just checked the compilation
Yeah, it seems to reassign the user to the actions set
I do remeber having some issue with it tho...
But maybe I tried something else
same
But I don't remember what it was
Okay, before I tried something different
But that did not work because the user was not created if there wasn't an asset assigned
This could work then
Learning this package feels like some kind of adventure... because I have no clue where I would have to look to figure that out from the docs
Yeah, the docs don't mention this workflow for some reason
Is this using the generate C# class from the asset?
Yes (tho it's not a good approach, we discussed a better one)
What is it?
I've read the chat but I don't understand
input = new PlayerInputActions();
playerInput.actions = input.asset;
But it is yet to be fully tested
I see
Yeah, this works:
public class PlayerActionsReporter : MonoBehaviour {
public PlayerInputActions PlayerInputActions;
void Awake() {
PlayerInputActions = new PlayerInputActions();
PlayerInput PlayerInput = GetComponent<PlayerInput>();
PlayerInput.actions = PlayerInputActions.asset;
PlayerInput.user.AssociateActionsWithUser(PlayerInputActions);
PlayerInput.SwitchCurrentControlScheme(PlayerInput.defaultControlScheme, Keyboard.current);
}
}
Now I can have player input reporter objects adequately and access them in a typed way.
public class PlayerInputsLogger : MonoBehaviour {
public PlayerActionsReporter PlayerActionsReporter;
void Start() {
PlayerActionsReporter.PlayerInputActions.Player1.Action1.performed += _ => Debug.Log($"Action1 Performed");
}
}
And have multiple of them and it will work for the same keyboard.
Need to make sure that I choose the correct asset in the PlayerInput component.
Interesting
This is working out alright:
public class PlayerController : MonoBehaviour {
public PlayerActionsReporter PlayerActionsReporter;
InputAction Movement;
InputAction Action1;
InputAction Action2;
public Character ControlledCharacter;
void Awake() {
Movement = PlayerActionsReporter.PlayerInputActions.ActionMap.Movement;
Action1 = PlayerActionsReporter.PlayerInputActions.ActionMap.Action1;
Action2 = PlayerActionsReporter.PlayerInputActions.ActionMap.Action2;
Action1.performed += _ => ControlledCharacter.Action1.Start();
Action1.canceled += _ => ControlledCharacter.Action1.Stop();
Action2.performed += _ => ControlledCharacter.Action2.Start();
Action2.canceled += _ => ControlledCharacter.Action2.Stop();
}
```Then in the Character itself I respond to the actions starting and stopping, too. This way I can have any number of PlayerInput objects even if it's the same keyboard and hot swap them on the player controllers, controller only cares that there's PlayerActionsReporter, and specifically that there's the `PlayerInputActions` class.
And everything is typed, so I don't have to work with strings, which is nice.
And I can hotswap the controlled character, too, which I do need, because it's a team game.
A bit irrelevant to the topic at hand but I wish there was an event that was called when the value changes instead of just performed / cancelled or something. It really bugs me having to write performed and cancelled when I could handle them both in one method lol
agreed - I've made helpers for this before - e.g.
SubscribeAll(InputAction a, Action<InputAction.CallbackContext> listener) {
a.performed += listener;
a.started += listener;
a.canceled += listener;
}``` and a corresponding unsub function
Dang I might just have to steal that
What about UnityEvents?
Can I define something like this:
void Action1(InputAction.CallbackContext CallbackContext) {
if(CallbackContext.action.phase == InputActionPhase.Performed) {
}
if (CallbackContext.action.phase == InputActionPhase.Canceled) {
}
}
But I can't choose this function in my PlayerInputComponent
Oh yeah, there we go:
public void OnAction1(InputAction.CallbackContext CallbackContext) {
if(CallbackContext.action.phase == InputActionPhase.Performed) {
}
if (CallbackContext.action.phase == InputActionPhase.Canceled) {
}
}
You can use Unity Events for it if you want.
Well, that's on the game object that you have PlayerInput on.
I had to make the function public to make it work.
You can use that Ethan, I guess, but I'd argue against it for the thing you want to use it for, because you'll inevitably write those if statements and do different things depending on the new state and it's more code, more logic and isn't as clean anymore IMO
Rabobank Livestream 2019 with Uncle Bob | A session about clean coding
The program:
09.00 Uncle Bob - Part 1
11.00 - Break
11.20 - Uncle Bob - Part 2
12.30 - Lunch
13.30 - Breakout sessions (NO LIVE STREAM)
15.30 - Uncle Bob - Part 3 - Including Livestream.
#werkenbijRabobank #RabobankIT #unclebob
Here Uncle Bob talks about it. Well, kinda, it's about passing booleans but that's our case basically.
I don't think any of the actions in mind would really require it as my suggestion was more aimed at generic vector / float related actions
But yeah I completely agree with you when it comes to stuff like buttons
I'm perplexed by the point made in this video tbh
You're gonna have to do an if statement check either way so why not do it in the method?
Of course you can, that's the intended use
though you can and should use a switch
Not necessarily, I've seen it quite a few times where people write methods with if statements in them and then they call this method in multiple places with true/false arguments.
Instead, you can refactor this method into 2 different methods and call those 2 different methods in 2 different places where appropriate.
Consider this:
Log(string Message, bool DisplayInViewport) {
if(DisplayInViewport == false)
Debug.Log(Message)
else
Display.Show(Message);
}
Then somewhere in our code we call Log("Our Log", false) and in another place we call Log("Out Log 2", true).
This can be cleaner, of course, if we completely remove our Log method and just call Debug.Log(Message) and Display.Show(Message); where appropriate.
It's very close to the real life scenario that I saw in a real project:
def log_refresh(message, show=False, do_log=True):
"""
Print a message and refresh the UI.
"""
if show:
show_wait_box(message)
else:
replace_wait_box(message)
if user_cancelled():
raise Exception("Cancelled")
if do_log:
log(message)
That's the one that I could find from the top of my head. And this is a more of a cleaner one where they call functions and there is only one call in an if statement. Sometimes there are tenths or hundredths of lines in each branch.
I am using the new Input System with UIToolkit. I have been messing around with components in the scene to understand how they work together. How is it that my buttons can still receive mouse and gamepad input when I have the PlayerInput component disabled, and I also removed the EventSystem and UIInputSystemModule from the scene? I don't understand where the input is coming from
PlayerInput is irrelevant.
The EventSystem and Input Module are the important ones
it shouldn't work without those.
So I don't have either of those in the scene, yet it is working somehow?
t:eventsystem
still nothing
if it's not there - are you sure those are UI Toolkit buttons and not IMGUI?
I made it in the UI builder for UIToolkit. Is it possible to have IMGUI buttons in there?
Is an event system somehow created under the hood, but does not exist in the scene?
Does anyone else have a bug where I have to press Listen, press the key and then click on the key 2 times each time?
It works only every other time
Interesting. I still can't figure it out though. I tried doing Debug.Log(EventSystem.current == null) and it printed true. So there isn't an event system
I also tried EventSystem.SetUITookitEventSystemOverride(null, false, false); and that didn't work either. I can still hover and click on the buttons.
Right - it's a compltely different system
not using the EventSystem class
What I'm trying to achieve is that I want to be able to control when UI can receive input and when it can't. Basically toggling between player and UI mode. I also want to add some custom UI controls that I'm not sure the default UIInputSystemModule supports. I want to be able to use the bumpers on a controller to navigate left and right between tabs, but then use the joystick to navigate the elements within a tab
Hello. When I click on some buttons in play mode like left ALT or TAB or typical windows button combinations, my system goes crazy because the game in is play mode (it's inside IDE window).
I would like it to act like a separate window because currently I can't do anything in the game because of this crap.
For example in Godot when I start the game it catches all inputs and prevents other applications from catching them as well.
Imagine when I press CTRL+SHIFT+W in the game and my browser closes with all saved tabs. This is beyond sad.
Do you know how to deal with it?
that sounds like you haven't focused the unity editor
your inputs are going to the wrong program entirely
I have focus on game window. When I spress alt+w, the unity's Window panel pops up
and there are many other combinations that makes my game lose focus.
I can't even lock the cursor because it just doesn't work. Probably it will work after exporting the game as standalone app.
cursor locking works fine in the editor
public void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
This surely does not work.
and people confirm that in the internet
does this code actually run?
note that you need to actually click on the game view to focus on it
it won't grab the mouse automatically
(this is an editor-only behavior, along with how hitting Escape always frees the cursor)
yes exactly, but it should because I order that
even if I have a focus I'm losing it after alt+w and other combinations
if the cursor locks after you click in the game view, then everything is working as intended
yes but that's completely not related to my issue
I can reproduce that on Windows, at least. That's annoying.
I think that's just a Windows thing
ohh no, that's surely not 😉
it's unity that can't deal property with key bindings
I will find a way to not use the play mode, it's horrible anyway
that's a bit like saying you'll find a way to not use the gas pedal..
I ratehr wait 500% longer and build the whole game every time.
i don't have a new enough version of unity on my PC to check this, but the little keyboard toggle in the top right of the game view is supposed to toggle unity shortcuts
it's not, you can test it yourself, the problem is that alt+w is a windows shortcut, not unity
building the whole project is a no-go because it takes very long time
Is there a way to make this menu... unbroken?
Or is that just what Unity does in a version I am using
2022.3.45f with Input System 1.7.0
Hey everyone, I'm just getting back to unity for a project after quite a while and I use the "new" input system the first time.
Somehow I'm not sure if I do things right: I want to switch action maps for certain scenarios... fictive scenario would be "switching from player third person controller to a vehicle controller / input action map".
Somehow... this leads me to implementing something like a global solution since I do not want to have the PlayerInput component live on the character gameobject it self... since the player input is something generalist and should persist when the GO of the character is disabled... blablabla...
My Question:
Am I missing some sort of a way to receive the Messages / Broadcasts / Events globally of the new input system?
I do understand that SendMessage broadcasts to the GO it is attached to, Broadcast also to all children... blablabla...
But I was just wondering if there is a globally accessible context or something I'm missing.
what's the issue here exactly?
The top part of the UI being covered by the bottom one (and mouse clicks being iffy)
you might want to just have other objects responsible for responding to input also be able to process inpuy on their own
you can check for specific keypresses/mouse inputs/controller inputs directly but that's not exactly the intended use
ah, yeah. sorry idk about that
It's an educated guess at best, I am still discovering this system. But did you try to reframe how you look at "the object representing the player"?
Basically, instead of thinking of a player as a in-game character, you think of them as a abstract being that possesses a character.
That would solve this issue, because it would all tie into this system. The car would be "possessed" by the player.
The side effect is that it probably will require some plumbing
But that's generally what I used when working with multiplayer (Photon) exactly. Which made things like switching scenes much easier as I could just spawn and assign the avatar to the player that persists all the time
Alternative is to do a hybrid version of that approach by having the player be still enabled. Just with a disabled model for example.
That way you can have the player controlling the car
-# Again, it's just an educated guess based mostly on the general programming knowledge
@austere grotto // Okay, did some test and assigning an asset does in fact work!
This is the code I used
private void Awake()
{
actions = new MyPlayerActions();
playerInput = GetComponent<PlayerInput>();
playerInput.actions = actions.asset;
actions.Walking.Jump.performed += ctx => OnJump();
actions.Walking.SwitchToCar.performed += ctx =>
{
/* ... */
};
actions.Driving.SwitchToWalking.performed += ctx =>
{
/* ... */
};
actions.Walking.Enable();
}
There are some edge cases tho. Two that I found are:
- The player input still tries to enable an action map if you have set one in the past. Even if the enum for that is no longer visible
So make sure you leave it at "<None>" or throw inplayerInput.defaultActionMap = null;for safety - If you enable and disable the maps yourself, Player Input's
currentActionMapwon't be correct as it does not listen to external changes at all
Should I check something regarding that approach? As I already have the project open
@meager ginkgo
I don't know, sorry. I'm new to Unity, I didn't encounter those problems yet.
Oh, just tagged you to inform you about those problem.
It's something one could accidentally run into, but they are trivial to walk around
Nice, gread to know! Thanks for testing it out.
I'd still love the flexibility to do it the other way. This way has some weird caveats like the unecessary creation of extra action assets (and the associated GC)
Honestly, you are saving one asset worth of creation in practice. It's not that bad.
It also saves you the hassle of unsubbing from the events
@inland quail How are you causing OnAim to be called in the code you shared in #💻┃unity-talk ?
I believe whatever you're using only calls that method when the action is performed
You'd want to react to both the performing and the cancelling of the action
I want to let the user control the durations for the Tap and Hold interactions
I see two ways of doing this:
- Subclass each interaction type so I can check a setting to get the duration
- Edit the interactions in my InputActionAsset at runtime
The latter feels scary, and I also don't see how I'd actually mess with the interaction objects anyway
I also see I could just mess with InputSystem.settings.defaultHoldTime/etc.
i think that's for when you haven't set a specific time for an action, it'll inherit the default?
if you've set specific hold times for different actions that you also want to change with it then that wouldn't be applicable
i guess it really depends on your setup and how you want to provide the control
Yeah, and I'd like to have actions with non-default hold times
So I think I'll just wind up doing a custom interaction type
(i might not even try to subclass them -- this will be a copy-pasta operation)
Hello, i made an inventory system by guide on youtube and wanted to change it a bit so i can just press mouse0 anywhere on screen to use item from active slot but for some reason my script just using consumables from whole inventory if there any. I've tried to add check for active slot either to UseItem function and on Update function but it still dont work as i wanted to make it
Here is a logic to change active slot
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Left)
{
OnLeftClick();
}
}
public void OnLeftClick()
{
//if (isActive)
//{
// bool usable = inventoryManager.UseItem(itemName);
// if (usable)
// {
// this.quantity -= 1;
// quantityText.text = this.quantity.ToString();
// if (this.quantity <= 0)
// {
// EmptySlot();
// }
// }
//}
inventoryManager.DeselectAllSlots();
selectedSlot.SetActive(true);
isActive = true;
}
and this is what i've tried
private void Update()
{
if (InputUtilities.PressButton("Use"))
// its input.getButtonDown function
{
if (isActive)
UseItem();
else
isActive = true;
}
}
public void UseItem()
{
if (isActive)
{
bool usable = inventoryManager.UseItem(itemName);
if (usable)
{
this.quantity -= 1;
quantityText.text = this.quantity.ToString();
if (this.quantity <= 0)
{
EmptySlot();
}
}
}
}
Also for some reason any time i press mouse0 i receive 8 messages from debug.log if i use it. Not sure why it happens but it also may be part of problem
Update. I found why it called 8 times. I use this script in every hotbar slot and as a half-working solution i find out i can change active slot and waste 1 consumable from currently active slot to change it and next time use from another activate slot
private void Update()
{
if (InputUtilities.PressButton("Use"))
{
if (isActive)
{
UseItem();
}
}
}
public void OnLeftClick()
{
inventoryManager.DeselectAllSlots();
selectedSlot.SetActive(true);
isActive = true;
}
Hi! So I am running into an issue where occasionally on script compliation my loading bar will load forever stuck on importing/loading the PlayerInput asset, which is my asset for the new input system for the player. After closing and opening my project I get the console message below:
A default asset was created for 'Assets/Input/PlayerInput.inputactions' because the asset importer crashed on it last time.
You can select the asset and use the 'Assets -> Reimport' menu command to try importing it again, or you can replace the asset and it will auto import again.
I tried doing what the console is telling me but it did not fix it. Was wondering if anyone has had this issue before?
i just deleted my XR plugins and it got rid of my input system and now my robot kyle third person controller is going ape
Hi,
I'm struggling to have my buttons work correctly.
Despite having an event manager, they didn't detect clicks & hovers.
I fixed the hover by adding a graphics raycast to my canvas, but still can't detect clicks. WHat do I need to add ?
You need:
- Event System in the scene
- Graphics Raycaster on the Canvas
- Raycast Target enabled on the Image for the button
if the hover is working then the click will work too
I have all three enabled, but the click specifically doesn't work
I know that because it should turn red on click, and it doesn't (using the Pressed Color option)
more likely you just set that up incorrectly
attach a listener function to it with Debug.Log and see if that is working
Here are my three setups
The function, right now, only outputs to log, but nothing is detected
OMG I found it
For some reason the left click was changed
do you happen to have an EventTrigger on it or something
oh yeah
in your input module
That lost me so many hours
Thanks for you help, it made me check all of this twice 🙏
How do I disable a button ?
thx
Does anyone here have experience with arcade guns in Unity? Mine use potentiometers. I'm having a little trouble.
You will get the best help if you explain and show details regarding your issue.
The gun is connected via USB cable. Using Unity's new input system.
Please share code via !code
Posting code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/ , https://paste.ofcode.org/ , https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Anyway there's nothing specific to the actual input processing here. It's not clear what kind of input you're expecting to receive from the device and what you're getting instead
you should focus on that, outside the context of the game itself, for now.
A tool for sharing your source code with the world!
This gun uses two potentiometers. I was getting raw data from them, but as I tried tweaking the code I ended up with only -1, 0, and 1 readings.
Again this isn't the code that actually handles the device setup/input handling.
This is game code
how did you get this custom device reading data into Unity?
other important thing(s) to show would be the Action configuration for this Gun_Controls action
I was able to reset the settings and get the raw data from the potentiometers again.
Project Settings > Input System Package.
I had tried making all the settings 0. I set them back to what they were originally.
I'll have to get rid of the Deadzone.
ah, yes, a Deadzone Max of 0 would cause problems
I'm thinking about switching to the C sharp events for my input but how would I start listening out for those events?
When you use C# events you listen to these events: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.11/api/UnityEngine.InputSystem.PlayerInput.html#events
I've never seen anyone actually use it that way.
Ok, this is not specifically input-system but input manager, when using Input.GetAxis("Horizontal/Vertical" , I noticed that those inputs go from 0 to 1 sorta slowly, I managed to make them go to 1 nearly instantly, but when I let go of the buttons, they slowly decrease to 0, is it possible to make that instant?
use GetAxisRaw, GetAxis comes with damping built-in
Another question, is it possible to change that dampening?
I believe that's controlled by the "Gravity" and "Dead" properties
well, at least Gravity
Ok thanks, I will play around with those.
i think dead might be deadzone?
yeah deadzone
so sensitivity for damping towards the raw input, and gravity for damping towards neutral
does anyone know a good tutorial for the new input system?
alrady took the unity one and it made me more confused
what were you looking at, exactly?
any ideas why my Vector3 Input Actions won't work? I have it set up like normal, but it constantly has a value of (0,0,0)
Have you tried adding Debug.Log statements to make sure your code is actually running?
i did. it only logged at the start of the game for some reason.
Later I made the input actions into separate ones (MoveX, MoveY, MoveZ) and it worked fine
how can i be able to have a button to jump with a function similar to getKey? for example, if i hold jump ill be able to continuously jump
Use an InputActionReference and check if the action is pressed.
e.g.
actionRef.action.IsPressed()
Reacting to a phase change would be inappropriate (you don't care about the action being performed, you care about the button being held down!)
thanks!
I started out using PlayerInput and responding to change events, even for continuous things
which was a bit awkward -- I'd have to save the latest value in a field and then check it later
Events are good for things like "jump" or "shoot"
i see yeah its not that great
I do everything with InputActionReference now; I subscribe to events for that kind of thing
same honestly
(subscribe in OnEnable, unsubscribe in OnDisable)
wait i dont have those on my code, what are they supposed to do?
I need to add a convenient way to do both of those automatically
This is only really relevant if you're using actions in objects that are getting turned on and off (or created and destroyed, even)
my game lets you possess any entity, so I do a lot of that
got it got it
pretty cool
I like to completely unsubscribe if I don't need an input, instead of just checking if I'm enabled before using it
this gets more important with Domain Reload disabled
which means Unity doesn't reset the "world" between play sessions
sounds about right, but that whole thing about subscribing and unsubcribing with the new input system still has got me a bit confused
you wind up with event subscriptions from long-dead objects, oops
You subscribe to an event like someActionRef.action.performed to have your function called whenever the action enters the "performed" state
as I was writing something my computer crashed from unity
Subscribing basically just puts your function into a list
and everything in the list gets called
The C# documentation hypes up the event keyword a little too much
It lets you publicly add and remove methods, but you can only trigger the event privately
that's it
huh, i thought it did more
It's very similar to having a public field that holds a delegate type
i see
(and a "delegate" is a function object)
public void Wow() {
Debug.Log("Wow");
}
public void Test() {
System.Action func = Wow;
func();
}
this logs "Wow"
thats interesting
public void Wow()
{
}
public void Test()
{
System.Action func1 = Wow;
System.Action func2 = Wow;
System.Action func3 = func1 + func2;
func3();
}
my favorite bit is how you can literally just add two of them together
(that's what's happening when you subscribe or unsubscribe
oohhh thats really handy
Delegate types let you pass entire functions around
I'm having problems getting mouse input to work with input system
such as...?
@austere grotto I'll show u
This is my input code im trying to use the x and y axis of the mouse for cam movement . https://pastebin.com/a0mxZmXX
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
This is my input Action
It dose nothing on click or x and y axis
What am i doing wrong
you never enabled the input actions
e.g. mouseX.action.Enable();
also this is not the action, it's the binding
And you can use a single Vector2 action for mouse x and y, you don't need two separate ones.
do I do that in code
Do you do what in code
mousex.action.enable();
I don't know where else you would write code other than in code... 🤔
"it" being what?
What did you try?
You also have some weird control scheme stuff going on I'm noting.
Sure - probably your weird control scheme setup not working now
you might also have sensitivity set to 0
check both these things
It couldn't be It works just fine with old input system. Also I have mouse left and right click on another script and it dosen't work with mouse but works with keyboard button.
right
this convinces me even more it's due to your weird control scheme setup
Why do you have a control scheme called "PlayerInput"
Because the keyboard control scheme only has keyboard and I tried adding a new one that has keyboard and mouse
you should remove/delete all control schemes unless you are doing local multiplayer
It is probably picking the keyboard-only one
Yep thank you I deleted keyboard and now it is working. it was picking keyboard
Is there any info on implementing double tap with the new input system?
I created a default Tap interaction in PlayerInputActions asset.
How do I subscribe to it? The document doesn't seem to show it.
It shows how to add them:
var Action = new InputAction();
action.AddBinding("<Gamepad>/leftStick")
.WithInteractions("tap(duration=0.8)");
var Action = new InputAction(Interactions: "tap(duration=0.8)");
But not how to use them.
Oh, I see:
fireAction.performed +=
context =>
{
if (context.Interaction is SlowTapInteraction)
ChargedFire();
else
Fire();
};
Hmm, it appears the MultiTapInteraction isn't available for Vector2D, which is what I want: I want the character to start sprinting when the X goes above like 0.75 twice in half a second. And I don't care if it's done with a keyboard, gamepad, joystick, wheel or a virtual visual controller on a phone.
I guess I'll write my own MultiTapInteraction that works with Vector2.
something like minecraft's double-tap to sprint, but supporting other devices?
im not sure that'd give a good UX with analog devices
Yep.
Well, I played video games that supported it myself: Battlefield 3 and Tekken, and those 2 support this kind of a control for sprinting forward
Not sure how it will work well for people on the phones
apparently L3 is used to initiate a sprint in minecraft for controllers
I see
Double tapping and triple tapping is used a lot in fighting games, it also acts as a balancing mechanics and arguably results in more challenging gameplay compared to "the shift key" approach
well, if it feels right when playing then go ahead, i don't play a ton of games lol
It's actually quite fun do the triple-tap into a button in Tekken
Well, Tekken is supposed to be played with a cross but some people control movement with the stick on the gamepad
It's a top down pseudo 3D sports game with fighting element
So like it's a 2D game but with emulated 3D elements, like what people used to do on NES
ah, so sprint has to work in all directions?
im kinda struggling to visualize this
could you show an example of the perspective?
Gamepad Ritmix. Emulator Nostalgia Pro. Android.
hm, why not sprinting up & down?
So when you sprint left and right, you can press up and down to do the half circle motion and change the direction
so horizontal handling and vertical handling are significantly different?
i think in that case it could make sense to just separate them as 2 axis input actions
Well, they're closer in the normal moving state and then very different in the sprinting state.
So, in the standing still and moving states:
- Perform movement in both axes: horizontal and vertical. So Vector2 is very good here.
- Player can double tab left or right to start printing.
Then, in the sprinting state: - Character continues moving the sprinting direction even if player lets go of the controller.
- If player enters opposite horizontal direction, character stops sprinting and actually fully stops and moves to the standing still state.
- If player double taps up or down, character makes the half circle motion and start sprinting the other direction.
yeah i think when sprinting that'd warrant separate actions
i don't think that'd be too much of an issue in the normal state
you can just combine them
Hello there
is there a way to check for input cancellation of a button type action when using Send messages on a PlayerInput?
Like I have this function
private void OnSprint ( InputValue value ) {
_isRunning = value.isPressed;
}
But it will only "toggle" my _isRunning state, not turn it on while pressed.
Is there a clean way of fixing that?
What's the difference between toggling it and turning it on while pressed in your eyes?
Can you show what you're wanting to do?
currently when pressing and releasing the sprint button, the state of _isRunning stays on.
I want it to turn off when letting go, which doesn't happen with this code
It should work as you describe.
Did you add any processors or anything to the action?
i think i need to adjust my action setting, ill check it out
fixed it, I added a "Press" interaction to my action with a Press and Release setting
Hi, I could use a little help from Unity's experts.
The problem is not getting a full range of the window when moving the target around. If you watch the video I've attached you'll get an illustration.
My guess is this first has to do with a deadzone that's normally attributed to joysticks. This gun uses two potentiometers and is not a light-gun.
One potentiometer is for the x-axis and the other for the y-axis.
In the video you can see feedback from both in the console window.
well if you think it's with the deadzones, have you tried removing them?
You mean doing this?
I'm figuring it out on my own.
Hey I'm having some difficulties assigning my Left Shoulder action to an input in the Input Manager. I've looked over this thread https://discussions.unity.com/t/xbox-one-controller-mapping-solved/187077/7 to see what values correspond to which Xbox controller key, but I can't seem to figure out how to bind the Left Shoulder. This is my setup for it right now.
The bumper or the trigger?
Bumper
Oh you're right. I apologize, I must've missed that.
how to make keyboard input smoother, like default GetAxis(), because it feels like GetAxisRaw()
How?
If you're asking a question you should start with: "How do you" or "How does... work" and end with a question mark "?".
Is this what you want to know?
https://www.youtube.com/watch?v=ixM2W2tPn6c
In this video I go over a few methods on how to move a player or an object around the screen. I think share my thoughts on which method is best for each use.
SUBSCRIBE: https://bit.ly/2Js78lE
In this video I discuss:
0:28 - Moving An Object Using Translate
2:20 - Problems with using Translate
2:50 - Using RigidBody for Physics & Co...
um no
i need help in context of new input system
Ah, something different entirely.
Okay, so what is your controller? A joystick, a D pad controller? Or something else?
keyboard
something wrong?
bro you didnt understand me
i want to know how to make this feel smoother
Well, that's not really a good question is it? Are you talking about changing the structure of this Action Map?
What do you want to make smooth?
These should be buttons.
when i used old input system, i used GetAxis(), but with new input system i using this like on screenshot, and it feels like from old input GetAxisRaw but i need GetAxis feel
My guess is that you want an easing effect.
Which would make this the video to watch.
#🖱️┃input-system message
So this is using the old input system. Compare that to the new input system.
https://www.youtube.com/watch?v=MK4OmsViqMA
Watch this video in context on Unity Learn:
https://learn.unity.com/tutorial/getaxis-o
How to "get axis" based input for your games in Unity and how these axes can be modified with the Input manager
Axis is among the choices in this dropdown.
Then you assign your key.
Is that what you want to know @sturdy jetty ?
Frankly, I'm not sure this will work. But you'll have to spend time trying possible solutions.
More settings under Edit >> Project Settings >> Input Manager.
i fixed it just with lerp
Congratulations. You figured that out on your own.
can you please check my problem in #archived-code-advanced
(chat gpt doesnt helped)
Hi, do you guys have any idea why action.ApplyBindingOverride only works on bindings that are part of a composite? For the rest, nothing changes
Thread: https://discussions.unity.com/t/applybindingoverride-not-working-on-non-composite-bindings/1576121
With the input system, how can I check things in a different order? I have UI Toolkit input box, when the user hits a key bound to UI/Console action, I want to check performed on it and block it, before the TextField accepts whatever key they typed. Right now it first writes the character on KeyDownEvent and then it performs my UI/Console event
Is there a way with the Input System to make hold duration of a button influence the axis output?
Right now the default move action treats WASD as either 0 or 1. I'd like the axis value to slowly ramp up to 1 depending on how long I have the key pressed, so that quick taps allow for fine control.
Is that possible?
My first thought is a Processor, but I believe those have to be stateless
you'd probably have to keep track of that yourself, perhaps with Vector2.MoveTowards
i.e. they can't remember values over time
Interactions can have state, but I'm not sure if you could use that to change the input value
I'm a bit surprised this isn't the default.. this has been a standard in PC controls for 50 years
Well, processors can indeed not store state, so those are useless for this usecase
If this isn't supported, then the entire input system is pointless for my usecase
This is a must have
i mean.. you can do anything with code
bit of a "baby out with the bathwater" situation there :p
the point of the inputsystem is the structure
Well yeah.. the movement action is 90% of the entire player action. So if fine control with keyboard isn'T possible, then Input System is indeed pointless for me
Code what. THe only way to do this seems with processors and those can't have state
you just...put the logic in the player controller
the input is digital
you can respond to it however you want
you could use interactions
The entire point is, that the action output is a Vector2, and that the player controller has no idea what created it.
It would be a break in the abstraction, yes
But I think you've already spent more time worrying about that then you'd have spent just dealing with it (:
have a tap interaction for the precise control, and a hold interaction for the normal movement
You can figure out what kind of device is producing your input
I used to use that to correctly handle mouse delta vs. joystick position
(now I use a Processor for that)
A -1,0 value might be the player pressing A, which needs post-processing, or the player using the joystick at full value, which doesn'T require post processing. If I need to split up the control inputs, then the entire point of the Input System of mapping inputs to actions is gone
And again.. if this doesn'T work for movement, which is most of the entire control scheme, then the rest isn't worth it either.. Then I need to look for a different solution, either handmade, or something from the store that supports this
you can put this interaction on keyboard bindings and let joysticks work in analog.
That wouldn't give what Witcher is looking for, though
They want the digital input to quickly ramp up to full value instead of instantly going there
Much like how the old input manager behaves
so that quick taps allow for fine control.
this is the goal, isn't it
You could approximate it, I guess
What I'm looking for is the abstraction of the action, sticks being read normally and keys being read based on hold duration
But it would be a lot less fluid
true
splitting it up is beside the point
Sometimes you have to punch holes in your abstraction.
You would still have the bindings together
You'd just make an extra decision based on the current device the player is using
(that is what I did!)
No I don't have to punch holes into the abstraction. If this abstraction cannot handle this usecase, then I need a different one
Okay, then go find something else.
You don't seem interested in being helped, which is very frustrating to me
As I said, movement is the most important thing by far. If that#s not supported then the entire system is pointless to me
i mean you could use multiple hold interactions, and then just smooth the output instead
Well Fen, I told you what solution I need, and all you tell me is that it cannot be done without splitting the abstraction, which is exactly what I don't want
I didn't ask how to work around this, I asked how to make this work in Input System. And you tell me that cannot be done
So that's my answer
he said it can't be done with processors
the inputsystem has more than processors lmao
I don't believe interactions would help you here
They don't transform the input value.
You'd have to kludge something together out of different tap interactions
Which could be transparent, but it'd also be a bit icky to put together
It would be easy to make a processor that works for a single player, of course. Just stick some state in a static field
It'd just break once you started using that processor multiple times (especially on the same action or binding)
seems like stateful processors are slated for v>1
soon(tm)
The current roadblock is that the processor only knows about the value and the InputControl that produced it.
If it knew more, it could put its state in a static dictionary
How do I set priority on RegisterCallback<KeyDownEvent> and actions.FindAction("UI/Console").performed? the callback is running first which I do not want
So as I said.. summary: can't be done with this system
Gamepads not working on macOS: https://discussions.unity.com/t/xbox-controller-not-working-on-macos/932929/12
- macOS 15.2
- MacBook Pro M2
- Gamepad works in Browser, Godot and Unitys Input debugger
- But no gamepads detected in Unity3D
- Tested Unity 2022.3 and 6
- Same code works fine on Win11
How can I compare if InputAction.CallbackContext context button pressed using _anyKeyAction = new InputAction(binding: "/*/<button>"); is equal to my _playerInput.actions.FindAction("UI/Console") ?
Using multi language btw, so the "Enter" key is not always called enter when doing context.control.displayName ... how do I check for the enter keybind?
Use the key code? Not sure where that problem you described would even come up. There should be no reason to make a string lookup for a key name outside a (re)binding system. You should practically never use the any-event to get input notifications except if you actually want to make a ‘press any key’ control, debug panel or said binding system.
@verbal remnantI need to block the bound key so it does not write to a UI Toolkit Textfield, but it seems the write always happens before I can catch the press event
Why don’t you disable the action(map)s other systems are hooked up with when in an input field (and vice versa)?
Nothing else is running. The problem seems to be that the input for the Textfield component is always written before I can catch the InputAction.CallbackContext and do something like: ```if (context.control.path == "/Keyboard/backquote")
{
return;
}
I’m saying you should not have to solve it like that
You can’t use events to intercept and consume input interrupts in any predictable order
You have to prevent the event from happening in the first place, by knowing your game’s mode/state and enabling/disabling actions/maps/controls accordingly
So how would that be possible? My console window is open, the textfield is focused so the user can type into it, but when I hit the console bound key it writes into the input field. There is nothing I can disable? I have no other action maps running, and I don't want to block any other inputs from happening
Hey, i'm trying to have local multiplayer, where I can drive two cars. I set up the player input, player input manager and control scheme. I am not sure what I am doing wrong. It only spawns one car but not the second one.
!code
Posting code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/ , https://paste.ofcode.org/ , https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
but those are screenshots
I am trying to add controller support for my game, and also allow it to be played on the Steamdeck. Not only would I need to allow the controller joysticks and buttons to work for my player movement, aiming, shooting, but even for the GUI navigation in main menu, character selection, using dropdowns for display resolution, checkboxes etc.
Would you use using the new input system is easy to do this? Or you recommend something like Rewired?
This is pretty standard
any game has these same requirements
the gui stuff comes mostly out of the box
Awesome, good to hear. I tried playing with Rewired, but couldn't get GUI to work.
Does the Unity Input support different controllers and custom mapping?
Like something that won't take me months to write on my own?
of course
Thank you. I will go through documentation and hopefully don't have to bug you all too much here
Actually, I did run into one very specific issue on the steam deck
Let me go find the post I made after solving it...
Basically, the d-pad would only sometimes work
you'd press it 10 times and it'd do something once
I do not really understand why this was a problem or why my fix worked -- but my menu controls are working perfectly well on my Deck now
normally, the input system tries to only let one control drive the action at a time
Was there a step by step tutorial you followed to get it all working from scratch?
Pass-Through mode makes it not do that
Nothing much -- go find the input action asset used by the event system input module, make a copy of it (so you can edit it), switch the "Navigate" action from "Value" to "Pass Through", and then plug that new asset into the input module
I'm curious to see if you have the same problem though
No, I meant to set up the input system, configure, use it with GUI buttons and navigate through menus etc.
Right now, I am doing everything through mouse clicks, and I want to be able to navigate menus and character selection through keyboard and controller
There's a script to allow InputSystem driven UI nav: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/manual/UISupport.html#setting-up-ui-input
Any idea why the composite type when given the multi-tap interaction will always return the midpoint value between min and max?
I just want to read which direction (ex. A or D) produced the action, and I have A as positive and D as negative component of the composite
What do you mean by it "returning" a value? Where are you getting this value?
The way you are describing this makes me wonder if this shouldn’t be two separate button actions instead of an axis.
Hello 🙂
My Player Input Manager is firing the Join Behavior on awake even though there are no inputs to the system to tell it to do so. Is there a setting I'm missing?
It should be waiting until a controller presses the start button
Okay, well I've decided to just handle the joining on my own which works. My last issue that maybe someone can enlighten me on, is that both controllers are controlling both players right now. I currently have two control schemes and each player is assigned to a different one. The control schemes share the same action maps and actions, however. I'm not sure if that is an issue.
I am setting the selected gameobject in my Start of my menu scene. To troubleshoot why my controller joystick isn't moving to other buttons, is there a way to Debug.Log what gameobject is currently selected?
EventSystem.current.SetSelectedGameObject(selectableObject);
Unlike with mouse hover, there seems to be no visual indication with controller on which button is currently selected
Buttons should switch to their selected state
How do I check if it's selected? Is there a method to find which object is currently selected so I can do do something different with it?
EventSystem.currentSelectedGameObject
These values don't work for mouse events? Like hover and pressed?
Since I set the composite type as 1D axis, I was reading the "return value" by using the InputActions.CallbackContext's ReadValue<float>();
Normally without the multitap the read returns min value set in the action map for negative binding and max value for positive binding, but after adding the multi tap interaction every time the Action is triggered the read now returns (min + max)/2 exactly
The thing is the multitap processor is probably not designed for axis controls, it's more for buttons. I guess it's making an assumption about what to put in the value that isn't correct for your use case
Thank you for the response!!
I’ll try a diff way then, maybe individual bindings
So playing with this more, I realize that that selecting buttons via controller is completely different from hovering over with a mouse. Is there no way to 'align' them so same events fire? Like playing a sound, and showing details for a character etc?
Just have them call the same function
Selecting via controller is the same as selecting via a keyboard
But hovering is different
Yes, that is what I am trying to achieve -
Hovering over with a mouse will play a sound, brighten the button, scale the button, show character details.
How do I make all this exact same thing happen with selected through controller?
By making ISelectHandler and IPointerEnterHandler call the same function
With the new Input System and with Animator, I have move/jump already set up.
I’m trying to add dancing loops. Does it make sense to make a new state machine graph on another layer? That’s what I have now, and key input is working, but I’m not successfully changing states and my Dance boolean.
Input system and animation should not have any direct relationship. You would in all situations put some type of controller between them and that controller implements whatever your application is doing (logic) while using input to understand the player and using animations to implement the response to that input. If you skip that controller you implement your logic in a place that is not designed to implement logic.
Is there a trick to preventing the input mappings from being garbled for controller on Web builds?
@help ?
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
I got stuff working (both UI and gameplay) with with a controller (xbox controller attached to my PC).
But when I play my game on the SteamDeck, I am having to use the right touchpad instead of joysticks. What am I doing wrong?
hey guys I need help
how do I handle mouse scroll wheel input?
I have an int, and I want it to go up when the mouse wheel goes up, and down when the mouse wheel goes down
but I don't really know how this input works, and there aren't really any tutorials going deeply into how it's implemented
Same as any other input really. What are you struggling with specifically?
Also which input system are you using
"default" doesn't mean much
New or old
The default can be different depending on which version of Unity you're using
Have you tried reading the docs?
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Input-mouseScrollDelta.html
It explains it pretty well
Is this with the new or old input system? And if it's the new one, how do you have your inputs set up in your InputMapping?
so from what I understood, the mouseScrollDelta is a float, going up and down, reseting itself to 0 when the wheel stays untouched
could I use a += to gather the info on how much the wheel has been scrolled?
I think it's the new one
With the new one. I followed the basic stuff to get keyboard mouse and controller mapped
What mappings did you use for the controller? Was it specifically like the Xbox controller mappings, or did you use gamepad mappings?
Not unless you installed it on manually
The value tells you how much it scrolled up or down this frame
Should I use the new input system for the Essentials bonus scene game?
if you feel like it
kinda big docs for it lol
yeah
finishing the Essentials soon
so it's a package that I need to install in the project first, if I'm not mistaken?
yes
Pulling my hair out with this one, i'm trying to display bindings for composites ( wasd ). I used the unity example and it shows LS|WASD, but when I use my own action, it shows as blank. My inputs are setup properly, (gamepad, keyboard) is checked. Any ideas? I'm on the most recent version
how are you displaying the binding?
I do GetDisplayString(n). If I force an index, say 1 it will display W/A/S/D which is correct. If I put a zero, then the gamepad binding of LS will display. When I call the method without any arguments, it shows as blank. Though if i were to switch the binding to a unity example project with another composite "Move" with wasd, calling getdisplaystring will show both the gamepad and keyboard bindings in the string. It's so odd, i feel my input system is not set up correctly, but everything works other than composites!
Is there a way with new input system to capture the last move so you idle on the correct side
within the animations
that's not really a job for the input system
rather, in the animation system, just make it not turn when the movement is 0
I have an input action bound to a trigger on my Xbox controller
When I press the trigger fully and then release, it calls "started" a second time before it calls "canceled"
This is unexpected behavior, how should I work around this?
Is it better to use "performed" instead of "started"? That is only called once, when the trigger is fully pressed
It's expected if you did something like set up a "press and release" interaction
There are no interactions added. I just want to use it like a basic button
This did the trick for me
Performed is almost always correct but that started behavior is weird
Maybe your hardware is doing something weird
Also, it seems like "performed" is called when the trigger is like halfway pressed, but that works for me
Yes that's expected
You can customize that with a Press interaction if you want
The Xbox trigger is not a button it's really an axis
Yeah I figured
That has been a pain in many games I've played
Also, is there any way to use the gyroscope of a PS4/5 or Switch controller in the input system?
on a real console yes, on a PC without third party drivers i think those are treated as xinput devices which doesn't include a gyroscope
Hi. How to do one-time Press in input. Same as Input.GetKeyDown. The .trigger doesn't work at all and I found out there are interactions in Input action menu but Tap or Press still not working
I don't have pc with me rn but the wasPressedThisFrame will work?
You should delete all interactions, make sure it's a button action
Triggered or WasPerformedThisFrame will both work
Assuming you're polling input in Update
If you're using events it's different
Well the trigger didn't work for me. In interaction I have got the Hold as default. But I will delete this after. Yes but the button which I'm calling was from my void so it wasn't directly in update.
Anyway I have seen some kind of void where was something callback. Is it better to have it? Or it just doesn't matter
You should not have hold
It's not about better or worse. It's a different approach
Also they are called "methods" not "voids"
Can you please explain me the difference between them?
Event based input handling vs polling every frame
Callbacks mean that someone calls your method when something happens
Polling means that you have to actively check if something has happened
Hello there
does anyone know whether PlayerInput isn't supposed to be used on console?
I'm having trouble getting my input device through the component, but it does work properly on PC
It's suitable for all platforms
You probably have a control schemes issue
does PlayerInput auto determine a control scheme if a matching device is present (when set to Any)?
can you elaborate on a proper setup?
this is what I have right now
I'm pretty sure you only get XInputController when using a gamepad on a desktop platform
You need a less specific device type
If you need things like gyro input, you'll want a specific kind of device
otherwise, just use Gamepad
huh, ill look into that, thanks
so if I wanted my game to be released on PC and console and support controller on PC as well, I basically cannot set up my control schemes based on a console platform, am I correct?
Like I can only have one for MKB and one for Gamepad
and anything that requires specific gamepad recognition I'd have to do myself?
If you want special gamepad features, you already need different control schemes anyway
But they dont get recognized
What don't get recognized?
I cant have a control scheme for Xbox and PS with both a gamepad configured in the device list
can I?
you'd presumably want the specific kind of device for those platforms
like "PS5 Controller"
so you'd have Mouse + Keyboard, Gamepad, Xbox, and Playstation control schemes
oh
I don't know which scheme would win if you used a playstation controller
It might be whichever one matches first, in which case Gamepad would go last
that'd need testing
non xbox/playstation controllers do exist, so you'd probably want a generic fallback one yeah
indeed -- even on consoles
that defaults to xbox afaik
are you talking about how your game handles that device?
like, what icons it displays?
because "Gamepad" is very generic
it has nothing specific to an xbox controller in it
so atm I have control schemes set up per platform, MKB, Playstation and Xbox (cuz they're the targets)
I've managed the game to recognize device changes on PC, so - for exampe - when input from a different device is registered, my button layout changes (standard feature)
and I use PlayerInput for that
so far so good
but when I build for xbox or PS, I still receive input just fine from the device, but my device recognition fails
because the control scheme change doesnt trigger
so essentially the PlayerInput component has a null device (or none at all), and a null control scheme at the start on any console
I've managed to get that to work, but unfortunately the PlayerInput still has no devices registered within it, even though input works (which it already did before)
@austere grotto is this what you meant when you said bind left stick directly?
Yes
Show a screenshot of the action configuration itself
i am not sure what that is tbh I just picked this up like 15 mins ago and have been using the legacy input system since
You have the binding selected
you mean in like the code where i define the actions?
Here
Click on "Move"
Hey everyone, ive been really stressing on this issue where my character doesnt respond to my keyinputs and the character just "march in place". im currently using root motion and below are the pictures for context
here is my character controller script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasicMoveRootMotion : MonoBehaviour
{
private Animator animator;
//public settings
public float rotateSpeed = 50.0f;
void Start()
{
animator = GetComponent<Animator>();
}
void Update()
{
animator.SetFloat("Vertical", Input.GetAxis("Vertical"));
if (Input.GetAxis("Vertical") != 0)
{
if (Input.GetAxis("Horizontal") > 0)
{
transform.Rotate(0, rotateSpeed * Time.deltaTime, 0);
}
if (Input.GetAxis("Horizontal") < 0)
{
transform.Rotate(0, -rotateSpeed * Time.deltaTime, 0);
}
}
}
}
You have two competing types of motion here:
- Animator root motion
- Rigidbody
You need to pick and stick with one or the other
Also you are using transform.Rotate directly on an object with a Rigidbody, which is going to cause issues like broken interpolation.
Anyway there's nothing in your code that would make the animator respond to any input.
The only thing your code is doing is rotating the Transform.
Which may itself even be getting overridden by the Animator.
by animator root motion do you mean the "Apply root motion" tick box?
yes
I assume you're trying to move via the animator
that's the only reason to tick that box
You said you're using root motion
im currently using root motion
Yep
So the solution would be to untick the rigid body?
But doing so would eliminate the characters gravity
what do you mean by "untick"?
No I'm not saying that's teh solution necessarily
I'm saying from what you've shown you have more than one movement strategies in use and also no actual code that will move anything
Uncheck the rigid body box
Ah
I see
You mean... disabling it?
Which box?
Rigidbody cannot be disabled.
I would say removing it is one option, certainly
But I'm not sure what you're actually trying to do or how you actually plan to move the object
Yeah i meant removing it
So I can't recommend any particular course of action yet.
In general if you want an animated character that moves via Rigidbody, the visual elements of the object should be on a child object
Im planning to move the character by AWSD key and using the animations imported from mixamo
so that the animator is not trying to move the root object
Root motion should be rare.
hi I need help
my action for no reason does not accept .trigger or wasPressedThisFrame
how to fix it?
I presume you're talking about InputAction
I'd guess that you don't actually have an InputAction
I do
the IsPressed works fine but the trigger does not
for no reason
this is for what?
What is the purpose of this
thats to say i need to make the player mesh a child?
and you are correct im trying to make a rigidbody character that is animated
I found out there was problem with update void. I wanted to keep the game in fixedupdate and it wasn't functional at all
input is frame-bound so you need to use update for any 1-frame things yes
why doesnt up and down on the sticks on a controller get recognised on web builds?
I've got a Player Input component set to "Invoke Unity Events" , and I have a button mapped to call a function on a component. I put a log in that function, and every time I hit the button it is being called more than once! Depending on which function I put there, it could be 3 times, or 2 times! What's up with that?
That's expected yes, there are multiple phases to the action
Make sure you have an InputAction.CallbackContext ctx parameter on the method and you can do this to understand what's happening:
Debug.Log($"Action phase is {ctx.phase}");```