How can I disable InputAction except some Input Action In Enhanced Input?

I want to create a Notify State that is disable all of Input Action except for a specific Input Action.
I used Enable Input, Disable Input function,
but it is disable all of Input Action…

You aren’t intended to directly remove input actions.
You should be removing the contexts instead.

What you can do is isolate that single input action into a single context, and disable the other contexts.

I may be able to give more specific advice if you explain exactly what this single action is.

3 Likes

oh… For example, I have a character walking to the right.
When this NotifyState is added to the animation of walking to the right, I want to disable all InputActions such as ‘Attack, Jump’ except for ‘W,A,S,D’ Move InputAction.
In other cases, only other InputActions can be activated(ex. only jump inputaction is activated).
I want to pick a specific InputAction that I want to activate.

in MappingContext1 DefaultMappingContext have all of your input actions assigned.
then in MappingContext2 OnlyWalkMappingContext only place the Move_InputAction

then in your trigger call a function that calls Remove Mapping Context(DefaultMappingContext) then Add Mapping Context(OnlyWalkMappingContext)
just remember to have some situation where you call a function to do the opposite

you can also make it so that the function to swap over Mapping Contexts takes an Enum then the Enum feeds a switch to then assign the Mapping context based on the Enum.

don’t worry about unassigned a mapping context that isn’t assigned it is safe to do so, but assigning a Mapping Context of none is also safe, just no input at all until it is reassigned (this might be desired)


forgot the part where I assign to the CurrentMappingContext the inMappingContext but that should be trivial for the demonstration.

if you really must disable input actions, then you could just use booleans/Enum/Bitmask to “fake” disabling the input actions:
depending on the complexity of the check this can have performance hit on the extreme

in your Input Action Events check against your desired approach and if it would not be “valid” in that instance then you can just have the InputAction do nothing but the check.

thank you for your kind reply :grinning:
But…
then, if I don’t use bool/enum/bitmask, does that mean I have to create all Input Mapping Contexts that fit all of each situation?
For example, when there is a situation where only walking is activated, and a situation where only walking and attack keys are activated,
you says, two separate Input Mapping Contexts are needed?

the method for using separate Input Mapping Contexts
-higher overhead on the swap
-you would need separate Input Mapping Contexts for each situation (in a 1-to-1 way)
-concentrated spaghetti.
the method for bools/Enum/bitmask:
-minimal overhead on the swaps
-floating variables that have to live somewhere
-potential spaghetti in each InputAction event
-having some consistent way to go to the proper state maybe creating logical issues.

pick the one you would be more comfortable with the drawbacks.
also keep in mind for the average controller we can expect a player to have (if controller is to be required) that is typically 2 joysticks + 16 buttons (including stick clicks).
for Keyboard supposedly 65% keyboards are getting traction (no 10-key, arrow keys, and maybe no readily accessible number keys)

2 Likes