Skip to content

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

  1. Open the Default map in Motion > Maps under MotionCore Content.
  2. Press Play.
  3. Move with WASD, jump with Space, sprint with Shift, and crouch with Ctrl.
  4. Stop Play mode.
  5. Open B_MotionCharacter in Motion > 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.

  1. Open the Content Drawer.
  2. In your project content, create a folder named MotionTutorial/Input.
  3. In that folder, create an Input Action.
  4. Name it IA_Interact.
  5. Open IA_Interact.
  6. Set Value Type to Boolean.
  7. 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.

  1. Enable plugin content if it is hidden: Settings > Show Plugin Content.
  2. Open IMC_Motion_KBM in Plugins > MotionCore Content > Motion > Blueprints > Input.
  3. Add a new mapping row.
  4. Set the row's action to your project IA_Interact.
  5. Set the key to E.
  6. Leave triggers and modifiers empty.
  7. 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.

  1. Return to B_MotionCharacter.
  2. Open the Event Graph.
  3. Right-click in the graph and search for IA_Interact.
  4. Add the Enhanced Input action event for IA_Interact.
  5. Use the Started execution pin.
  6. Add a Print String node.
  7. Set the string to Interact pressed from B_MotionCharacter.
  8. Connect Started to Print String.
  9. 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

  1. Press Play.
  2. Press E.
  3. Confirm the on-screen message appears once when the key is pressed.
  4. Move, jump, sprint, and crouch once more.
  5. 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

  1. Open B_MotionCharacter.
  2. Remove or disconnect the IA_Interact event you added earlier, so the test result comes from only one path.
  3. Add MotionInteractComponent to the character.
  4. Select MotionInteractComponent.
  5. Set InteractAction to IA_Interact.
  6. 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

  1. Press Play.
  2. Press E.
  3. Confirm the component message appears.
  4. Press Shift, Ctrl, and Space to confirm the existing Motion input still works.
  5. 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:

  1. Create or modify an Enhanced Input action.
  2. Add the action to an input mapping context.
  3. Keep the mapping context assigned to the local player.
  4. Consume the action directly in the character when the behavior is local to that character.
  5. Consume the action in a custom Motion component when the behavior should be reusable.
  6. Verify the new action without breaking the existing Motion actions.

Where to go next

Motion - Advanced First Person Character Controller