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):
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.
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:
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.
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.