Appearance
Tutorial: create and use a Motion input
This tutorial shows the complete Motion input path: create an Enhanced Input action, add it to the Motion keyboard mapping context, then consume it in Play mode.
By the end, pressing E will trigger a new IA_Interact action. You will first consume it in B_MotionCharacter, then move the same input into a small custom Motion component.
Use this tutorial after you can open the Motion demo project and run the default map. If you have not done that yet, start with Quick start.
Start from the working character
- Open the
Defaultmap inMotion > MapsunderMotionCore Content. - Press Play.
- Move with
WASD, jump withSpace, sprint withShift, and crouch withCtrl. - Stop Play mode.
- Open
B_MotionCharacterinMotion > Blueprints.
You are starting from a character that already adds the Motion input mapping context and already consumes Motion input. That gives the new action a known working path.
Create an input action
For this lesson, create a project-owned digital interact action.
- Open the Content Drawer.
- In your project content, create a folder named
MotionTutorial/Input. - In that folder, create an
Input Action. - Name it
IA_Interact. - Open
IA_Interact. - Set
Value TypetoBoolean. - Save the asset.
If you are modifying an existing input instead, open that input action and keep the value type that the consuming code expects. Sprint, crouch, jump, and interact-style actions should stay Boolean. If you only want to change which key triggers an existing action, change the row in the mapping context instead of creating a new input action.
Add the action to the keyboard IMC
Now add the action to the input mapping context that the demo character already uses.
- Enable plugin content if it is hidden:
Settings > Show Plugin Content. - Open
IMC_Motion_KBMinPlugins > MotionCore Content > Motion > Blueprints > Input. - Add a new mapping row.
- Set the row's action to your project
IA_Interact. - Set the key to
E. - Leave triggers and modifiers empty.
- Save
IMC_Motion_KBM.
For a project outside this demo, duplicate Motion's mapping context into your project content before editing it, then assign your duplicated context to the character or controller that adds mapping contexts for the local player.
Consume the input in the character Blueprint
Use this first path when the action is project-specific and belongs directly to your character or controller.
- Return to
B_MotionCharacter. - Open the Event Graph.
- Right-click in the graph and search for
IA_Interact. - Add the Enhanced Input action event for
IA_Interact. - Use the
Startedexecution pin. - Add a
Print Stringnode. - Set the string to
Interact pressed from B_MotionCharacter. - Connect
StartedtoPrint String. - Compile and save
B_MotionCharacter.
Use Started for one-shot actions such as interact, fire, inspect, or reload. Triggered can fire repeatedly while an action remains active.
Verify the Blueprint path
- Press Play.
- Press
E. - Confirm the on-screen message appears once when the key is pressed.
- Move, jump, sprint, and crouch once more.
- Stop Play mode.
The important check is not only that E works. The existing Motion inputs should still work because the new action was added beside them in the same mapping context.
Move the input into a custom Motion component
Use this path when the behavior should travel as a reusable component instead of living in one character graph.
Create a C++ component named MotionInteractComponent that inherits from UMotionComponentBase.
cpp
// MotionInteractComponent.h
#pragma once
#include "CoreMinimal.h"
#include "MotionCore/Components/MotionComponentBase.h"
#include "MotionInteractComponent.generated.h"
class UInputAction;
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMotionInteractInputEvent);
UCLASS(Blueprintable, ClassGroup=(Motion), meta=(BlueprintSpawnableComponent))
class YOURGAME_API UMotionInteractComponent : public UMotionComponentBase
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Motion|Input")
TObjectPtr<UInputAction> InteractAction = nullptr;
UPROPERTY(BlueprintAssignable, Category = "Motion|Input")
FMotionInteractInputEvent OnInteractPressed;
UFUNCTION(BlueprintCallable, Category = "Motion|Input")
bool BindInteractInput();
protected:
virtual void BeginPlay() override;
virtual void OnInputStarted(const FInputActionValue& Value) override;
};cpp
// MotionInteractComponent.cpp
#include "MotionInteractComponent.h"
#include "Engine/Engine.h"
#include "GameFramework/Character.h"
#include "InputAction.h"
void UMotionInteractComponent::BeginPlay()
{
Super::BeginPlay();
if (CachedCharacter && CachedCharacter->IsLocallyControlled())
{
BindInteractInput();
}
}
bool UMotionInteractComponent::BindInteractInput()
{
return InteractAction ? BindInputAction(InteractAction) : false;
}
void UMotionInteractComponent::OnInputStarted(const FInputActionValue& Value)
{
Super::OnInputStarted(Value);
OnInteractPressed.Broadcast();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(
-1,
2.0f,
FColor::Green,
TEXT("Interact pressed from MotionInteractComponent"));
}
}If this component lives in your game module, add MotionCore and EnhancedInput to that module's dependencies, then compile.
csharp
PublicDependencyModuleNames.AddRange(new string[]
{
"MotionCore",
"EnhancedInput"
});Use the custom component
- Open
B_MotionCharacter. - Remove or disconnect the
IA_Interactevent you added earlier, so the test result comes from only one path. - Add
MotionInteractComponentto the character. - Select
MotionInteractComponent. - Set
InteractActiontoIA_Interact. - Compile and save
B_MotionCharacter.
The component calls BindInputAction() from UMotionComponentBase. Motion handles the Enhanced Input binding and retries the bind if the input component is not ready on the first attempt.
Verify the component path
- Press Play.
- Press
E. - Confirm the component message appears.
- Press
Shift,Ctrl, andSpaceto confirm the existing Motion input still works. - Stop Play mode.
You now have the same input action flowing through a reusable Motion component.
What you practiced
You practiced the full input path Motion expects:
- Create or modify an Enhanced Input action.
- Add the action to an input mapping context.
- Keep the mapping context assigned to the local player.
- Consume the action directly in the character when the behavior is local to that character.
- Consume the action in a custom Motion component when the behavior should be reusable.
- Verify the new action without breaking the existing Motion actions.