Skip to content

Few questions about Unity's new Input System

Hi all! I'm working on a 2D platformer game and have a character that is able to do most basic moves, but I'm not really happy with my code. I recently found out about Unity's new Input System, so I followed their documentation and got it all set up. And then…. ran into a few questions. Some are flat out questions and some are me fishing for recommendations. So I'll list them out and if any one can answer all or some, I'd greatly appreciate it! Thanks!

  1. The unity docs say to use a PlayerInput component on your player character. This references the Input Action Asset, and allows you to set up a few specific settings yourself. However, all the tutorials I've found do not use this component. Is that because maybe it's fairly new? Or is it better for some reason to not use it?
  2. If I do use the PlayerInput component, should I utilize Unity Events or C# Events? Are there pro's and cons to each? Imo Unity Events seems easier to set up, but are there any draw backs, any limitations?
  3. With the InputActionAsset, is there a way to set up button combinations? Say I want a special attack to be triggered when both L1 and R1 are clicked simultaneously, can that be done with the InputActionAsset, or is it limited to one button inputs?
  4. Lastly, should I even be bothering to use the new Input System? My entire reason for it was because my player controller was essentially one large Update function, checking for multiple button presses and doing the actions accordingly. I looked for other ways of doing it that was a little more broken up and manageable as I start adding in more complex move sets, but everything kind of looked like a mess. I thought this may be better as we are able to break each action into a function and instead of checking every action every update, we only handle the ones that we are invoking with the event. However, I'm not extremely knowledgeable about events. Are there any downsides to this?

I know this is a lot of questions so I greatly appreciate anyone who is willing to take the time to answer or discuss the pros and cons and all that with me! Thanks much everyone!

2 points3 comments
Open on Reddit
About this post
Posted
Archived
Score
2 · 100% up
Kind
Text
ID
jsf1y3

Author

41
posts
37
comments
7
media
View profile

3 comments

Had heard of it before, but never got into it. Due to your question I took a look at https://docs.unity3d.com/Packages/com.unity.inputsystem@0.9/manual/Components.html and it looks very good. I think I will move my stuff over, this really simplifies input systems (if you want to do more than walk/jump for 1 not changing char).

Going from your post I think you will find the old system more intuitive to follow what is happening in code.

What you could do then is separate things into an input class that checks in an update loop for the button combinations and then fires a unity event. And then you could hook up your player code to it in another class. (This setup somewhat looks like that new input system but with less stuff and magic attached to it.)

Answers to your questions

  1. The Input Action Asset is needed to define the actions. Like walk, run, jump, move. Or 'special uppercut XXL edition' or whatever you want. And like this (https://www.youtube.com/watch?v=mvuXOyKz7k4) guy says you don't want that thing directly on a player but you could do that to keep things easy.
  2. C# events are better, more direct. However you can't wire these up in the editor. If you want to drag n drop your game together use unity events.
  3. Good question
  4. I think you could benefit from it. You would learn something valuable this way ;-)
1 points

For you're reply on question 1, this is how I'm seeing everyone online do it. What I'm talking about is the Player Input Component, that you add directly to your player game object. Unity docs show using that and when you do it will automatically generate a Input Action Asset with many of the basic controls already wired up. The Player Input component is what invokes the events. Which is why I'm confused as to why nobody else is using it. I would assume events would be better than a super long update function checking every single input to see if it was pressed, right?

1 points

The player input handles more than just the input. It act as an intermediate system to get the actions to your own code through events/messages. And it does more stuff that could be useful, like the camera and multi player input (as in: more players at the same system)

And on that most tutorials aren't that good in code quality: yeah that is a thing apparently.

2 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.