Purpose of Movement Components (+ regarding networking)

Hello,

I’ve recently finished my first good-looking version of moving my Pawn(simple plane) around.
This resulted in moving and rotating(with quaternions) my rootcomponent, and locally rotating some subobjects of my pawn.

Now I want to take all this movement logic and put in a seperate class. A movement component literally cries out to be used in this case. However this is the first time for me to encapsulate behaviour in a seperate class(in UE4) and some things are quite unclear.

My main question: What is the purpose of a movement component?

And to answer my question partly by myself:

  • Movement components offer a nice way to structure your code (regarding movement of your pawn)
  • You are able to reuse this component on other pawns which have similiar behabviours.

However some things are still unclear for me:

  • Can I set the rotation of my Pawn like I would normally do it? (used functions: SetActorRotation, AddActorLocalOffset, SetRelativeRotation)

(I’ve looked into the UPawnMovementComponent and only found an InputVector. How is this one computed?)

  • In regards to networking: does the movement component has already any inbuild functions to synchronize movement between client and server?

(Especially: are there some best practices to handle client-side prediction in UE4 with movement components?)

  • What is the reason Movement components are used in the first place? (some prosa, why they exist and what for would be nice)

As you can see from my questions, Im still not sure about why and how I should use this component. The documentation went like “well, if you want to move your component: do it in a movement class”. But it’s not really explained why. So if you explain the “why”-part, that would be really nice.

Thank you and regards :slight_smile:

Hi there,

I want to kind of restructure my question and answer it myself.

What had I already achieved?

I’ve defined the movement of my pawn for a singleplayer game. Therefore I created a pawn, which inherited from APawn. It used functions like SetActorRotation, AddActorLocalOffset, SetRelativeRotation and no explicit MovementComponent.

NOTE: There is a difference between APawn and DefaultPawn!

What do I want

Multiplayer support for my pawn while running a Dedicated Server.

What I’ve figured out

the main problem regarding networking

The basic idea while creating a multiplayer game with a dedicated server is, that the server does all the gameplay important decisions and the client gets only informed about the results.
E.g. you want to activate a skill:

  1. you would press the key for that skill
  2. you would let the server know that you want to activate that skill
  3. the server validates, if you are allowed to press this skill and if yes, activates it for you and should tell you that it really activated that skill
  4. you see that your skill activates and gain the effects of that skill

Well in most cases you can do it this way, since you do not really care about the little needed time for sending your event to the server, letting the server do its magic and waiting for the answer of the server.
In some cases however (like movement) this time will be perceived as lag and clunkiness, which it truely is! The majority of games will try to hide this lag by already doing this move locally and only letting it validate by the server. This is also called Client-Side-Prediction.

the two solutions:

In my research I’ve found 2 ways to solve this problem. The first one uses direct transform manipulation(SetActorLocation,SetActorRotation, …). The second one uses a custom movement component.

1st option:

You use the inbuild replication/networking system of the engine and determine all the movements through events and replicated variables.
For that one I want to give you one example on how to solve this:

The green commment boxes should highlight for you what the client is doing, while the red is highlighting the servers actions.
This implementation is analogue to the explanation which described how you would activate a skill networkwise. (1.-4. from before).

In this implementation you will feel lag if you have a high ping.

Further readings on this one:

  • [Come Learn Blueprint Multiplayer with me!][3]
  • [Pawn Networking][4]

… regarding movement components

Movement components seem to generally encapsulate all the behvaiour you want and additionally make it functional for networking. (Or at least you hope that your movement component is doing that). In addition some smoothing should be done here. (Client-Side-Prediction and some more neat stuff to achieve nice fluent movements)

Furthermore a movement component inherits somwhere down the line from UNavMovementComponent. This should allow Pathfinding for your AI. (At least I think so, could be wrong here, haven’t touched AI yet!).

Further readings on this one:

  • [Lack of Movement Components for Networking][5]
  • [Networked “Physics-Vehicle Movement Component”: existing examples or implementation hints?][6]

Conclusion

Movement components exists to make your movements look smooth. The player should feel to achieve changes through input immediately.
They might have some more use (AI).

However you can update all your movements manually through the given networking/replication system.

Further readings/tutorials:

  • [Introduction to Blueprint Networking][7]
  • [About general networking issues][8]
  • [Networking Interpolating replicated movement data in Pawn, without modifying source][9]
  • [Is Default Pawn multiplayer capable?][10]