I realized there seems to be two different ways to use an Input Action Asset in a script.
First is as per the example in this part of the tutorial:
where you attach a Player Input component onto the game object and use that to set up corresponding OnX() methods based on actions in your input action asset (this can be different based on the behavour setting of the Player Input component).
Second way is per this part of the same tutorial:
where you dont need a Player Input component at all and just need to reference the input action asset in the script to do that funky stuff like:
void Awake()
{
controls = new PlayerControls(); // This is the auto generated input action asset class
controls.Player.Buttons.performed += context => SendMessage();
}
Playing around with both methods in my own project and you can achieve the exact same thing with both methods? Are they essentially just doing the same thing, and one is just using the editor more?
Based on the Player Input component documentation it looks like this allows handling of multiplayers so is that the only thing extra?
I just watched this: https://www.youtube.com/watch?v=JLr54sMGlPc and I think maybe I understand it better, but now I think I have more questions about the different Behaviours and when is the best to use which one.
Like for example there are performance differences, and I read somewhere that when you are handling UI inputs you would want to use Player Input component (I can’t remember from where I read it). I think I’m going to stop for tonight as my brain is turning to mush, and I feel like I’ve been reading stuff about this from so many different people with differing opinions and levels of knowledge on it, kinda just thinking to go with the C# event method for now.
There are even more ways to use the Input System. The Workflows page in the documentation goes into three of them with a “Pros and Cons” section for each.
I wouldn’t say there’s a best way to use the Input System and performance will be about the same for all of them. It’s more about how much you want to customize and what fits your coding style best.
PlayerInput is a good point to start for beginners, implementing standard behaviors that work well for most games. For more advanced and complex scenarios, you probably you want to implement this yourself, though.
Personally, I’m not using any of those three outlines approaches and prefer using InputActionReference and some custom tooling to coordinate input. It really depends on your specific situation. But if you’re unsure, PlayerInput is a good point to start and you can always replace it later once you better know your requirements.