Does UE4 have client-side prediction built in?

This UE3 doc says that it is implemented in UnrealScript in the PlayerController script.
UDK | NetworkingOverview Movement and Prediction

I assume this is still present, but nothing networking related is mentioned anywhere in the features page and the documentation doesn’t mention prediction. The recent Blueprint Networking video tutorials also don’t bring it up (I didn’t watch all of them though).

If it is included I would think it would be something they advertise, since Unity’s networking implementation is not great and you don’t have enough access to their physics to make client-side prediction doable at all.

#Yes

Player movement is properly and wonderfully predicted in the UE4 engine

I know from having hosted multiple real multiplayer games in UE4, some involving more than 2 people!

Rama

Does this apply to physically driven vehicles/aircraft?

Yes, player movement replication and prediction is implemented in UE4 as Rama points out.

However it has changed locations from the days of UE3 (where it was in the PlayerController) to the CharacterMovementComponent for Characters in UE4. Prediction and correction when the character strays too far from the server’s authoritative position is implemented, as well as a Client authoritative mode that can be enabled. It’s fairly complex, but you can get a grasp of it by looking at the INetworkPredictionInterface implementation in UCharacterMovementComponent, as well as the related SavedMove processing in there that replays moves on the client when they receive a correction.

Vehicles using UWheeledVehicleMovementComponent also support replication to/from the server basically by replicating the input which drives the remote simulations. This is a simpler example but may server as a good starting point.

Is the replication and prediction handled by transmitting input events or movement impulses and then the movement component executes the movement on both client and server?

Is the replication and prediction handled by transmitting input events or movement impulses and then the movement component executes the movement on both client and server?

Yes, that’s correct. For characters it sends position and acceleration (where acceleration is the result of input), for vehicles it sends the input params (acceleration, braking, steering, etc).

How does the prediction work in combination with path finding? There seems to be a lot of trouble making that work - there are several posts here and in the forum about it.
My idea was to send the hit location to the server, use SimpleMoveToLocation() on the server to move the character and everything else should work over the character replication. Basically that works but the movement is “jerky and jittery”. Is that an unreal bug or just a wrong approach?

When you’re trying to move the local player, you should perform the movement on both the server and the client to keep them in sync. The server will correct the client to the server-authoritative position if there is a large enough error, but if the client isn’t trying to do what the server is dong, those corrections will be constant and it will look jittery.

If you use the console command “p.netshowcorrections 1” you should see some logs and debug displays of corrected movement. If you set things up correctly, ideally you wouldn’t see any at all.

To follow up: I just realized that if you are using Path Following (SimpleMoveToLocation()), there may be issues w/ using that on a client in network games. I’m trying to get clarification from some folks and I will follow up!

Hi Zak,
thank you very much for the answer. This issue is kind of driving me crazy. It seems like I’m not alone but there were no help so I hope you can provide some clarification.

You’re right - when the server character is moving there are no corrections at all. But when the client is moving - there are corrections practically every frame.

Yup, I’m in same boat. Thanks Zak! Looking forward to any more information on SimpleMoveToLocation Replication.

Keep-alive-message. Just to make sure this thread is not forgotten

I’m waiting to hear back from the AI/PathFollowing experts, I will ping them again.

SimpleMoveToLocation was never intended to be used in a network environment. It’s simple after all :wink: Currently there’s no dedicated engine way of making player pawn follow a path. It seems like a feature we should support in the engine, so we’ll add it in not too distant future. In the meantime I’d suggest just having an AI controller on the server that PlayerController would send requests to and have all the movement happen on the server.

Thank you for the clarification. About the AI controller: how do one setup this combination? Is it just the AI controller for the player’s character or a combination of the AI- and player controller?

I’ve come up with a working solution and decided to post it - it may help someone who is struggling with the same issue. Here how it goes: you have a total of four Blueprints two of which are spawned on the client and the other two on the server:

Client:

  • BP_WarriorProxy : this one is just an
    empty pawn that the user controls
  • BP_WarriorController : player
    controller blueprint

Both are set up as “Default pawn class” and “Player controller class” in Game Mode.

Server:

  • BP_Warrior : this is the actual character with skeletal mesh, animations and all the other shiny stuff
  • BP_WarriorAI : an AI Controller class to control the character

Both are spawned and owned by the server.

The main idea is that the player is owning and controlling a proxy pawn which spawns the actual character and his AI controller (on the server) when the game begins. After that all the input received by the player controller is sent to the server and passed to AI controller which in return moves the actual character.

Here is BP_WarriorProxy:

It spawns both the character and his AI controller and saves them as variables for later use. Don’t forget to set both variables “Replicated” for later use.

And his controller BP_WarriorController:

Nothing special here: take users mouse click and send it to the server (vector would’ve been enough) where I take the AI controller from the proxy and call MoveToHitLocation event.

BP_WarriorAI :
I can not attach more screenshots but it’s rather simple: It has the same movement logic as in the TopDown template except that I use the MoveToLocation() method instead of SimpleMoveToLocation() which is important.

BP_Warrior :
This is the actual character with all the usual components like MovementComponent, SkeletalMesh etc.


Couple of problems I’ve encountered:

  • You need to put your camera on the proxy pawn instead of the character because later is spawned on the server and this combination does not work well.
  • I put the camera on the spring arm and I don’t know why but in this set up it’s arm length is completely ignored - I ended up with positioning the camera through it’s transform.
  • You also need to set your proxies position to the position of the character (camera movement, network relevancy etc.)

Altogether it feels like a hacky way to make smth. basic like moba-game so if you have any suggestions - I’m all ears.

Hi ggs_alex, I’m trying to replicate your solution and I’m stuck on the BP_WarriorController blueprint. Specifically, what does “Event Move To Location” do? Is it a function? What’s inside it?

Hm. It’s actually in the screenshot:
“EventMoveToLocation” in the BP_WarriorController is a replicated event that executes on the server. It just takes the controlled pawn, casts it to BP_WarriorProxy (remember that BP_WarriorController controlls the proxy pawn), takes the AIController (which we saved previously) and basically calls its MoveToLocation method (which in the screenshot is wrapped into EventMoveToHitLocation but that’s not important).
I know, it’s confusing but if you grasp the idea of who-controls-whom you can implement it your own way. Our current implementation for example does not need the proxy pawn and still works fine.

Thank you. This was a massive help. I managed to do this in C++ and posted a howto