InputMappingContext

I’m writing the code to make the character move. I’m implementing the move with InputMappingContext.

But the problem is that after I wrote the code, I built it

Global options:
-Help : Display this help.
-Verbose : Increase output verbosity
-VeryVerbose : Increase output verbosity more
-Log : Specify a log file location instead of the default Engine/Programs/UnrealBuildTool/Log.txt
-TraceWrites : Trace writes requested to the specified file
-Timestamps : Include timestamps in the log
-FromMsBuild : Format messages for msbuild
-SuppressSDKWarnings : Missing SDKs error verbosity level will be reduced from warning to log
-Progress : Write progress messages in a format that can be parsed by other programs
-NoMutex : Allow more than one instance of the program to run at once
-WaitMutex : Wait for another instance to finish and then start, rather than aborting immediately
-RemoteIni : Remote tool ini directory
-Mode= : Select tool mode. One of the following (default tool mode is “Build”):
AggregateClangTimingInfo, AggregateParsedTimingInfo, Analyze, ApplePostBuildSync, Build,
ClRepro, Clean, Deploy, Execute, FixIncludePaths, GenerateClangDatabase, GenerateProjectFiles,
IOSPostBuildSync, IWYU, InlineGeneratedCpps, JsonExport, PVSGather, ParseMsvcTimingInfo,
PrintBuildGraphInfo, ProfileUnitySizes, Query, QueryTargets, Server, SetupPlatforms,
Test, UnrealHeaderTool, ValidatePlatforms, WriteDocumentation, WriteMetadata
-Clean : Clean build products. Equivalent to -Mode=Clean
-ProjectFiles : Generate project files based on IDE preference. Equivalent to -Mode=GenerateProjectFiles
-ProjectFileFormat= : Generate project files in specified format. May be used multiple times.
-Makefile : Generate Linux Makefile
-CMakefile : Generate project files for CMake
-QMakefile : Generate project files for QMake
-KDevelopfile : Generate project files for KDevelop
-CodeliteFiles : Generate project files for Codelite
-XCodeProjectFiles : Generate project files for XCode
-EddieProjectFiles : Generate project files for Eddie
-VSCode : Generate project files for Visual Studio Code
-VSMac : Generate project files for Visual Studio Mac
-CLion : Generate project files for CLion
-Rider : Generate project files for Rider

D:\UE_5.3\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.exe (process 7688) exited with code 1 (0x1).
Press any key to close this window . . .

This is what happens. Other projects don’t get this error. But the projects I create get this error. What’s the problem? :cold_sweat:

Did you add the EnhancedInput into the .cs file that has the list of modules?

I added it to ProjectName.Build.cs as below.
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" });

And I made a character base that inherited the character, and I made a character player that inherited the character base.
I wrote down the input code in Character Player. The code below is Character Player cpp code.

#include "InputMappingContext.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"

ALuckyCharacterPlayer::ALuckyCharacterPlayer()
{
	// Input
	static ConstructorHelpers::FObjectFinder< UInputMappingContext>DefaultInputMappingContextRef(TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/IMC_Default.IMC_Default'"));
	if (DefaultInputMappingContextRef.Object)
	{
		DefaultMappingContext = DefaultInputMappingContextRef.Object;
	}

	static ConstructorHelpers::FObjectFinder< UInputAction>JumpInputActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/Input/IA_Jump.IA_Jump'"));
	if (JumpInputActionRef.Object)
	{
		JumpAction = JumpInputActionRef.Object;
	}

	static ConstructorHelpers::FObjectFinder< UInputAction>MoveInputActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/Input/IA_Move.IA_Move'"));
	if (MoveInputActionRef.Object)
	{
		MoveAction = MoveInputActionRef.Object;
	}

	static ConstructorHelpers::FObjectFinder< UInputAction>LookInputActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/Input/IA_Look.IA_Look'"));
	if (LookInputActionRef.Object)
	{
		LookAction = LookInputActionRef.Object;
	}

}

void ALuckyCharacterPlayer::BeginPlay()
{
	Super::BeginPlay();

	APlayerController* PlayerController = CastChecked<APlayerController>(GetController());
	if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
	{
		Subsystem->AddMappingContext(DefaultMappingContext, 0);
	}
}

// Called to bind functionality to input
void ALuckyCharacterPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent);

	EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
	EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
	EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ALuckyCharacterPlayer::Move);
	EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALuckyCharacterPlayer::Look);
}

void ALuckyCharacterPlayer::Move(const FInputActionValue& Value)
{
	FVector2D MovementVector = Value.Get<FVector2D>();	

	const FRotator Rotation = Controller->GetControlRotation();	
	const FRotator YawRotation(0, Rotation.Yaw, 0);

	// 전방 및 측면 방향 계산
	const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
	const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

	AddMovementInput(ForwardDirection, MovementVector.X);
	AddMovementInput(RightDirection, MovementVector.Y);
}

void ALuckyCharacterPlayer::Look(const FInputActionValue& Value)
{
	FVector2D LookVector = Value.Get<FVector2D>();

	AddControllerYawInput(LookVector.X);
	AddControllerPitchInput(LookVector.Y);

}

This doesn’t look right at all. What you can do and this is better IMO, is add UPROPERTY for each of the things like MappingContext and so on, and then assign them in the blueprint.

As for the paths to the objects you have in your code, they should be simply “/Game/Input/IA_Jump” assiming there is an InputAction called IA_Jump in the input folder of your project.

First of all, I implemented the rotation and movement of the character. I don’t know if I did it right, but it moves and rotates.

Is it because I didn’t make the path to the object simple? There are no errors in live coding, but there are still errors in the questionnaire in the Visual Studio community.

I input it directly through the path, so when I go into the character blue print, there are things like MappingContext assigned. What should I do?

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputMappingContext> DefaultMappingContext;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputAction> JumpAction;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputAction> MoveAction;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputAction> LookAction;

void Move(const FInputActionValue& Value);
void Look(const FInputActionValue& Value);

I wrote it in the header file like this. Is it right to just declare it like this and set it up in the character’s blue print? I think that would be more convenient…

Yes, it is better to do it that way and most examples do it that way.

So is the error now because I used the code as a path to specify mapping context?

Did you happen to change your Unreal Version?

Is this relating to the C++ Course or which course rather?

The Unreal version is using 5.3. I’ve used 5.3 before.

Does this mean what kind of lectures are you taking? Since I’ve never learned InputMappingContext, I searched on Google and wrote the code by reference.

No, I was just wondering which lecture of which course on GameDev.tv you are applying this to so I can try help better.

I don’t know if I understood right
Are you saying that the code I wrote now applies it to which of the lectures on GameDev.tv ?
I’m sorry I didn’t understand, because I understood it through a translator… :disappointed_relieved:

If I understand correctly, it was a code I wrote because I wanted to create a project by myself.
I use the Visual Studio community, but if I build it using Ctrl+Shift+B, there is no error.
But when I do Ctrl+F5, the Unreal editor opens while building. But if I build using Ctrl+F5, I get that error.

I’m sorry. I am actually covering for Dan right now so I can’t really spend too much time helping outside of the courses.

What I see there looks ok but I can’t be 100% sure.

That’s fine, and thank you for your reply.

Privacy & Terms