How can I set up multiple functions for a specific keybind depending on the situation?

Hey guys i have a little problem and i feel stupid about it. I hope someone have a better solution than mine

I work on a Historical / Simulation / Survivor game and i am stuck with the input.

Normally we set up InputComponent on a controller, pawn or character pair with the .ini to handle the key stroke and call functions but when it’s active it’s done we cannot do anything except redefine an another InputComponent to put it on top of the stack.

But imagine the situation where i would desable some key or change the purpose of a certain key depend on the situation or the state of game ie Leftclick for pick up object on normal mode and shoot or use the current equipment during combat mode.

I could probably go around and use raw data input but it could be cool if there is a better solution.

Thanks to help me

I can details more if needed. Just says it

I’m not quite sure if i understand it right but are you asking in a general way how to implement such a feature or if your implementation doesn’t work…
As a general software architecture answer: i would build a inputManager…

You build an inputManager based on a config file for your players input for example

jump      =     "space"
crouch   =    "shift"

The Manager has for each key you might use a Keyinput-Listener which Translates key inputs into “User Requests”

additionally to that you need a player StateMachine…

here is a simple one:

when Your Player is in the standing mode you can press jump or crouch and both actions will be executed…
while you are jumping however any User Request will be ignored…
and if you are crouching and request jump you get into ultra-jump mode…

so… i’m still not sure if i understood you wright and you are looking for basic concepts or how to implement them in code or if your code didn’t work and you don’t know why…

Ok first of all thank for answer.

Let me details more my problem I want to be able to swich the fonction of a key or turn off a key depend on the state of the player or the state of the game. For example if i’m near a plant or a tree Leftclick allow me to pickup object such ingredients and when i’m near a npc leftclick allow me to talk to him. In combat leftclick allow me to use the current equipment.

Your idea of input manager is great and i did one on a past game with unreal engine 3 but in that case i use just the raw input data to control specific input during specific state and i didn’t use .ini file at all.

i’m stuck with unreal engine 4 in the concept where I need to setup the input for a controller or pawn and when it’s set i cannot unbind a key or bind a new functions. For this game i would to use the architecture correctly but the setup input block me and i don’t how to use it or if need to use it at all.

I don’t know if you can understand better. If not just says it.

Thanks for help

Well as far as i am concerned it is still the correct way…
for what you are describing i would use a state-dependent Strategy-Pattern…

here is a link to the Strategy Design Pattern of the Gang of Four

if you don’t know the book “Design Patterns: Elements of Reusable Object-Oriented Software” yet, i highly recommend you read it before you go too deep into design decisions… It’s like the bible of software architecture and computer games tend to have very complex architectures…

anyway i don’t think you can leave the StateMachine-approach behind…
I would design it with several global Player states like

  • “is in Fighting mode”
  • “is in Trading Mode”
  • “is in Free Walking mode”

and depending of your global state i would implement different strategies for UserActionRequest:Main

and the UserActionRequests-Events would be invoked by your InputManager which maps the KeyboardEvents to UserActionRequest-Events…

Or do you want to know how to write a parser for your config file and how to map the keyboard events to your game events depending on the config file?

I totally agree with you with about this concept, the problem is unreal engine 4 architecture we must “enable” input for a player controller and the input process pass trough with the ini file to check the mapping. I don’t how to make it versatile cause of the ini and the setup. I need to find a way to listing to specific stuff at specific time (Bind and Unbind or enable input disable input) . The problem is not the classic c++ architecture it’s more work with the input system of unreal engine 4 and the mappings and ini file. I don’t how to do this.

Thanks for help

like you asked for it…
link text

Now i know is possible and i will find the way to do this properly

Thanks !

Hey there,
I think I kinda got what you’re saying. Basically, you want to be able to activate and deactivate KeyEvents (key pressed), right?

If so I found two ways:

  1. Use Actor Blueprints within your Area and add an “enable input” e.G. if you overlap with a volume. Also make sure to disable the input if you leave the area (endoverlap or so). Then below simply add your key and what it should trigger.
  2. Simply create a float variable in your player Blueprint. Set it up to 0 at first and then plug your keyEvent into a compareInt. Then decide what you want, for instance Value = 0 nothing happens, Value = 1 trigger something. Second step is to set the Value of that variable somewhere, like an actorblueprint that triggers a costum event in the players blueprint and then sets the value to 1 enabling the player to make use of the key-input event.

Hope that’s what you were looking for. :wink: