Summary
This article introduces the input processing mechanism in Mover 2.0, what the input command context is, how to pass data to the Mover system through the context, and how to customize the InputProducer to manipulate the context.
Introduction
UnlikeCharacterMovementComponent (inherited from PawnMovementComponent), you only need to callAddInputVector to drive the character's movement.
In Mover, the handling of movement input becomes more flexible, but at the cost of user code becoming more low-level and complex.
Input Command Context
In Mover, the main way to pass user input to the Mover system is through InputCmdContext (input command context), hereinafter referred to as Context.
You can simply understand Context as aMoverData container, which can be manipulated through Blueprint/C++ APIs to add, delete, modify, and query the data it contains.
Here, theMoverData refers to: a structure that inherits fromFMoverDataStructBase, therefore, you must add a new MoverData type through C++.
Context can accommodatemultiple types of input parameter structures.
What is InputProducer?
Any UObject that implementsMoverInputProducerInterface can be regarded as anInputProducer.
MoverComponent has a built-in ProduceInput function that is called every frame.
It also holds a reference to an object that implementsMoverInputProducerInterface. The default implementation of ProduceInput above is completed through the InputProducer object below, allowing users to decouple input logic from the Mover system.
By default, MoverComponent will try to query objects that implement this interface from the owning Actor or its component tree at BeginPlay.
Since this object is public and can be read and written in Blueprints, you can assign any object that implementsMoverInputProducerInterfaceto this member at any time.
Note
Although the code comments claim that this object is optional, much of the engine code in the current Mover plugin does not treat it as '
optional'. So make sure you always provide an InputProducer.
Users only need to care about how to pass input command control parameters to InputCmdContext through the ProduceInput function.
Implementing the MoverInputProducerInterface
Both Blueprints and C++ can implementMoverInputProducerInterface,
note
ProduceInput will execute every frame, but you do not necessarily need to add data to the Context every frame.
Official Example
In the MoverExample plugin,MoverExamplesCharacter this Class implementsMoverInputProducerInterface, and demonstrates how to bind InputAction, cache the value of the Action, and in OnProduceInput, based on configuration, the character's current state, and the value of InputAction, constructs inputs forCharacterDefaultInputs. You can refer to it for basic usage, but please refer to later sections for how to design your InputProducer.
Designing Your InputProducer
I recommend implementing this interface through a Component rather than through an Actor. Component-based development can enhance the portability of the code.
Using separate components, implement the control logic of the business through inheritance of components, thus achieving different control strategies.
You can perform logical control through your component derived classes.
Loading Blueprint
Initializing BlueprintUE renderer...
Handle Dash..
In the engine's lower level, theProduceInput on the MoverComponent is called by theNetworkPrediction plugin.
It is a world subsystem that updates with the lifecycle of the world. We will delve deeper into this part in future articles.