inhanced input - how to change input mapping context priority

Hello! I’m learning the inhanced input now, in documentation written: “…Mapping Contexts can be dynamically added, removed, or prioritized…”. But I can’t understand how. All I want is to create Input Action to switch between interact and battle mods, as I understood: I need 2 mapping context (for interact mode and battle) and change the priority for this contexts, but i don’t know how. Could you please help.
I already tried to do it like this
(checking the the value of variable bBattle? and setting the context):


or like this
(Swaping the values of contexts priority):

But its not working.=(
Please Help!

3 Likes

For this application, you’ll need to remove and add back the contexts.
If you’re in build mode, build mode contexts should be added and battle mode contexts should be removed- and vise versa.

Priority just decides which is executed first (If the input is consumed, it’ll decide which gets to go at all).
So say your build mode has the ‘R’ key bound to rotate and your battle mode has it bound to reload- priority decides whether you rotate then reload or reload then rotate.

5 Likes

@rokenrock Thank You for your answer! But, sorry, I still can’t understand how.(
I tried to do it this way:


But it’s still not working. Looks like i doing something wrong. Could You please show me an examle how should I do this.

2 Likes

You forgot to flip the BattleMode value. (Also maybe consider using an enum if you intend to have more than just build/battle- it’s fine as it is now though).

Also- make sure that you actually push the battlemode value whenever you first spawn.
Not this exactly, but something to the same effect. Just apply- don’t flip the value:

Other than that, it looks great.

3 Likes

@rokenrock Thank You very much! It works! As usual missed the simplest thing xD
Also Thank You for enum idea! Have a nice day!)

1 Like

Hi @danilbo991 I’m trying to change the Input mapping context when I possess another character and I can’t figure it how. Can you share the blueprint modified that works to you?

Hey there @IArriagada , here’s how I am doing it with possession: You need to make sure the IA is being used on both IMC. LMK if you have any questions.

1 Like

So to be clear: there’s no way, out of the box at least, to change the priority of the Mapping Contexts added to the EnhancedInputSubsystem.

Browsing the code I see that these contexts are added to a TMap called AppliedInputContexts. This structure stores the contexts and its priority. This is a private member so I think that if you want to change the priority of the already added contexts instead of adding/removing you should do something like this:

  • Expose the AppliedInputContexts TMap in order to make it accessible and editable outside the EnhancedInputSubsystem (bad idea imo).
  • Implement the logic to update the value (=priority) o these TMap items. Working with TMaps doesn’t look complicated, example link.
  • After updating the priority of the contexts I think that you should make a call to RebuildControlMappings().

It seems that this priority mechanism was added to avoid conflicts between existing contexts more than to allow swapping between contexts. I mean, looks like the idea is to add various input contexts and have them working simultaneously, using the priority attribute only when the same input is defnied in more than one. If you want to perform a real change of input context you need to remove and add.

6 Likes

Thank you for your time, it was very interesting and helpful to learn!