Skip to content

Tutorial: create and use a Motion input

This tutorial shows the full Motion input path. You create an Enhanced Input action and add it to a project mapping context. Then, you use the action in Play mode.

At the end, the E key starts a new IA_Interact action. First, you use it in a project character Blueprint. Then, you send it to a small custom Motion component.

Use this tutorial after the Motion character moves in PIE. Otherwise, start with Quick start or Add Motion to a character.

Start from a working character

  1. If plugin content is hidden, select Settings > Show Plugin Content.
  2. Find B_MotionCharacter in Motion > Blueprints.
  3. Duplicate it into Content/MotionTutorial.
  4. Rename the duplicate B_MotionTutorialCharacter.
  5. Duplicate B_MotionGameMode into the same project folder.
  6. Rename it B_MotionTutorialGameMode.
  7. Open the duplicated GameMode.
  8. Set Default Pawn Class to B_MotionTutorialCharacter.
  9. In the test map World Settings, set GameMode Override to B_MotionTutorialGameMode.

The project character copy already adds the Motion input mapping context and uses Motion input. The copy keeps the supplied plugin assets unchanged. It also gives the new action a known functional path.

The supplied character has a functional input setup. Use it as a reference before you add a project action.

Motion input setup on the shipped character

Create an input action

For this lesson, create your own 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.

To change an existing input, open that input action. Keep the value type that the code expects. Sprint, crouch, jump, and interaction actions must stay Boolean. To change only the key, edit the row in the mapping context. Do not create a new input action.

Add the action to the keyboard IMC

Add the action to a project copy of the input mapping context that the demonstration character uses.

  1. Find IMC_Motion_KBM in Plugins > MotionCore Content > Motion > Blueprints > Input.
  2. Duplicate it into Content/MotionTutorial/Input.
  3. Rename the duplicate IMC_MotionTutorial_KBM.
  4. Open it and add a new mapping row.
  5. Set the row action to the project IA_Interact.
  6. Set the key to E.
  7. Keep triggers and modifiers empty.
  8. Save IMC_MotionTutorial_KBM.

Open B_MotionTutorialCharacter. Find the existing Add Mapping Context node in ReceiveControllerChanged. Replace its mapping-context asset with IMC_MotionTutorial_KBM. Compile and save the Blueprint.

Changing IMC in the character blueprint

The existing Motion movement actions use the same setup path. If the supplied actions operate in PIE, the new action uses the same mapping context.

Consume the input in the character Blueprint

Use this first path when the action belongs directly to your character or controller.

  1. Return to B_MotionTutorialCharacter.
  2. Open the Event Graph.
  3. Right-click in the graph and find 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 from B_MotionTutorialCharacter.
  8. Connect Started to Print String.
  9. Compile and save B_MotionTutorialCharacter.

Use Started for one-time actions such as interact, fire, inspect, or reload. Triggered can fire repeatedly while an action stays active.

Verify the Blueprint path

  1. Select Play.
  2. Push E.
  3. Make sure that the on-screen message appears one time.
  4. Stop Play mode.

Make sure that E operates through the mapping context of the character.

Move the input into a custom Motion component

Use this path for behavior in a reusable component. The character continues to own the Enhanced Input binding. Unreal creates its input component during possession. Thus, the input component can be unavailable during actor component BeginPlay.

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"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMotionInteractInputEvent);

UCLASS(Blueprintable, ClassGroup=(Motion), meta=(BlueprintSpawnableComponent))
class YOURGAME_API UMotionInteractComponent : public UMotionComponentBase
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintAssignable, Category = "Motion|Input")
	FMotionInteractInputEvent OnInteractPressed;

	UFUNCTION(BlueprintCallable, Category = "Motion|Input")
	void HandleInteractInput();
};
cpp
// MotionInteractComponent.cpp
#include "MotionInteractComponent.h"

#include "Engine/Engine.h"

void UMotionInteractComponent::HandleInteractInput()
{
	OnInteractPressed.Broadcast();

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(
			-1,
			2.0f,
			FColor::Green,
			TEXT("Interact pressed from MotionInteractComponent"));
	}
}

Replace YOURGAME_API with the API macro of your game module. Add MotionCore to the module dependencies. Then, compile the module. The Blueprint owns the input event. Thus, an EnhancedInput dependency is not necessary for this component.

csharp
PublicDependencyModuleNames.Add("MotionCore");

Use the custom component

  1. Open B_MotionTutorialCharacter.
  2. Add MotionInteractComponent to the character.
  3. Drag the component from the Components panel into the Event Graph as a reference.
  4. Replace the Print String node after the Started pin with a HandleInteractInput call.
  5. Compile and save B_MotionTutorialCharacter.

The character owns the possession-sensitive input binding. The component owns the reusable behavior. It broadcasts OnInteractPressed for additional Blueprint listeners.

Verify the component path

  1. Select Play.
  2. Push E.
  3. Confirm the component message appears.
  4. Stop Play mode.

The same input action flows through a reusable Motion component.

Where to go next

Motion - Advanced First Person Character Controller