Character speed replication

I am creating a multiplayer game and am setting the max walk speed on the client through a custom event that replicates on there server. The issue is that in the clients animation blueprint, it still read the speed as if it was set to the lower max walk speed.

On the server, the speed and the animation works.
On the client, the speed works but the animation doesn’t

Image of my custom event setting the max walk speed:

I have managed to get around the issue by having a replicated Speed variable as a float in my character blueprint. It uses a custom event run on the server that updates the variable which I call in each tick (Image below).

From there, I just grab the variable from the character blueprint from my anim blueprint.

However, I just feel as if this is not the ‘correct’ way to do it. Am I doing anything wrong?

In fact, I think this is causing a jitter on the clients aim offsets.

I am trying to create a function to allow the user to sprint. I can achieve this in single player by simply ‘upping’ the Max Walk Speed. However, it does not replicate on the server.

Hey WillB,

I’m not sure that I understand exactly what it is you’re trying to set up. What is the functionality that you’re trying to achieve?

Could you provide a bit more detail in terms of what this would accomplish in your game? This would help give me a better idea of what we can do to see if we can get this working in another manner, or if the way you’re currently doing it is best practice.

Thanks

Are you working with the Third Person Character or are you using a custom character with a custom AnimBP? If you notice, the ThirdPersonAnimBP sets the speed just like you do in your SRV_SetSpeed event.

Working with the default Third Person Character, yes I understand that it sets it in the anim bp but it doesn’t replicate.

Edit: If I use the default way in the anim bp, it updates on the server but not the client.

I tried this, although the character seems to be moving faster, the anim bp doesn’t get the faster speed so the animation doesn’t get played. Which is why I added my work around previously. Thanks!

Okay, great. So I have one more question for you just to make sure we’re on the same page:

Are you trying to set the speed of both the Server and Client’s characters, or are you just trying to set the Client character’s speed? I just want to make sure I’m understanding your issue.

If you want to create a sprint function, you can try something similar to what we have pictured below:

This worked on my end and I was able to have both the Server and Client’s characters sprint.

Let me know if that is what you’re looking for, or else I can suggest something else.

Thx bro, i used the workaround you added and it worked, its weird cuase im sure i didnt need to set the speed in char bp before and it worked, this time the clients didnt upodate the speed var on anim BP and anims didnt play, althou their physical velocity was updating! Maybe its a bug it should be reported!

By the way Sean, the problem is not on setting the char max walk speed, but yes on getting the velocity from the anim BP, it doenst work on clients!

I copied this exactly, and I get the jitters when trying to Sprint? Constant position corrections from the server. This is from a fresh Third Person Template also (as I’m trying to solve some networking issues of my own with sprinting.) Using 4.20.1

Same for me on 4.20.1, I can’t seem to find a solution and its driving me nuts. When there is a change in speed it jitters and position correction from the server seems like. I am not even sure it is an issue with speed at all but an issue with movement replication, the client is not in perfect sync and the server corrects it causing a jerky feeling.

I also encountered the whole problem, the client is not working and it looks like it is stuck

Just before you send the Server RPC to change walkspeed on the server, set the walkspeed on the client, then the client doesn’t have to wait for server round trip to replicate walk speed back to client.

On the other hand, this is a Character Pawn we’re talking about. It might be replicating and predicting movement speed already without RPCs, and adding RPCs might double the effect, thereby causing jitter. I don’t know without looking in the character pawn code.

Try setting walk speed just on the Client with NO RPCs and see if that works better. Character Pawns have a lot of hidden networking replication and prediction stuff already built in to them, that works better than RPCs alone.