EnhancedInput Mapping problem

Hello my friends!

I’m trying to make Enhanced Input with C++ - so far I made it all working with one small problem… The keys that I’m binding and mapping are not working well. One key is making few actions at once.
In my case i was making CameraMovement WSAD, CameraZoom MouseScroll, and CameraRotate QE.
AD buttons are working good, but WSQE are making both actions at the same time (Rotate and Zoom at the same time) - while MouseScrollAxis doesn’t work at all. Did I messed up mapping?

I’m using this tutorial:

It’s great, but it does not fully explain the mapping multiple actions. How do I correct it?

			if (!InputMapping.IsNull())
			{
				InputSystem->AddMappingContext(InputMapping.LoadSynchronous(), 0);

				UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>(InputComponent);
				
				const FEnhancedActionKeyMapping Mapping = InputMapping->GetMapping(0);
				
				Input->BindAction(Mapping.Action, ETriggerEvent::Triggered, this, &ATacticaPlayerController::CameraMoveCallback);
				Input->BindAction(Mapping.Action, ETriggerEvent::Triggered, this, &ATacticaPlayerController::CameraRotationCallback);
				Input->BindAction(Mapping.Action, ETriggerEvent::Triggered, this, &ATacticaPlayerController::CameraZoomCallback);
			}

Best regards!

That is a rather messy way of setting up inputs. Just make a c++ version of the third person template to see how to properly setup mapping. It has both camera controls and movement logic to show proper axis setup and boolean inputs too like jumping.

It should be via exposed input actions that are assigned to specific functions.

In your example you are assigning the same internal input action to all of the functions which is not logical.

True, but I’m using InputAction and InputMappingContext as C++ Class not Blueprints, so it’s a bit different.

In the link I showed there is sentence: " One important thing to note is I am getting the Action that is stored in the input mapping via InputMapping->GetMapping(0) . If you simply create another Action of the same type and try to feed that into BindAction , it won’t work. It has to be the action stored in the mapping itself. We only had to get the first one because all our mappings reference the same action." - Which I don’t fully understand, but it’s a tip how to manage this problem.

Please read my reply carefully and with understanding.

I did not mention blueprints. I suggested you create a third person project as c++. No need to reinvent the wheel every time you need inputs when there is a perfectly fine example made by epic games

Yeah, I understand, maybe i wrote it wrong, but you can make everything in UE as C++ or Blueprint/Asset (I thought that IA, IMC, Widgets are still blueprints…), there is tons of tutorials on Youtube where you create InputActions and InputMappingContext via Asset creation in Unreal Engine and then you implement logic in C++ in PlayerController/Character in IDE.

I wanted to try implement everything with C++, but I couldn’t find much information about this, guess I will stop forcing it :stuck_out_tongue:

By using a 100% pure c++ you are locking yourself out of the possibility of remapping inputs (at least with the implementation you were following).

You would still need specific separate input actions ( TObjectPtr) for each action instead of passing in a single input.

Okay, I thought that the Turorial I shared was a good start, but I gues it’s not worth it to force it. So I will do like everyone else → IA IMC as Assets, and rest in C++ in PlayerController class :slight_smile: