#🖱️┃input-system
1 messages · Page 56 of 1
not here, but in DM
it's probably not even related to touchapi or the input system. more likely something to do with the UI
any1 got some time, dont know why I cant choose a dropdownbutton in my Script
no code - no help
"yes"
What does this have to do with the Input System?
it is working not praetor thx 🙂
I'm pretty sure Sony keeps the cool Gamepad controls unavailable right? For example, we couldn't use the controller shake sensor?
In the old system the value received by my HOTAS slider was between -1 and 1.
In the new input system the values are between 0.98 and 1.02, how can I normalize them so that they are between -1 and 1?
Vector2 input = playerInput.Player.Movement.ReadValue<Vector2>();
playerController.PlayerMovement(input);
Is there an alternative to ReadValue that doesn't create GC? Not that big of a deal, 80B per frame, just curious
is there something new with the input system that so new the tutorials doesnt work with it?
Im getting errors with this OnEnable/OnDisbale now:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class ForkliftController : MonoBehaviour
{
private ForkliftController forkliftController;
private void Awake()
{
forkliftController = new ForkliftController();
}
private void OnEnable()
{
forkliftController.Enabled;
}
private void OnDisable()
{
forkliftController.Disable();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Vector2 move = forkliftController.forkliftInputs.Move.ReadValue<Vector2>();
}
}
nothing has changed, your code is wrong
forkliftController.Enabled;``` ???
Please go back to your tutorial and copy it correctly
yeah, sorry. i shoould have used parenteces, but it doesnt work anyway
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class ForkliftController : MonoBehaviour
{
public ForkliftController forkliftController;
private void Awake()
{
forkliftController = new ForkliftController();
}
private void OnEnable()
{
forkliftController.Enabled();
}
private void OnDisable()
{
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Vector2 move = forkliftController.forkliftInputs.Move.ReadValue<Vector2>();
}
}
i did.
Show their code next to yours
Every tiny bit of spelling, capitalization, and punctuation matters in C#
It has to be exact
alright, ill check it in detail
once again 🙂
what happen was that i was referencing the wrong script.
its ok now. thanx for the help.
In https://docs.unity3d.com/Packages/com.unity.inputsystem@1.3/manual/KnownLimitations.html, it mentions the inability for the Input System to pre-empt each other. Considering that each action can be rebinded separately (may or may not have modifiers / possibly a modifier we haven't anticipated / a third separate action now has a modifier that collides with these 2), what's a suitable workaround for this?
hey guys, i have a input action that can be used both on keyboard and on gamepad, but when i press the gamepad stick just a little bit the player moves pretty slow, i don't remember how to remove this, i wan't basically to change to something like "getaxisraw" of the old input system (-1f, 0f, 1f only)
i know i can set a processor to scale the value like 10000x and clamp it, but there is a option that does that automatically, and i cant find it
Value types don’t create garbage, reference types do
GetAxisRaw didn't do what you describe
It just got rid of the "acceleration" on the joystick - but it would still report values between 0 and 1
Maybe what you want is to set the value type to something like Digital/DigitalNormalized/Normalized
If not, you can always just normalize the value in your code
thanks, it was exactly this i was looking for, instead of creating a binding and setting the left stick i created a 2d vector and set it to digital, worked like a charm
So question about input and movement, do I have to manually check that a collision hasn't occurred before moving the transform of the character? or does the colliders handle that for me, I know they handle that with regards to gravity, but what about walls?
Actually.... I don't know that this is even the right place to ask
Don't crosspost. You've been answered in #⚛️┃physics.
Hi! Can i have help i didn't mean to switch to the new input system and I did and i need help adjusting my code .
Just switch back?
not helpful
How is that not helpful?
It would solve the problem
Unless he wants to be on the new input system which he hasn’t said yet
nvm
Is there any way to reuse code for such approach with new input system?
rn I have to create all these for each action:
public static MainActionComponent MainAction => mainAction;
private static MainActionComponent mainAction;
private bool _mainAction;
private void RegisterMainAction()
{
Game.MainAction.performed += _ =>
{
mainAction.pressed = true;
mainAction.active = true;
};
Game.MainAction.canceled += _ =>
{
mainAction.pressed = false;
};
}
And do this in update
// Main action
if (mainAction.active)
{
if (_mainAction)
{
_mainAction = false;
mainAction.active = false;
}
else
{
_mainAction = true;
}
}
I can't figure out if there's a better option
or a way to reuse such code for other actions
all info for each action is stored in it's structs
How do i make my player shoot with arrow keys with the new input system cuz i can't find any tutorial
make a method that takes in a vector 3 as a parameter and have it subscirbe to a 2D input action
I know how to make it with the old system can i somehow translate it to the new system?
yes
so how can i translate it?
make a composite binding based on a 2d digital vector
subscribe the shooting method to the input action event
thx
new input system lets me use all bindings from all devices as single input action
I'm not sure if old system will see Input.MouseClick same way on gamepads and etc
doesn't input manager handle that in old system?
how would I switch it back?
Go to package manager and remove the new input pack
Hi, I want to make bind settings, and I have problem with unbinding
I have two binds, main and alternative, and I want to remove bind when backspace is pressed
But ChangeBinding(index).Erase(); is removing it, not setting to null or <no bind>
How can I replace bind with null/<no bind>?
Forward [W] [↑] > when pressed backspace on alternative > [W] [ ]
Back [S] [↓]
Left [A] [←]
Right [D] [→]
Do you guys know why it's giving me an error in line 22?? It says Null Reference Exception !!
There's no touchscreen device that Unity is aware of presumably
So probably Touchscreen.current is returning null
the guy who I was watching said that it isn't going to work on pc and then he build the game on android and worked for him but when I build it on android it doesn't work
¯_(ツ)_/¯
Standard debugging strategies apply
use Debug.log
figure out what's null and why
well I guess there is no other way then 😅
Hey, I have a question about how the input system works. I have movement assigned to keys and controller input, I've set up the event system on the character's "Player Input" and I have code in my "move" function that should move the character, but when I press arrow or wasd keys, nothing happens. The event doesn't seem to fire.
Is there an article that describes the input pipeline, from the button press or keyboard key to the fired event?
I think I'm using the new input system
Why does it always return duration as being 0?
If you are using the new input system this article should explain how you can detect input all the different ways. https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/QuickStartGuide.html
duration returns the time difference between start of the action and the time of it being triggered. I don't see any reason your duration should be greater than 0?
Because this is if ctx canceled
You start holding down the button earlier
Is there a built-in way to get how long the button has been held when you release it?
Isn't that what I'm doing?
My thoughts are that maybe since you are not calling "duration" until after your action is cancelled it reads the duration as 0 since the action is cancelled?
Put the debug.log(duration), inside of the function instead of in the if statement for canceled, and see what it returns then?
and if you really need the duration there, I would just store the value of the duration in a variable and then use that variable when you need it inside the canceled if statement.
That just makes it log 0 twice when pressed and once when released
Check the settings, is it set to hold, or press?
Yeah, that's what I was gonna do. It just looked like there was a simpler way to do it with CallbackContext.duration
There's "no interaction added", but if I add a hold interaction, it just returns 0 after half a second of holding
OK, after adding a press interaction instead, it does return the proper duration
Hmm..
So it's fixed now, I think. Thanks dude
Good job fixing it. The functions for the callback context aren't very intuitive lol
Yeah, which is weird since it's more flexible than the old input in many ways
There should also be an option to make inputs run in fixedupdate time if they don't already
Because that's how you want to use input most of the time
But I don't have time for robustness right now
There is an option for that
Once i get back on my PC I’ll screenshot where for you, give me a min
That's what I was reading to set this up. The problem is that despite assigning the move callback, I still don't get messages from the input system.
Np.
Do you have a screenshot of your code?
The Debug console shows nothing which is the problem. Let me try running it with the input debugger
It does play, as in if I hit the play button, it does the right thing to start up the game, but then I get nothing from the debug console when I press any keys, despite having a move action that's attached that Debug.Log's to the console
should this work with the old input system because it doesn't and I have no errors
Update
Not "update"
You should also get your IDE configured
did all of it and it worked thank you!
try changing move to Onmove()
oh wait nvm that's for send messages
I trying to add lift to my drone controller but currently, the drone is just falling to the plane https://hatebin.com/rhcmrtvnpu
not input system?
I am trying to add a 2D Vector composite on the new input system. But the option is not showing up.
You need the action type to be Value/Vector2
Ok
public void OnAttackDown(InputAction.CallbackContext ctx)
{
if (ctx.performed)
{
attackDown = true;
}
else if (ctx.canceled)
{
attackDown = false;
}
}```
I tried this for my if attack is held boolean but it's not working
If you're using SendMessages/Broadcast Messages it should be an InputValue parameter
Not a callback context
Probably silly but how would I listen for 2d vector up press?
If my InputActions group is named Standing and the Actions category is named Movement & set to Vector2, just trying to figure out the magic combination to reference up in my standing.Movement.?Up? or however best to reference it
Send your script and a picture of your input actions
Trying things out right now but figured I might as well ask incase someone knew off the top of their head
In update do Vector2 movement = playerInput.NeutralStanding.Movement.ReadValue<Vector2>();
From there do whatever you want with it
thank you
Where are some good tutorials on this new system?
How am I gonna do 3rd person movement from bracks tutorial?
Unity has one on their youtube channel.
but but how do I do it with this?
Learn how the new system works, for starters.
Posting a bunch of screenshots isn't showing that you understand it. You asked what are some good tutorials, use the one on the Unity's youtube channel.
watching rn
theres no 2d vector composite option just up down left right, binding with one modifier, or binding with two
wait nvm its there
up down left right
sorry its been a while since i used unity
hello!, is using the Player Input Component a good way to use the new input manager? :D
from my experience yes
Ive almost got movement to work right
Only problem I have is that i need to rapidly press the movement keys to move (im not sure if its player input's fault)
i use cs Input.GetKeyDown(KeyCode.Space) is this still recommended?
If this pc only the legacy inputsystem is fine...
What input system are you using
input manager
I was following both the tutorial on unitys youtube and brackeys third person controlleer
Hello, I use the new input system and I have a "button" input with the F key. I am trying to ensure that when I enter a trigger and press the F key, then something happens. But I have to press several times consecutively for the rest of the code to work. We would say that it responds once in 20!
My code for that :
(InputManager.Input.GetPlayerInteract() = F key)
Trying to read input in a physics callback is your issue
They don't run every frame. It's the same as FixedUpdate
Input should be processed in Update or with events.
Mark the entry/exit of the trigger in OnTriggerEnter/Exit with a variable
🤔 Ok ok
OnTriggerStay is not useful here
Ok it's good it works ! Thank you
So I kinda figured out how input works, However my movement has this issue where i cant hold down wasd
I have to rapidly mash the keys to move
Was there something I missed?
And with a controller I need to wiggle the stick to move
So basically it only works on pressing it once
how do I make it so I can hold down a movement key?
Ok. so after doing some more debugging, I noticed that the keyboard doesn't work but the gamepad sort of does. I get the logging in the console when I use the analog sticks.
But the player character doesn't move
Shouldn't you be checking for the input under update() ?
I cant put the OnMovement void in update
and it needs to be in there so that it can detect input
And I cant put the stuff that moves the player in update either cause then it wont detect the direction variable
so how the hell do i fix this?
The way you are supposed to do movement is with a vector and detecting the input by reading the vector
instead of using events, since events are updated dynamically by default and can only be changed to fixed update or manual, neither of which fix the issue without drastic work arounds
I found this article that may help you; https://medium.com/nerd-for-tech/moving-with-the-new-input-system-unity-a6c9cb100808
How can I get the x,y coords from this click's context?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputSystem : MonoBehaviour
{
private PlayerInputActions playerInputActions;
private void OnEnable()
{
playerInputActions.Enable();
}
public void Awake()
{
playerInputActions = new PlayerInputActions();
playerInputActions.Player.Click.performed += Click;
}
// Start is called before the first frame update
public void Click(InputAction.CallbackContext context)
{
if(context.performed)
{
Debug.Log("Clicked");
}
}
}
the action is a Button type > and binding is "left mouse button"
So was unity's own YouTube tutorial just bullshit?
Many have changed, for example, between v0.9 vs v1.1.1, many of v.09 apis are obsolete in v 1.x... not to mention v1.3
That saidn. many tutorials you found weren't just some bogus tutorials
Hi, I want to make a local multiplayer with the new input system. Movement is working normal if one player is on the screen. But if i join with a second input, one input (for example the controller) moves both player. What can I do? I already have a player input manager in the scene. I move the player by changing rigidbody velocity. (2d game) (Version 2020.3.21)
have the character controllers respond to different InputActionMaps (or just different actions), the PlayerInput component also helps you managing exactly that.
somehow possible without character controller?
you can put an input-to-character-controller component inbetween... but there is no way around routing the input in some way or other
So, you are talking about the character controller compenent
i'm talking about the concept of a character controller
Hi, I want to make bind settings, and I have problem with unbinding
I have two binds, main and alternative, and I want to remove bind when backspace is pressed
But ChangeBinding(index).Erase(); is removing it, not setting to null or <no bind>
How can I replace bind with null/<no bind>?
Forward [W] [↑] > when pressed backspace on alternative > [W] [ ]
Back [S] [↓]
Left [A] [←]
Right [D] [→]
Ok. So it's not that the input system doesn't work anymore, I got it working, but the problem is that left and right don't move the player but jump does.
Jump causes the player to jump, but left and right/A and D doesn't cause the player to move left or right
And I'm getting the right vector values from the input system
So it must be the physics system
Can someone shed some light on what this warning is telling me? Is there a different way I should be using Eventsystem.IsPointerOverGameObject() when using the new InputSystem?
"Calling IsPointerOverGameObject() from within event processing (such as from InputAction callbacks) will not work as expected; it will query UI state from the last frame"
Currently it's being used as a UI check in an InputSystem click callback to prevent clickthrough.
void OnSelect()
{
// Ignore if over UI
if (!EventSystem.current.IsPointerOverGameObject()) //function returns true if over panel. That's why it's inverted.
{
It's just giving you a warning - if the data from last frame is ok you're fine.
EventSystem.current.IsPointerOverGameObject() is kind of a hack anyway. You could/should use the event system for detecting clicks on things and you won't have a need for it
e.g. using EventTrigger components or implementing IPointerClickHandler etc.
Gotcha. I'll have to read up on EventTrigger components and the EventSystem in general.
How do I set up continuous input where if I hold the left or right keys on the keyboard, the character keeps moving, instead of just moving once?
What do you have now?
Well, right now I have a character that at first moves around sort of correctly, (I sort of figured out that problem but I'm not sure if I did so correctly, but it seems to sort of work) except it catches on something in the environment and now it sort of rolls around when it loses its orientation.
So... yeah. That's how it's working so far
LOL
at least it doesn't fall out of the room
lol
Why are you setting the velocity on the x axis to zero whenever it's not started?
And why are you calling AddForce in Update
That's a classic faux pas
Physics should be done in FixedUpdate
Ran into an issue with touch where 2 touchpoints seems to be valid when checking for 3 touchpoints. Testing it on an Android tablet running 5.0.1
if(Input.touchSupported && Input.touchCount == 3) {
// This runs with only 2 fingers
Debug.Log("Handling touch rotation");
x = Input.GetTouch(2).deltaPosition.x;
y = Input.GetTouch(2).deltaPosition.y;
}
Anyone knows why this is?
Having some word finding difficulties right now so i can't really google my issue and find any results, so I apologise if this might be an easy google search normaly,
So i have two scripts: an inventory script that does specific stuff and an UIWindowManager with a singleton that does things like toggle cursor on and off. When I now add the functions that should be called on button press, I want to add the cursor toggle from inside the inventory script, like this:
instance is the singleton.
i was hoping it would work but i get this Error:
usually i get an error code which i can look up and try to understand, but "Value does not fall within the expected range" sounds like I should not add functions of foreign scripts in the awake?
I really tried to google it but can't give google something that gives me a solution in return
As a workaround, I could copy paste the ToggleUICursor function into the Inventory script but that feels... not good, since I would also have to do that for every other UI script that toggles the cursor on and off
I guess I have to call it inside the UIWindowManager awake, or copy the ToggleUICursor code. I don't see another method
it seems like the problem is that i try to use the singleton. if I instead set up a normal variable. it works
Problem solved. I guess?
Because as best as I can tell this method is called when the action begins and ends. Rather than seperate messages. So when you start holding the direction buttons, the speed vector increases and add force on update keeps adding force to move the player. When you stop holding it, it gets called again and the player stops moving because the vector is set to zero and velocity is set to 0. So update keeps adding a zero force.
I'm assuming you're using a PlayerInput component in "Unity Events" mode?
If so - OnMove will get called whenever the actuation of the bindings for Move change
Yes. Unity events mode is what I'm using.
that means if you go from holding right to holding up, it will be called again, and the phase will not be started
started will only happen when going from zero actuation to non-zero actuation
(I'm making the assumption that you're using the default interaction aka "no interaction" in your input Action)
How do I turn off an actionmap? (and is it even recommended?)
I currently have the problem that my character attacks and can move when the UI is open. which is annoying, so i thought "i just disable the PlayerControl actionmap while opening the UI"
But when i try that i get the error:
your error is on line 51
which you didn;'t even show in your screenshot
ah fuck wrong screenshot >.<
1 moment
thats the correct one
the problem is the line
playerInput.actions.FindActionMap("PlayerControl").Disable()
either playerInput is null or it doesn't have an actionmap named PlayerControl
your if statement on line 22 is very weird - seems inverted
and why are you mixing and matching a PlayerInput with using the generated C# class
typically you'd only use one or another
if playerinput is not null then do stuff otherwise shout at me
what's the point of line 25 if playerInput is already not null?
And what's the point of playerInput at all, since you're using the playerInputActions that you're creating on line 24?
you seem to be mixing up two different styles of using the input system
that might be possible
I am using it for the first time in a project and am completely overwhelmed
hi uh i have a TMP input field built to android but when i put something in "Text" doesnt update and also "Placeholder" doesnt show
show what you mean. but also this is a #📲┃ui-ux question
oh sorry ima migrate there
that was the problem. comment line 25 out was all that was needed to make it work >.<
but hey. now i have new funky problems to solve .-.
the StarterAssetInputs go crazy and I have no idea why
I have a press interaction on "Movement" and a Press and Release interaction on each scheme inside "Movement"
why
yeah fuck the new system. i give up
its not worth the stress and the damage it does
have fun fixing
I think the press was leftover from a tutorial, the press and release was to react to holding the direction buttons down.
I will tell you that you don't need/want any interactions for a simple movement axis input, unless you want a custom deadzone or something
I have keyboard/mouse and game pad and joystick support. I have no issues filtering device id to route actions to specific players. But I’m having trouble doing this with the UI input module. How can I say, prevent certain devices from triggering UI input actions?
So when app loads I have 5 inputs (1 keyboard, 4 game pads) and all interact with UI, but I only want Player 1 to have that ability.
I can’t disable the other devices because I need input to listen to them in case a “player wants to join” the session.
Well, I'm otherwise not sure how to keep repeating input when the button is held. The player should move continuously if the user holds the button for movement down.
You don't need to repeat input
you save the current input value in a variable
and you use it in Update
But then don't you have to keep getting the input to check when the user releases the button?
If you're not going to have an "interaction"?
you will get a callback for the release, with the new value of 0
basically your whole callback function just needs to be currentSpeed.x = context.ReadValue<Vector2>().x;
Ok, but where is the proper place then to "AddForce()"?
AddForce should be done in FixedUpdate
Ok. That works a little better.
I need to expand my arena to experiment more.
I also need to make sure that jumps can only happen on the floor
Thanks
Oh.... and I need to make sure my character stays upright.
you can freeze the player's rotation on the x and z axis if you want this
Even if the rotation is frozen, can I manually rotate it?
Well, I'm thinking if the player turns around when going the other direction. He's not gonna walk backwards
We're not freezing rotation on the y axis
Is using inputs like GetKey() the old system?
Anything that is Input.xxx is the old system
Hello! I'm following along with a tutorial using the new input system and I've hit an unusual snag. Right now I'm just trying to get the camera to move up and down, and while the inspector shows the values are changing with mouse movement, the camera holder (which the camera is a child of) isn't responding to the changes in said values and not moving. Have I missed something? ```cs
public class scr_CharacterController : MonoBehaviour
{
private DefaultInput defaultInput;
public Vector2 input_Movement;
public Vector2 input_View;
private Vector3 newCameraRotation;
[Header("References")]
public Transform cameraHolder;
[Header("Settings")]
public PlayerSettingsModel playerSettings;
public float viewClampYMin = -70;
public float viewClampYMax = 80;
private void Awake()
{
defaultInput = new DefaultInput();
defaultInput.Character.Movement.performed += e => input_Movement = e.ReadValue<Vector2>();
defaultInput.Character.View.performed += e => input_View = e.ReadValue<Vector2>();
newCameraRotation = cameraHolder.localRotation.eulerAngles;
defaultInput.Enable();
}
private void CalculateView()
{
newCameraRotation.x += playerSettings.ViewYSensitivity * input_View.y * Time.deltaTime;
newCameraRotation.x = Mathf.Clamp(newCameraRotation.x, viewClampYMin, viewClampYMax);
cameraHolder.localRotation = Quaternion.Euler(newCameraRotation);
}
Where are you calling CalculateView()?
In reference to what? The script is attached to the player, currently. Is there another place I should call the function?
In reference to.. .anything? If nothing is calling that function, it will never run, and the rotation of cameraHolder will never change
that's where you're doing cameraHolder.localRotation = Quaternion.Euler(newCameraRotation); which is what would actually rotate the camera holder object
That's very true, I thought I was following along with the tutorial properly because the script worked on his end, but maybe I should take a closer look and see if I've overlooked something
any good tutorials on the new input system
cant find any
Ive looked
and they never work
i mean input manager
I tried this one
In this video, we are showing you how to create a cross-platform character controller using Unity's Input System!
Download this project here:
https://on.unity.com/39WT0iv
For more information about the Input System - click here!
https://on.unity.com/2MJnzj2
Chapters:
00:00 Intro
00:29 Input Manager
01:10 Installing the package
01:34 Using th...
but the movement wouldnt work right
Cause here i had to mash wasd to actually move
the brackeys vid is outdated
All i want is to use the 3rd person movement brackys made
but with this system
so how do I do it?
Youre using an event for movement
Events only get called once per button click not every frame while it's held down
I tried with buttons but when i press a button it will trigger twice
Are you using the Input whatever component?
PlayerInput Component
That's usually best practice
So how would I make an input script?
do you mean the same script that the manager makes?
No you use the script the manager makes
This one?
Yes
So do I attach it to the player?
Is there any prerequisite for a method to be detected by the Player Input component in Invoke Unity Event mode? In the image there's my current config and this is my C# script (MonoBehaviour is declared in one of the parent classes)
However no method appear when I try to select the event
using UnityEngine;
using UnityEngine.InputSystem;
class PlayerPlane: Plane
{
public void Axis(InputAction.CallbackContext context)
{
Vector2 value = context.ReadValue<Vector2>();
Debug.Log(value);
}
}
what methods appear
None
Can you screenshot
The literal one thing that appears is MonoBehaviour -> string name
Also ive heard not to use player input
I'm unsure what exactly you're looking at, if this is not the answer please do screenshot it, it'd make it less vague
So how am I gonna add the input stuff here?
Oh, it needs to be the component, not the script, got it. And yep, it works now
I was really confused as to why it was working before and wasn't any more
nvm got it to work
You got it now?
Yep
Can I see it?
here
Now i gotta figure out the camera
(the camera is similar to luigis mansion)
Cinemachine
That's fine, you don't really have to make a variable for movement InputAction but itll work the same
Cinemachine can switch to first person
Hello, I need some help with mobile input system
I really can't understand it like keyboard input
guys how do unity devs handle double key press?
cuz I'm new and all input methods I'm looking at are continuous
Anyone have bright ideas?
Short way how to know if the object that was triggered event UI or Not. Or know the tag or layer of that object. Key element that camera have physics ray caster.
private void Update() {
if (EventSystem.current.IsPointerOverGameObject()) {
if (Camera.main is null) return;
var ray = Camera.main.ScreenPointToRay(point);
if (!Physics.Raycast(ray, out var hit, maxDistance, layer_mask)) { //if it hit no game objects, that means it is UI. as it shoots only after it is over UI.
isOverUI = true;
return;
}
if (Physics.Raycast(ray, out hit, maxDistance, layer_mask)) {
if (hit.collider != null) {
isOverUI = false;
//if there is an object that triggered this event, that means it is not UI.
} else isOverUI = true; //this one just in case I guess
}
}
}
this is my current solution. it works.... But ..... It is not pretty solution and I want to make code that makes sense. Teach me senpais
A thing you could do, instead of the last
if (hit.collider != null)
IsOverUi = false;
You could just use
isOverUi = !(hit.collider != null)
Or
isOverUi = Hit.collider == true
So, I found a script that I think might work well for my purposes, but it used the old input system and I'm struggling to convert it to the new system. It's changing a bool based on it's press state, setting it to true when pressed then false when released. Is there a way to do something similar with the new system?
yep - either using started and canceled events or by reading WasPressedThisFrame() and WasReleasedThisFrame() from an InputAction
I'm looking for some advice on dealing with a local multiplayer game which uses split screen where players need to be able to navigate their own menus on their own screens (at the same time). Using the new input system, the Input System UI Input Module and the Event System doesn't seem to result in the desired behaviour, as either only one player can control the UI or they can control each other's UI. Any ideas on how this should be done in the new input system?
The new input system introduced a MultiplayerEventSystem component for exactly this reason https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/UISupport.html#multiplayereventsystem-component
Brilliant. I knew there had to be something I'd missed. I'll give it a go now.
Can you provide an example of that toggling a bool? I've been pouring over every last hit I could find on Google but everyone has a completely different answer
What's confusing about it? You'll want to start with what style of input handling you've chosen, as the Input System supports many
Are you using events?
Polling things in Update?
Using a PlayerInput component?
I'm not using events or polling in update, I'm using DefaultInput
I assume "DefaultInput" is the name of your input actions asset?
yep
You must use either events or polling in update to do anything with that
Yeah, that worked like a charm. Not sure how I missed that at all. Thanks!
Sounds like you are using the generated C# class.
Yep; I'm looking at the documentation for events now and it's like its bouncing right off my eyeballs
you are either using events right now or polling
there's not really any other options
I think I'm going to have to use polling unfortunately, this doc is so obtuse I'm not sure I'm capable of processing it
I don't even know bro, I am so lost. Here, let me post the script as is on GistHub then I'll link to the original script I'm trying to convert from
My current script: https://gist.github.com/ProudCipher/59753a984af76505b1c9c3cdacf83d56
The original script: https://gist.github.com/ProudCipher/746f41e81e8ce843292ff268cde3133c
Well after diddling around a bit I've found the Player Input component and it's ability to broadcast messages
How to make use of those messages, I'm still working on that
Any advice on ensuring a button stays **visually **selected (colour tint) even after the canvas has been disabled and then enabled again? The EventSystem clearly remembers which was selected as you can submit and it executes the right one, but visually it doesn't have the colour tint.
I have been trying to figure out this bloody input system for 4 hours and I still cannot find anything that tells me plainly how to toggle a bool. Sure ReadValue<> is a thing but whatever value it reads cannot be converted to bool
this is genuinely upsetting
What are you trying to detect? A button press to toggle a bool?
yep, I want LMB to toggle 'shooting' to true while down and 'false' when up
I keep seeing promo material from Unity claiming this is easy but this is the hardest thing I've had to do in Unity
literally nothing that has been suggested seems to work and I cannot find a straight answer as to why
Ok, one way to do this is to change the Player Input Behavior option to use Invoke Unity Events. That way you can use callback contexts. If you open the Events section at the bottom you can then define what function on what script to execute when the button is held. In your code you can then use InputAction.CallbackContext.
I just tried that actually. 'InputAction' doesn't exist it says
Like I said dude I'm done. Thank you sincerely for trying to help but this just isn't going to work.
Add "using UnityEngine.InputSystem;" to the top
I tried that too! It didn't do anything.
I thought I was really starting to get somewhere with making a game. But apparently, unless someone is holding my hand through the entire process like a goddamned toddler I am mentally incapable of going it alone.
As much as I want to blame Unity the fact of the matter is I'm just disabled or something
To be fair the new input system, whilst being very flexible, isn't the easiest to get going with.
Plenty of people seem to get along just fine with it, and those that don't usually seem to find answers somehow.
No, with my experiences with Unity thus far it's pretty clear I'm the problem
I'm not quite ready to give up the dream just yet but christ this is demoralizing.
Again, seriously, thank you for trying to help me.
i'm going to bed, peace
how should i remove all bindings from an InputAction (including composites etc.) - doing
foreach (InputBinding b in bs) playerInput.actions["Player/NavigateUI"].ChangeBinding (b).Erase ();```
doesn't work and it's the best i could come up with
that gets a "InvalidOperationException: Instance not valid" error, the action is a Value Vector2 type with Delta [Mouse] bound to it by default for testing
Instead of sleeping, I just kept thinking about the damn script and where I was screwing it up. So I took some extra adderall and have attempted to figure it out on my own without a tutorial or external script.
Naturally, it's borked. However the errors this time feel much less intimidating, so I'm not too bummed about it. I've tried to use function calls to set the bools this time around. I was trying to use Update() to check one of the functions but all it did was set every variable to true and flooded the debug log. If I comment those calls out, the mouse button input doesn't seem to work either. Would someone be willing to look things over and see where I've gone wrong?
While I wait for someone to (hopefully) lend a hand, I'll be watching Brackey's video on the input system to try and better understand this eldritch abomination
watch samyams videos
will do
I think what is causing some confusion for me at least is the use of the Update() loop with the new Input System
so you're setting a bool to true in the subscribed function for the performed action, and then letting the Update() use that bool
What might be better is to instead call the function directly inside the subscribed function
Sorry, but what do you mean by "subscribed" function?
the .performed callback
defaultInput.Character.PrimaryFire.performed += e => PullingTrigger();
Oh? Could you show me an example?
Learn to develop games using the Unity game engine in this complete course for beginners. This course will get you up and running with Unity. Free game assets included!
✏️ Course developed by Fahir from Awesome Tuts. Check out his channel: https://www.youtube.com/channel/UC5c-DuzPdH9iaWYdI0v0uzw
⭐️ Resources ⭐️
(To download assets you may have...
Thank you very much for helping by the way!
Right now the update loop is dealing with animations a lot of stuff, I'm suggesting getting rid of the Update() loop entirely
So instead of checking for a bool every single frame, make it all event based. When you press the fire button, set the animations to go into the fire animation
Shouldn't those calculations be in Update since they rely on Time.deltaTime?
well you'll have to re-code it differently
it's a different approach than what you have now
Ah jeez the event system. Well that seems to be the golden ticket to using the new input system since events were frequently referenced
I'll have to learn it eventually
Might as well buckle down and try now
yeah the old way of doing input was to have a huge if then block in an Update() loop, and it absolutely sucked to work with
Well I'm all for more efficient scripts
the new way you just subscribe a function to fire off whenever a certain Input occurs (the performed callbacks) and just let the input system tell you when to execute it
I've got some examples from a little project
I'll just have to study diligently and try to see it in action so I can better wrap my head around it
// Unity functions
private void Awake()
{
controls = new PinchTouchControls();
controls.Touch.TestTouch.performed += context => Shoot(context);
controls.Touch.TestTouchMouse.performed += context => ShootMouse(context);
EnhancedTouchSupport.Enable();
// Start listening for disable shooting events
EventManager.StartListening(Events.RoundStart, OnRoundStart);
EventManager.StartListening(Events.RoundEnd, OnRoundEnd);
mainCam = Camera.main;
}```
you also need to unsubscribe
what is subscribing used for anyways? Never have needed to use it before
don't need to handle memory leaks if you alt f4 lol
to get input context
Might have to rewrite the entire thing. That's an intimidating thought considering the vast majority of it was me following a tutorial and copying code by hand
player input will handle all that
ah I can see that
// Shooter functions
private void Shoot(InputAction.CallbackContext context)
{
bool isTap = context.action.ReadValue<UnityEngine.InputSystem.LowLevel.TouchState>().isTap;
if (isTap)
{
Vector2 screenPos = context.action.ReadValue<UnityEngine.InputSystem.LowLevel.TouchState>().startPosition;
var ray = mainCam.ScreenPointToRay(screenPos);
RaycastHit hit;
if(Physics.Raycast(ray, out hit))
{
var target = hit.point;
ShootAtTarget(target);
if (hit.collider.tag == "Enemy")
{
//debugtext.text += $" hit enemy";
}
}
}
}```
there's like 10 different ways to get input
in this new system
none are better than another
it's just a ton of options
lol ive just been writing references to different scripts and testing a var
which the var holds input
I mean I could rewrite everything to subscribed events, but I don't want to fuck up my code lol
so it makes learning the system 10x harder
it will fuck everything up
learn them all and use them accordingly
or choose one
but it is more efficient
ill prob start using them once I need to get input from MULTIPLE events at once
and then when you ask for help someone tells you that's the wrong way
I should be able to figure this out if I really put some time and effort into it, right? Writing my code more efficiently and less clumsily should be worth it
That was the exact source of my original frustration
less lines and less room for error
so yeah
Hell even the official documentation is about as beginner friendly as a crash course in bomb defusal
That's why I like the samyam videos. After watching them like 5 times over I got the hang of it, and it is way easier for me to handle input now. Like before it'd take me hours to deal with user input, and now I can get really responsive input in 10 minutes
I just watch tuts, and recreate them, and usually by then I understand how they work
The docs for just about every other part of Unity manages to provide some clarity, but the input system doc is agony
they assume you know everything
and it doesn't help when there's confusing shit like inputsystem.inputsystem
https://www.youtube.com/watch?v=ERAN5KBy2Gs ```
I watched both of those videos over and over until I finally understood
This experience actually made me briefly consider switching to UE4/5 until I remembered C++ is my sleep paralysis demon
i heard ureal is more user friendly
it has to be to make up for C++
It definitely is. The benefits of having a multi-billion dollar corporation backing it
less fighting the engine more making games
Unity's strength definitely lies in its community
Case in point: y'all! ❤️
At least we're not using Godot
It's necessary for progress in these industries. In tech, you snooze you go bankrupt
It still baffles me though that Unity considers itself the 'accessible' engine when its documentation and new user experience are basically hate crimes
yeah they need to hire someone that speaks human
They could do things differently/better, but overall it's good enough (don't ban me mods)
Especially they could maybe offer a multiplayer solution that isn't client/host combo package
I mean yeah, if it was shit we wouldn't be using it. Unity has some pretty great features that keep it afloat, such as the relative ease with which you can deploy software on virtually any platform
Hell, their WebGL stuff continues to impress me
I was about to say excluding webgl lol
that entire platform is just up in the air atm
are they going to switch to WebGPU? Will they ever support multithreading? Will I die of old age before I know the answer to these questions?
Well from what I've read, you actually can include multithreading with their jobs system
What i'd really like is for the bloody editor to use more than one thread
I've got a 3900x overclocked on all cores to 4.3Ghz at safe voltages and it uses one or two of my 24 threads
I specifically bought it because it was my understanding that compilers, terrain generators and the like thrived on parallelization
I think default it uses one thread for rendering (with batched jobs helping) and one for audio?
Terrain generation you'd do in like maya or blender no?
I don't actually know if either of them can do proper terrain generation, I was thinking more along the lines of WorldMachine
Which I dread potentially having to use again because apparently a 200x200m block of land requires half a terabyte of storage
WorldMachine looks cool
Oh yeah it's bonkers
I just need to know, if I have keyboard or mouse controls for my game, that absolutely NEEDS a mouse and cant be ported otherwise, do I need to do anything extra for the mouse to work on the android device if someone plugs it in
Trying out that samyam video that was recommended to me, might be cool
If I recall, Unity supposedly allows you to directly work with USB HIDs though I don't know if that extends to mobile
It seems like it should since android uses the same USB protocols everyone else does
okay, I might see if I can find a usb-c to usb adapter just to test it
I believe Unity references those devices by their UUID, you'll need a way to expose that information on android
that fact NO ONE online had the same question on me that I can find leads me to believe that it just works
Hmmm well I did have to create separate input actions for mouse input and touch input
To my surprise, Unity can connect to Bluetooth devices in much the same way according to that document
Shoot and ShootMouse have the same functionality, just connected to different input types
@tame oracle if you're on Windows, maybe take a look at the android subsystem for windows to help you along
Holy cow this samyam is blowing other tutorials and guides out of the water with how clearly she's explaining things.
Another thing the new input system solves is the previous conflict of reading input and the physics system. Before you'd have issues where you would try to move the player in Update() and it would give jittery movement/clipping glitches because the FixedUpdate is where all the physics processing happens. You could try to process everything in FixedUpdate, but it isn't guaranteed that your input will be received on a FixedUpdate frame. So you'd sometimes click and nothing would happen. The new system you don't have to worry about any of that
You know, now that I'm watching this it's all beginning to make sense. With a bunch of crap thoroughly demystified I can suddenly see the advantages of the system
I don't know if that makes me more or less angry because this 30m youtube video is utterly humiliating Unity's official resources on the matter. It's criminal how poorly they explain it!
I have a question about the new input system #archived-code-advanced message
Pretty new to using the new input system, but I'm trying to have my game recognize when a player clicks on a game object (2D). Been doing some research on ways to do this and saw things like OnMouseDown() and Raycasts but wasn't sure if there was a better way to do it with the new system. Any recommendations on ways to go about recognizing mouse clicks in 2D?
From what it sounds like, OnMouseDown() no longer works with the new input system so I'm looking for some direction. 😅
make a detection method subscribe to an input action bounded to mb1
Could you explain a little more what the detection method could look like? I understand how to create input actions with the system but I'm struggling with checking if the object has been clicked on.
raycast is your best bet
Bet, I'll look into that more then. Thank you!
Okay, so I do feel like I've actually learned a bit about the Input System, but I've hit a weird snag. I'm trying to use unity events to trigger the Fire() function in the weapon controller script. No matter what I do it seems I can't get any functions to appear in the PrimaryFire event in PlayerInput
show a screenshot
I tried simply plugging the weapon controller script into it, nothing. Wrote a bunch of stuff into the character controller, still can't see nothing
Of the player input component?
yes
does the fire() method have an inputcontext parameter
You mean like cs Fire(InputAction.CallbackContext context) ?
yea
No, but I'll give that a whirl.
Nope, that didn't seem to do it
public void Fire(InputAction.CallbackContext context) //pow pow pow
{
}
that's what I tried
is it a monobehaviour
Pardon?
the weapon controller script
Here's the weapon controller script, lemme do the char controller too
I mean there's scr_WeaponController : MonoBehaviour in the class declaration
Man though it feels like I'm getting close to a breakthrough at least
instead of adding a script to the bottom left input, add the gameobject
instead of scr_weaponcontroller
whatever the parent is
unity's fault for even letting you put a script in
hey what do you know, it showed up when I actually did it correctly
unga bunga I'm maximum smoothbrain right now
Anyway, lemme plug a Debug.Log into the Fire function and we'll see how the inputs are behaving
Yep, it reads it. Now I just gotta stop it from calling Fire() three times with each press
I could tell you but it would be better if you learn how yourself
I'm going to set an interaction on the bind for press and release and see what that gets me
lmao that literally made it worse and called it 4 times instead of 3
read through that if you really want to learn how everything works
had that open on my other monitor actually
welp lets see what I can find
Hmm...no changes yet. I do notice I'm getting two calls of Fire() when I press, and a third when I release the button.
button
i think you have to check for performed inside the method
if
(context.perfomed)
i don't use unity events so im not entirely sure
or it might be
if(context.phase == inputactionphase.perfomed)
Lemme see
This look right? ```cs
public void Fire(InputAction.CallbackContext context) //pow pow pow
{
if(context.performed)
{
Debug.Log("Fired!");
}
}
if not that then try the second one
the mouse delta action becomes far more sensitive when I'm performing the move action, how can I solve this? I'm using the default generated input actions for player input
Well now, I just have to figure out how to enable fully automatic fire
at last
finally
FINALLY
It's a little hit-or-miss, it doesn't always register quick taps and sometimes just stops responding altogether, but thats a hell of a lot better than it was earlier today
I'm trying this out now to try and improve how quickly the bool changes ```cs
public void FireTap(InputAction.CallbackContext context)
{
if(context.started)
{
pullTrigger = true;
}
else if(context.performed)
{
pullTrigger = false;
}
}
Hard to tell if it's really having an effect though
started and performed start at the same time unless you use an interaction
FireTap is a separate function that uses the Tap interaction; in this case, started marks the moment the pressPoint is passed and performed is when it goes back below pressPoint before the tap duration
For once, the documentation was actually very helpful
god I'll tell you man that was an exhausting experience, but it definitely feels worth it. I think I might have gained XP lmao
anyone know why it gives me error that type movement already contains a definition for sprint? i tried to add sprint with new input system
InputField.isFocused what is replacements to this in new input system?
nvm i figured this out
Is there a known issue in the new Input System where touch events on windows are not reliably reported, particularly touch-ended/-lost events?
InputField is not part of the input system, it's part of UGUI (the UI system)
Moving over from #archived-code-general:
@austere grotto
These are all super helpful, thank you! Say I wanted to grab that InputActionReference from the code alone, I would need to somehow grab the whole input schema first, right?
Like Say I have:
InputActionReference mousepos;
Vector2 foo = mouspos.action.ReadValue<Vector2>();
If I chose not to assign mouspos through a serialization in the editor, how would I go about assigning it in the code?
You could instead do e.g.:
[SerializeField]
InputActionAsset myActionsAsset;
void Something() {
InputAction mousePosAction = myActionsAsset["Actions/Mouse Position"];
Vector2 foo = mousPosAction.ReadValue<Vector2>();
}```
where now you're referencing the whole asset
and you can get a particular action from a map/action name string
(this is assuming your action map is called "Actions")
Gotcha, so what I'm getting is that really at some point it'll require that I wire in either the whole InputActionAsset, or wire in individual actions, but either way I need to use the editor to do so, if I'm creating said mapping in the editor.
Again you can also use the generated C# class (there's a checkbox to generate this in the inspector for your actions asset), and then you'll get something like this:
// this class name is based on the asset name
MyInputActions myInput = new MyInputActions();
myInput.Enable();
InputAction mousePosAction = myInput.Actions.MousePosition;```
The new system is very flexible, but it can be confusing since there's so many options
I'm getting that. Once I have it down though it seems way more robust and easy to change on the fly
One slight change I might add is subscribing to the timing of the input action
At the start I would subscribe to the .started event with cs FireTapStarted(InputAction.CallbackContext context) { pullTrigger = true; } and the .performed with another function cs FireTapPerformed(InputAction.CallbackContext context) { pullTrigger = false; }
which would required adding them to the top cs controls.InputTest.started+= context => FireTapStarted(context); controls.InputTest.performed += context => FireTapPerformed(context);
just ask your question
im trying to make a script that moves the player left and right with the analog and w and d keys
but i just can seem to get it to work
Well I would start by watching this video a few times and copying what she does https://www.youtube.com/watch?v=m5WsmlEOFiA
How to use the new input system in Unity! I go over installing the package, the different ways to use the input system, and the recommended way!
📥 Get the Source Code 📥
https://www.patreon.com/posts/55295489
►🤝 Support Me 🤝
Patreon: https://www.patreon.com/samyg
Donate: https://ko-fi.com/samyam
🔗 Relevant Video Links 🔗
ᐅALL of my Input System...
I have
they never did anything with analog sticks
ill watch it again and check back if it worked
Do you have an input action map for an analog stick setup?
your action type should be value, and control type should be stick
the binding will list all the sticks unity supports
yeah
let's see it
ok
hold up my start menu just broke
i need to reset my pc
back
@gleaming oar here you go
excellent, and how are you reading the value in code
I'm not super familiar with using the Player Input component as I've instead just created a new object from the generated controls class
Is it a requirement for you to use the PlayerInput component?
I believe so
Ok, I think you'll have to access that component in your Player Move script then
and it should be similar to doing it the other way
you need to use the player input manger to make 2 players
and when ever you use the player prefab it doesnt let you
im so sorry but i gtg
controls.Player.AnalogStick.performed += context => ListeningFunction(context);
in awake? or update
ive already done this
MoveAction.ReadValue<Vector2>();
MoveAction.performed += ctx => Move(ctx);
MoveAction.performed += ctx => analogValue = ctx.ReadValue<Vector2>();```
Hello! Can the input system be used the specify which direction your character moves on the map?
idk
Or is that a coding thing?
i see
Sure I would love to see it
ok, is it okay if i dm it to you?
Sure
k
nvm
yes, naturally, that's kinda what the input system is for.
does any one know why i cant select my functions in the select function dropdown menue in unity
I only see mono script
This means you dragged a script into the slot, which is not correct.
You need to drag a GameObject that has the script attached to it into the slot
but. . . I have
You have what?
i have script in slot and in player
Right - like I said dragging a script into the slot is not correct
ok
If you have the script attached to your player GameObject, what you want to drag into the slot is most likely your player GameObject
mhm
thank you so much
but my functions arnt showing up now
{
rb.AddForce(analogValue.x, 0, 0 * speed * Time.deltaTime);
}
//Jump Function
void Jump(InputAction.CallbackContext ctx)
{
rb.AddForce(0, jumpPower, 0);
}```
they must be public
I know it moves characters up/down/left/right but I am wanting the player to move in a specific angle
Anything is possible with the right code.
Okay. I'll need some help figuring out the right code when I get to that point.
how do you use the chat system with the new input system for detecting when the player pressed enter while text box is active?
Answer: It works!
As long as you are using the new input system input module on your event system, you're good to go
alrighty
You can use the on submit thing for the InputField
my controller shows up in input debugger but not in console, w h y ?
when I unplug my controller it says "XinputControllrWindows"
How would I go about setting up " Quadrupedal controller" for the player? Would this be using Unity's new input system? Any tutorials for this?
Input system is for reading input from the user's input hardware. This sounds like a general scripting question
Well I googled "Quadrupedal controller". I've never heard or seen it before. I've made 6 games already myself, 4 published. 1 3d 3rd person, the rest 2d.
I don't see video's for Quadrupedal controller
It seems to me that "quadrupedal" would be primarily an Animation concern
I've seen people make procedurally animated walking creatures with 8+ legs
But the way the character controls generally has little to do with that
Why would you do this? I heard about this.
I'm googling more. So Quadrupedal controller, you think this is a separate collider for each leg? Why not just use 1 collider?
I never said that
Heyo folks, I have a question~ Is it possible to set up W|A|S|D 2D vector composite along with a held button?
Like shift+W|A|S|D?
Idk but I’m sure you could check to make sure they are both performed in a script
Hey guys, so I am using Brackey's player movement script for 2d but it runs on the old input system. Can someone help guide me through how to switch it from a code perspective. I watched a bunch of videos, but all of them weren't super helpful because many are outdated
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.3/manual/Migration.html
Pretty decent guide for converting any old Input.xxx call to the new system
Thank you so much @austere grotto. This looks like what I was looking for. I'll let you know if I have any questions
I always forget that it's possible to just declare InputAction(s) directly on a component and use them directly
Does anyone know if mobile touch on Unity Remote is supported on the new Input System?
I can't get it to work and I'm seeing old threads that say it doesn't work, but I mean come on the new input system has been out for over 2 years and getting it to work with Unity Remote is vital to get people to switch, it should be integrated by now
hi, someone can help me? I'm getting this error: "The type or namespace name 'InputTestFixture' could not be found (are you missing a using directive or an assembly reference?)"
I don't understand why it don't find InputTestFixture class
guys help
i cant add license on unity hub
btw im in macbook and i logged in and im connected to the net
whts the problem
Are you missing a using directive, as the error suggests?
no, I needed to change the manifest
hey
Which one should I use "Send Messages" or "Invoke Unity Events" on behavior
I am making simple driving simulator to play with my steering but the issue is input is not detected until some threshold amount of wheel is rotated. Is there any way to solve please
it works fine after threshold is crossed
It'll be in the configuration of your Axis (old input system) or Input Action (new input system)
I am using new input system
something like this
yep, add a processor for the deadzone
brb let me try again
oh also - another thing to try is temprorarily remove the other bindings, sometimes they interfere
you mean other actions ??
I think uncheck Default there and set the deadzone Min to 0
or something quite small
cant assign lesser than that
really? 🤔
i'll recheck
ya it resets to default
but thought deadzone means end points of sticks
like range of value from controller
deadzone is how far you can move the joystick before it detects any movement
all movement inside that zone is "dead"
what is difference on axis deadzone and stick ?
stick defines both axis dead zone ??
I changed default value from input settings to 0 now it might work i guess
Hey guys, so I am using Brackey's player movement script for 2d but it runs on the old input system. Can someone help guide me through how to switch it from a code perspective. I watched a bunch of videos, but all of them weren't super helpful because many are outdated
I believe axis dead zones are for things like mouses while stick deadzones are for controllers
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.3/manual/Migration.html praetor blue sent this before, use it
solved issue
thanks
but it was quite opposite to what you said
i set min dead zone to 0 and max to 1
deadzone is sth like [min,max] where value less than min is dead and greater than max is dead
i did, and didn't find a solution
I've used it so I know it works, what part of the tutorial don't you understand
so, I set it all up in unity, but idk how to do it in code.
I added the stuff
private void Awake() { controls = new PlayerControls(); controls.Enable(); }
But idk how to convert this
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
into the new system
@foggy notch
I'm doing the roll a ball tutorial and I can't get the ball to move under my player input property in the inspector I see this error. Could this be why?
I am really stupid. I figured it out and fixed it though.
what is the best way to get mobile input ?
For movement, I used UI buttons and a manager script with a public method that takes in a Vector3
Set the movement Vector3 to the button's OnClick method parameter while the button is pressed
is there a better way to do this? ```cs
input.Player.Sprint.performed += () => isSprinting = true;
input.Player.Sprint.canceled += () => isSprinting = false;
No
I was gonna ask a question about how to figure this out but I figured it out on my own
public class CinemachineManualInputProvider : MonoBehaviour, AxisState.IInputAxisProvider
{
public Joystick rotateVCamJoystick;
public virtual float GetAxisValue(int axis)
{
switch(axis)
{
case 0:
return rotateVCamJoystick.Horizontal;
case 1:
return rotateVCamJoystick.Vertical;
case 2:
return 0;
default:
return 0;
}
}
}
If you ever need to provide your own input to a cinemachine, you can do it like this
And it'll look something like this, hope this helps someone
even better
public class CinemachineManualInputProvider : MonoBehaviour, AxisState.IInputAxisProvider
{
public Joystick rotateVCamJoystick;
public virtual float GetAxisValue(int axis)
{
return axis switch
{
0 => rotateVCamJoystick.Horizontal,
1 => rotateVCamJoystick.Vertical,
_ => 0.0f
};
}
}
basic question: how can i receive multiple inputs at the same time?
Which input system
What would be the preferred way to recognise "Combo" inputs like: Down, down, up, up, left, right, a, for example
track them in script
the new one
You could just read it in update instead of using events
bool isSprinting = input.Player.Sprint.IsPressed();```
I'm using the new input system and I'm trying to do just up,down,left,right,forward,backward for movement, but the vector3 has other dimensions that cause my player to do wacky things unless it's on the zero y axis, how do I change the Vector3 to just vector3.left etc like the old
Just use a Vector2 for forward, left, right, back and different inputs for the reset
Theres no such thing as a three dimensions stick, you only need your input in 2d vectors
2D Vector
Oh thanks
That's not really working for me, W & S now move it left and right and A & D don't do anything
It does work, you just don't have it set up right
So, this is weird. I get this error:
NullReferenceException: Object reference not set to an instance of an object InputTemplate+CameraLookActions.get_CameraPan () (at Assets/InputActions/InputTemplate.cs:1399) CameraTargetManager.Awake () (at Assets/Scripts/CoreSystem/Camera/CameraTargetManager.cs:21)
In a call to auto-generated code. What gives? What do I need to be passing in here? I don't think I'm doing anything special, so it's a little frustrating to be blocked on this.
You where right, it did work, oddly when converting from Vector3 to Vector2 it switched the keybindings about...
It didn't fix my original issue though, so not really advanced anything.
Fixed my issue, lol had the rigid body on the inner object of my player so it was going wild...
I think CameraTargetManager doesn't know what InputTemplate+CameraLookActions is
That doesn't seem to be where the exception is thrown. I create a variable of type InputTemplate.CameraLookActions within CameraTargetManager, and the variable shows a value. But when I try to get any of the four actions within the variable they all throw null reference exceptions.
do some debugging
I'm staring at the debugger. Any time I try to reference any of the actions they're null. It's some kind of setup issue; do I need to instantiate the generated code for the ActionMap before I reference it within an object?
yes
Can you point me to sample code for this? I downloaded some viking warrior sample thing and have watched three YouTube clips but I'd love to have some reliable reference code to work with.
'clips' - they were each 20 minutes long.
Thank you.
You are a gentleman and a scholar.
Nice. It works. Instantiating and setting up the callbacks rather than attempting to access the properties fixed the issue.
Uh. Follow up question. Will this thing manage its own Singleton state? Do I need to worry about instantiating the class in two separate places, and build a manager class around it to avoid that?
uh how do you switch input settings from the old to new input system
oh sorry for not clarifying
im getting this error
but I don't how to change it
Show the script it's referring to
I didn't write a script yet
at least for the new input system
I commented out the old code
It's referring to an old script you wrote
You have a script that does Input.whatever
Which is why your getting that error
He hi, i wonder if someone could point me out how to use Unity UI button highlighting with the new input system and a gamepad.
I am currently using the Handler interface calbacks to refresh the highlight state of the buttons, but i guess it should support it natively (?
Is there any issue with that?
I get the UI elements highlighted and can navigate with the mouse, but when using the gamepad i can only navigate and select, no highlight change.
Your at a level where I don't think there is specific documentation on that, if you showed the code and explained why it's not working people might be able to help
Im just asking if there is any known issue about the input system not doing the highlight transition
lol
im pretty sure I don't have that tho
You do I promise
Send your whole error log
Does your game have a UI or use cinemachine
Disable the UI and see if the error goes away
im sorry stupi8d nquestion how do you disable ui
The canvas...
that didn't work
The error is still there?
yep
Ehi guys, I created 2 gameobject and they have the same new input system I would use them simultaneously in the same scene. Inside Unity, they work both, when I press D, they move right in the same time. When I build the game, only one works. What can I do? 😢
I know I'm a week off on this, but searching the discord led me to this and it's exactly what I was missing
Is there an easy way to make key-presses act the same way as controller presses? It seems like the Logitech F310 I have continuously sends right thumbpad data, where the keyboard processes a keypress once and leaves it there.
Show the two scripts
The new input system
I'm working with the new input system. As I said, the thumbpad sends continuous events where the keyboard does not. I guess I can simply operate off of the 'triggered' property, but the autogenerated, "OnCameraForwardBackward" event ends up with two different types of input.
Actually, I'm wrong, nevermind. The thumbpad just changes more.
I seem to be missing the defaultinputactions asset that's mentioned here:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/UISupport.html
Anyone know how I can get it, or re-create it in my custom system?
found it! I needed to click all for the search, it was hidden
Using the Input Actions, how would one go about performing a "tap and hold" type of action?
hold interaction
Hey, how I check what the last controlScheme my player used is?
I want on screen prompts to change based on what input the player is using, and I have controlSchemes for keyboard and gamepad
Specifically I'm trying to create a dash movement on a 2d platformer. Currently when I double tap the button, the player performs a dash. I have the interaction double-tap set to 2. This results in the player needing to tap and release the button twice, then push the button down a 3rd time to continue running. Does that make sense?
that's handled by the playerinput component and set to useUnityEvents
there will be a callback when you switch controls
mhm, I have a reference to my inputActionMap already set up
though I'm not sure if thats the correct component?
do you have a playerinput component
no, I dont think so
use it
I cant
you can
not without dramatically changing my code base
you don't have to?
I'm using a third party input system, sort of
ok and?
but it still uses InputActionMap and inputActions
so?
oh hm.... player input component.... I've never used this before
ok
ok, I added it, selected my controls, set default scheme...
oh man I have no idea how to use events
alright, got my gamepad inputs working.... I just... I have no idea how to make use of these events and actions
you don't see it?
I see it, I dont understand how to implement it
make a method that changes screen prompts when that event is triggered
it says the action tahts being done when onControlsChanged.... but what do I get out of that? how do I use that to define other things or change things in if statements?
how do I check if that event is triggered
playerinput.oncontrolschange += methodyoumake
just make a method that changes the UI textures
thats the easy part
assume I have that already
changeInputPrompts()
so like... Im still nto clear on how to implement this
you make methods subscribe to the event
📝 C# Basics to Advanced Playlist https://www.youtube.com/playlist?list=PLzDRvYVwl53t2GGC4rV_AmH7vSvSqjVmz
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle
✅ Let's check out what are C# Events, how we can ...
still having trouble subscribind to the event....
I dont know how to write the method in this case
what is its return type?
void
cant do void, it errors
Cannot implicitly convert type 'void' to 'System.Action<UnityEngine.InputSystem.PlayerInput>'
inputComponent.onControlsChanged += Testing_onControlsChanged(); error caused by this line
I learn best by seeing a working example and reverse engineering it...
atm, i have no idea what a working example looks like
and its not going to be shown in this video
Hello! Does someone know how can I make Delta X behave like the old input system function Input.GetAxis("Mouse X"). I tested and Input.GetAxis("Mouse X") gave small values(1; 0; -1; 1,5) but Delta X gives values like 30, 50, -20 and so on.
not for my specific thing
the new mouse deltas work the same as the old mouse axis
if i run camera scripts that were made for the old input system, the sensitivity is very high
void Start()
{
player = GameMaster.i.player;
inputComponent.onControlsChanged += InputComponent_onControlsChanged;
}
private void InputComponent_onControlsChanged(PlayerInput obj)
{
throw new NotImplementedException();
}```
this is what I got when I auto completed after the +=
show a screenshot of your input action
ok, I made some progress... I debug.log`D everytime input changes, and thats working
now I need to figure out which input it was changed to
got it
show the new code vs the old
NewInput.GetAxis is reading the input action value
how? Show that code? When is UpdateMouseLook Running?
update
{
var inputAction = PlayerInput.actions[actionName];
return inputAction.ReadValue<float>();
}```
remove (); Nvm, controls.Touch.TestTouch.performed += context => Shoot(context);
if it was a normal action and you wanted a void type you would leave the function name without the ();
already got it 😛
just finished implementing at a basic level
void type on InputAction require the little discard underscore thingy controls.Touch.TestTouchMouse.performed += _ => TestFun();
haha that was mostly for me so I could remember
Hello, im' using the old input system. I have a problem with the touch phases. It seems that I correctly receive the touchphase.began, but sometime I don't receive the touchphase.Ended or Canceled. Is it a known bug ? Or did I missed something ?
new here, how do I add a new method to an input listening on a key I've already set ?
I added Interact to listen to F press and hold... but not sure how to register a method to that listener
Are you in FixedUpdate or Update()?
I haven't had good luck with the interactions so far, but it's just because of the value I'm wanting usually. Anyways, you subscribe the that InputActions's .performed event in your Start() loop or something at the beginning and when the key is pressed it calls back to the function you subscribed at the start and executes it
do you even have to do that, or can you just add the method handlers in the StartAssetInputs.cs .... it seems to be getting called without being verbose and registering it in Start();
Wait... can you not add an already created InputAction to an InputActionMap?
I dont understand why I'm getting this error...
Object reference not set to an instance of an object controlSchemeListener.OnEnable () (at Assets/controlSchemeListener.cs:22)
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.
if I do
private void OnEnable()
{
inputComponent = GameMaster.i.player.GetComponent<PlayerInput>();
if (inputComponent.currentControlScheme != "Keyboard")
return;
SR.sprite = KeyboardButton;
}```
then it only errors when controlScheme is Keyboard.... this makes absolutely no sense to me
ah I fixed it.... appearantly OnEnable happens before Start
Is there any way to map a keycode to a controlpath?
OnEnable runs before Start
Oh you figured that out already ☺️