INPUT_Action works but ENHENCED_INPUT_ACTION doesn't?

Hi all and thank you for reading my Q

I have taken the following course on udemy to get started with unreal engine

in one of the lectures i need to create a bluprint to make the actor increse walk speed by pressing ‘LEFT SHIFT’

so i needed to create a new
input action

image

imc default and create a new mapping there

image

attqach the nodes on blu print

image

But it does not work at all
*there was no ‘INPUT’ folder in my "third person folder’ so i created a new one and created a new input action for the left shift key

i created a regualer INPUT_ACTION and that seemd to fix it but i dont understand why the enhenced_input_action did not work?

Hi and welcome to the community.
The input actions define the inputs so that would be a boolean input for the equvalent of the old input action mappings. For the Axis Inputs, you can define 1D and 2D so they return either a float or a vector2.

This is an example of something that might define a jump

The various types are here. The 1D ones are like the old Axis mappings

Next, you have to create an input mapping context. This is very similar to the old inputs. They are incredibly powerful. You add an Input Action and then you can add the inputs you want to use. There are then modifiers to alter the inputs (such as deadzone for gamepads or invert)
I’ve pasted examples from 2 different projects. note the first even handles touch input. The second uses something called swizzle which is used for 2D axis to swtich the input to output from X to Y when using keyboard input.


The last part is you need to bind your Input mapping context and this can be done in either C++ or Blueprint.
C++ first This would go either in the PlayerController or Player Character class in BeginPlay. You’d typically add a UPROPERTY to specify the context which was done in this case and then the following binds the context to the player

	auto const Subsystem{
		ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer())
	};
	if (!Subsystem) return;

	Subsystem->AddMappingContext(InputMappingContext, 0);

And the blueprint:

Once you have these - binding events. In a lot of ways, Blueprint is easier so I’ll start there.

Trigger is like sending it continuously which is what you’d typically use for movement (up/down etc) where as started and completed is like pressed and unpressed

For C++, it’s actually similar to the old system albeit parameters are different. Like the context, the various inputs were defined in the headers as UPROPERTY and mapped via a blueprint based on the C++.

void ATopDownCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	const auto EnhancedInputComponent{Cast<UEnhancedInputComponent>(PlayerInputComponent)};
	if (EnhancedInputComponent)
	{
		EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this,
		                                   &ATopDownCharacter::MoveTriggered);
		EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Completed, this,
		                                   &ATopDownCharacter::MoveCompleted);
		EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Canceled, this,
		                                   &ATopDownCharacter::MoveCompleted);

		EnhancedInputComponent->BindAction(ShootAction, ETriggerEvent::Started, this, &ATopDownCharacter::MouseShoot);
		EnhancedInputComponent->BindAction(ShootAction, ETriggerEvent::Triggered, this, &ATopDownCharacter::MouseShoot);

		EnhancedInputComponent->BindAction(StickAimAction, ETriggerEvent::Triggered, this,
		                                   &ATopDownCharacter::StickAimTriggered);

		EnhancedInputComponent->BindAction(GamepadShootAction, ETriggerEvent::Started, this,
		                                   &ATopDownCharacter::GamepadShoot);
		EnhancedInputComponent->BindAction(GamepadShootAction, ETriggerEvent::Triggered, this,
		                                   &ATopDownCharacter::GamepadShoot);
	}
}

The last thing I’ll add is the handlers. All these handlers follow the same signature. They all take an FInputActionValue and this has a Get. The Get then specifies the desired return type so, for a button as example, InputActionValue.Get<bool>(); returns true/false. The example below returns a Vector2d and for this game, a little like a twin-stick shooter the right stick I used to aim.

void ATopDownCharacter::StickAimTriggered(const FInputActionValue& InputActionValue)
{
	if (!CanMove || !IsAlive) return;
	if (!UseGamepad)
	{
		SetMouseShow(false);
		UseGamepad = true;
	}

	auto AimDirection = InputActionValue.Get<FVector2d>().GetSafeNormal();
	AimDirection.Y = -AimDirection.Y;

	const auto RotateTo{
		UKismetMathLibrary::FindLookAtRotation(FVector::ZeroVector, FVector(AimDirection.X, 0.f, AimDirection.Y))
	};
	GunParent->SetRelativeRotation(RotateTo);
}

I know this is a lot of information but this is the basics of the new input. If you want to make things easier for following the older code, use an Axis 1D for up/down and another for left/right. For keys you negate the input for 1 as when pressing a key it always returns a value of 1, so if you used WSAD keys, A for example would need to be negated.

I hope this helps

thank you for the response beegeedee :slight_smile:

If so, how does my bluprint structure ( the one from the course ) is different from the one you suggested?

I suspect you’re missing the step where you set the input mapping context for your player, either controller or the character.

basically here was my flow, accroding to the lecture

re

  1. create a folder in my thirdperson folder
  2. create an IMC
  3. create an IA
  4. map the IA in the IMC
  5. add IA blue print, connect the nods accordingly (as seen in the photos)

Which course again? Action adventure? Can you give the name of the lecture too so I can find it and see where you are.

If you’re starting from scratch, you have to link the mapping context to the player but, if remember anyway, this starts with the third person template so all that should be done and you would be adding the input action to an existing context. Saying that, I’m not familiar at all with this specific course.

@Tuomo_T do you know where the Imc is configured in this course?

Technically the imc is already configured for us because we use the Third Person template, but you would want to go back to lecture 1.9 (Setting Up the Metahuman) where you’ll see we have this important piece copied over from the third person character blueprint.

Next, I’d recommend looking at lecture 2.4 (Making our character walk) which tackles adding another input action for toggling running and walking.

1 Like

That is correct, however, after completing 1.9 lecture and assigning accordingly it still doesn’t work
I created a metahuman, did the retargeting, changed the default pawn class and so forth , just like the class…

However, here is what I noticed, in the regular BP_thirdperson_charecter
I noticed that in the lecture the instructor blueprint contains “addinputmapping”

for some reason, my blueprint did not come with that by default

the problem was,
I had to recreate from the video the ‘addinputmapping’ and then in the ‘add mapping context’ mapping context the IMC ive set before.

Awesome, I’m glad we were able to work out the solution together.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms