Input System Action Types Explained | Value, Passthrough, Button - Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so the input system has a lot of cool features you can use however the documentation can sometimes be hard to understand or may not answer your question and one thing i did not understand is pass-through versus value for your action type and so i'm going to be explaining the different action types that are available for the input system action asset and what the difference is between them and why you might want to use one over the other so as you may know if you right click and create a new input action and then you create your action map and your actions on your newly created action you have an action type and there's three different types value button and pass through so i'm going to explain all three of these in depth however in general for value and pass-through you have different control types that you can choose from so for example we select value or pass through we have a bunch of control types here any analog axis bone digital double etc and the one i use the most is vector two for movement and looking around whereas for button you don't really have that option it's just a button and ideally you'd use this action type if you just want to know when a button has been pressed down but before explaining value button or pass through i have to explain the different callbacks that the input system provides so the input system is event based and that just means it sends out events for any type of input that you make while playing the game so if i start pressing down for example on this button the input system will send out an event that we have started to press down on this button or we have press down on this button and then we can subscribe to that event and get that value that's being transmitted so if it weren't a button maybe a vector 2 we can get that vector 2 value and we can do something with it whatever our game needs so there's different event callbacks specifically there are four phases started performed cancelled are the big three and then waiting so by default every action has an interaction and the interaction is just how you interact with the game and so you can actually add new interactions as you can see has a hold press and slow tap and tap however every action has a default interaction which basically tells you when these callbacks are getting sent out so if we go with the default one which is you're pressing down on the key or you're pressing down on the gamepad button then that interaction has several stages so in the started stage this just means that the interaction has been started so it has received some sort of input but it's not complete then performed is the interaction is complete so we give an example maybe we do the hold interaction if we press down it starts the interaction however it will not complete until it's held down for a specific period of time that you are specifying and then there's cancelled which means the interaction was interrupted or aborted so for example if you lift your finger before the hold is completed meaning you lift it before the specific time that you set then it is cancelled and then there's waiting which it just means that the interaction is waiting for input that it's just on standby and it's actually pretty complicated because depending on your action type it influences when these event callbacks are called and so this is going to be the important part for your use case you're going to want to choose the action type that best match your use case and when you want these actions to be sent out so with value as you saw previously you can choose between a bunch of different control types vector2 button and the big thing about value is that it has this process called disambiguation so let's say you have two controllers connected to your computer and really the game only has one player playing it at all times so you can assume that really only one controller will be the main one that will be held and interacted with and so in this case value would be a perfect choice because there's only going to be one main device but it also gives you the option to switch to the other controller so if this one suddenly isn't working as well the player can switch to the other controller and that one will become the main device so the disambiguation process basically determines which controller or which control device is the main one so you want to use this one if you have different controls for an action but you only want to take input from one at a time and so how does it determine which one is the main one well here's where the callbacks come into play so let's say i'm on my controller and i'm moving my joystick if i'm not moving my joystick it's just waiting for input however the moment i start moving the joystick away from the center or its default value then it automatically starts the event so it started now with value however not only does it start the event but it also performs the event the input changes so every time the joystick is moved to a different location the action is performed so the first time when you move the joystick it starts the action and it also performs the action and it sends out those two callback events and once you're done with the joystick and you lift your finger and it moves back to the center it moves back to the default value that's when the action is cancelled so this is a super important differentiation between value and pass-through is that value performs disambiguation while pass-through does not pass-through will get any input from any controller and will not do any processing on it and i'll continue explaining that a little bit later one more thing i want to mention is that value does an initial state check value is the only action type that does this neither button nor pass through actions do this let's say an action is disabled it's not reading input from anything and you have it disabled so that even if you press the button it shouldn't do anything now when you enable it what value does is it checks the control and if the control is actuated which basically just means it's not at the default value or in the case of the joystick it's not in the center then the action will immediately be started or performed so even if the joystick is not in the center and the action is enabled it will still send out that perform callback and so the difference is that button and pastor do not have this and if the joystick is not in the center per se for pass-through at least since pass-through is the only other one that you can use with a joystick then you'll have to move the joystick in order for the pass-through to read the value however value will send out that callback once it's enabled if it's in its non-default position and for button for example you'll have to lift your finger from the button and press it down again if you want it to be performed alright so now i'm going to explain button and for button you'll just want to use this for anything that only has one value because it returns a float 0 or 1. you won't want to use this for anything that's vector 2 or vector 3. it doesn't perform an initial state check like i just mentioned as value does and you want to use this for inputs that trigger an action once when they are pressed you'll only want to have that performed action once it's pressed you don't want the button to be performed every time you have your finger down and what's interesting is that you can specify a press threshold so if you add an extra interaction here let's say you add a press interaction you can add a threshold that basically determines once the user has pressed point five of the way so fifty percent of the way then it will be performed so the user has started pressing the button and it's not yet at point five it will send out the started callback for the button but it will only send out a performed callback once it reaches the threshold and it will only send that performed callback once and not constantly like value does and going back to the initial state check you really wouldn't want to have this check because this happens when an action is enabled and if an action is enabled and you have the button being pressed down if it does have the initial state check it'll perform that button but usually with buttons you'll want the user to lift their finger and press it down again because that button might have been held down from a previous press before that action was enabled all right and now for the last one which is passed through the main difference between pass-through and value they're very similar except that pastor does not use disambiguation and it doesn't have a main controls so let's say the user has two controllers and they just happen to be using both controllers at the same time moving the same joystick then pass-through action type would send out two different events one for the first joystick and one for the second joystick whereas value would only send out one event on that frame it would just determine which one has the greatest magnitude and deem that as the main control so pass-through is much simpler it doesn't have as much processing to it and you'd use this if you want to process all inputs from a set of controls now the interesting thing is a pass-through action will not send out started or cancelled events it will always send out performed events when the joystick value is moved if you do want to have that started and cancelled callback with passthrough then you'll have to add in an interaction only then when you add an interaction with pass through you can get those extra callbacks because it makes it more clear to unity that okay i have a hold interaction so when i start to press down that will start the interaction and when i lift my finger it will cancel the interaction otherwise unity will just report any change in value as performed and of course passthrough does not have the initial state check as value does as i mentioned so in most cases you'll probably want to be using value if you have one player however if you don't want unity to do the processing behind the action and you just want to get all of the information directly inputted to the controller or the device that's accepting input then you can use the passthrough one however i've mostly used value in my previous videos i've used passthrough and that was because i was not aware that the pastor does not automatically send out the started and canceled callbacks but if you are having an issue with your input try changing it from pass through to value or value to pass through sometimes it actually fixes the input issues that you may be having so yeah i hope you found this video useful it took quite some digging to get through the documentation for unity to find this information so if you appreciate it be sure to like and subscribe there's more information on interactions that i haven't gone over but i feel like that should have its own dedicated video so with that i want to thank all of my patrons for the support it helps make these videos possible and we actually smashed one of the patreon goals the other day and patrons selected my next video which will be a third person character controller for shooter so i'll be making a character controller that can aim and shoot with cinemachine and i'll also be using animations to animate the character but i might split the video up just because it might be too much to cover in one video so i want to thank all my new patrons in the supporter tier we have thank you so much in the enthusiastic tier we have rodrigo drunk fly and andrew thank you so much for the support and in the dedicated tier we have rayleigh 47 stephen cooper and stefan thank you so much for your support i really appreciate it and if you're interested the link is in the description i offer source code early access to videos and an exclusive discord channel and if you haven't already joined be sure to join our discord channel where you can chat post memes or ask any questions so thanks so much for watching and see you next time you
Info
Channel: samyam
Views: 6,540
Rating: undefined out of 5
Keywords: passthrough, value, button, disambiguation, intial state check, new input system, unity input system, unity new input system, input system unity, action types, action types explained, input system actions, input system action types, value vs passthrough, value and passthrough, value action type, passthrough action type, button action type, action type, input system passthrough, input system value, input system button, new input system tutorial, input system tutorial, how to
Id: DMUZfVSYJfs
Channel Id: undefined
Length: 12min 30sec (750 seconds)
Published: Thu May 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.