Modular Game Features plugin. How to detect input in the component that will be attached to actor?

I’ve created a game feature blueprint. I’ve set a target pawn and which pawn component to add to this pawn.

In the game feature component I’ve added a print node that fires on begin play. It works, the text is printed to log so the system works.

But now I want to add some code to this component and I want that code to start when I click the mouse left button. Or the space key.

But those inputs don’t seem to work when they are inside this component blueprint

This component is attached to the pawn that the user controls and the inputs there work. In theory the pawn receives the input, the attached components should receive them also?

I don’t know how to approach this. Can someone help? Thank You.

As a general rule of thumb, the fewer blueprints that handle player input, the better. Exceptions surely exist but this does not sound like one.

Any reason why the Pawn cannot simply fire the appropriate event / function / logic in the component it owns?

If the components are added dynamically during gameplay and we do not know upfront what will be added, you could use event dispatcher.

In short: handle the input in the pawn who tells the components what to do.


You might be up to something more elaborate, ofc; if, for some reason, the above wouldn’t work, do tell.

If I understood correctly this whole Modular Game Feature idea is to separate code in independent pieces so they can be added and removed with a click and without worrying about breaking something.

I have no idea how to use the input with this type of setup.

If i want to add a piece of code that allows the player to drag something in the scene when clicking with the mouse. So left mouse drags some object. So it needs to know about left click. works if the code is in the player character/pawn

What I need is for this code to be inside the game feature plugin. So it doesn’t react to the input. :face_with_monocle:

Obviously the input needs to be in some place where it doesn’t become a mess. So putting the left mouse button node there may be wrong. but then how to do it?

You put the input in the Pawn and add an interface - if you have many types of comps.

The components implement the interface and decide what that input means to them.

From the Pawn’s point of view, you press Left Mouse and tell the component to Action it.

Each component has a different implementation of said action.

If in doubt, share more details. Are those components spells? Maybe they’re bags of loot, perhaps they’re rocket thrusters or extra appendages of Pawn?

1 Like

For anyone that finds this and you’re using Lyra, here is a great tutorial to setup inputs for a GameFeature plugin

1 Like

thank man, this is really helpful

Can you mark it as resolved, or do you still have issues with the input? Maybe it can help someone else.

I did not had time to verify this because I had no idea how to work with that setup at the time, I don’t have the project set in that way right now, but I’ve marked the answer as the solution because it appears it does what I was asking for.

1 Like