Where to process an Input Action

Hi!

Where do I have to process an Input Action? In a Player Controller or in a character class?

Thanks!

If you only ever let the player play a single character class (e g, don’t move between vehicles, different kinds/types of player character, etc) and you don’t do networking, it’s usually easiest to do the decoding, processing, and implementation of player input in the player character.

However, if you do networked gaming, or have a character select option, or move between different controlled objects, or the player turns into a ghost, it may be better to move the input decoding into the player controller, because this is a more flexible and robust architecture.

In general – “decoding the player’s intent” should be in the player controller, and “implementing the decoded intent” should be in the character / pawn. In addition, even if many different pawn classes implement the same intent – “swing sword” – you might actually have different character classes for this, because you have different procedural flair to illustrate/animate those different actions. Character-based games like MOBAs do a lot of this. It might be useful to download a few of the Paragon characters to see that in action, although the “gameplay” half of that has been stripped out.

4 Likes

Thanks!

What do you mean with “decoding the player’s intent” and “implementing the decoded intent”?

Thanks.

“Decoding the players intent” means something like figure out whether the player wants to “attack” (in some RPG) or “perform an uppercut punch” (in some fighter game) or “fire the grenade launcher” (in an FPS.)
This is “the action” that the user binds to “a button” (or a button combination.)

The character/pawn knows nothing about buttons (or keys, or joysticks) but it does know about actions. It will typically have action-specific events/methods like Attack() or UppercutPunch() or FireGrenade(). The role of the PlayerController is to translate Press Button B into call FireGrenade()

You can see this in the existing Character class (which is a subclass of Pawn,) which has functions for things like Jump()

The implementation of the character knows what a particular character needs to do to make an uppercut punch or attack. This may play different animations, play different sound effects, deal different amounts of damage, etc, depending on the particular selected character. (a bigger character may have longer reach, a different weapon may be equipped, etc.)

2 Likes

Thanks!

I have understood everything, but now, I don’t know how to use it with enhanced input.

I say that because I have these input actions and input default:

imagen

But, I don’t know how to decode the intentions in a Player Controller. I think the intention is already defined on these Input Actions.

About the implementation, if I’m not wrong, I have to do it in the character’s class like this:

You can do the same thing in a player controller instead:

It’s the exact same thing. Just remove it from your pawn class, and add it to your player controller class instead.

Alternatively, you can save yourself a lot of headache and make your code extremely modular by investing in the GASCompanion.

After, reparenting my character blueprint, I was able to create a GameFeature plugin, and this is all that it took to make it jump. Just a couple of extra nodes, but now you can reuse that for your player in any game. You can also use Mapping to assign the key and also reuse the ability to grant and execute the ability on an NPC as well.

I created a Movement Game Feature that handles all movement, jumping, sprinting, crouching. Next I’m going to add a second and third mapping that handles 2D side scrolling and top down views. Then use the Gameplay Tags to grant the right abilities to the right characters.

Screenshot 2023-07-25 at 4.49.27 AM

Thanks but, how can I decode the intentions in a Player Controller using Input Actions?

I … don’t understand the question.

Simple case:
If there’s an Input Action named “IA_Jump,” and that Input Action triggers, that means you’ve now decoded the player wanting to jump. You can forward this to a Character by calling the character’s Jump() function.

This starts getting more interesting where you have chords and combinations, where you’ll need state in your player controller to figure out in what sequence input controls are being actuated, and at the determining point, call the appropriate function on the character.

OK. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.