Replicate Floating Pawn Movement Problem

Hello.

I’m having issues getting my player pawn to replicate changes to it’s velocity from the client to the server and other clients.

Here’s a quick blueprint I made to demonstrate what I want to do and what’s not working:

The client and server receive and execute the print string.

But only the client sets the velocity. So I can move the player on the client, but I just stand completely still on the server.

Does anyone know why I can’t set the player’s velocity on the server? I’ve checked the “replicate” box in the blueprint class defaults.

I’ve also tried to set the Floating Pawn movement to replicate, but it still doesn’t work.

Any insight on this issue would be much appreciated! :slight_smile:

-Headstub

1 Like

Anyone? I can’t work more on the clientside prediction if I can’t change the velocity of the character on the server as well as other clients.

The “Set Velocity” node receives the execution fine, but nothing happens:

So noone moves when you press jump?

When server moves, all clients see the move.

When client moves, only owning client sees the change, even though the server and other clients are executing the exact same code with inputs from the client.

I can put together a quick youtube video showing off the problem. Will post it here in a sec.

Here’s the video:

Top Left: Server

Top Right: Client 1

Bottom Left: Client 2

The walking movement, gravity, friction, etc… use the same method as shown above. What’s weird is that the “Add Controller Pitch Input” and the “Add Controller Yaw Input” isn’t being executed on server from clients either, even though the debug view shows the node receiving the execution pulse on the server’s version of the pawn.
As I showed in this picture:

Okay, so I found out that the only reason the server is being replicated is because the “Replicate Movement” box was ticked in the Class Defaults tab. Once I turned that off it behaved just like the other clients, meaning that the server only moved on it’s own screen. But I see that I don’t want the “Replicate Movement” anyway since it negates what I’m trying to do here, which is to replicate everything manually with my own system. It seems like everything comes down to the fact that Variables and Functions won’t execute on the server when it gets called from an RPC. I’m continuing to look around for answers as to why that is. Is there something I have to do in order to let call commands from RPCs to execute things like “Set Velocity” and “Add Controller Pitch Input” on the server? This is all so confusing since you can clearly see in the debug window that the nodes do receive the call to execute.

To call RPC’s you need to make sure the correct Ownership is available.

For example: A “RunOnServer” RPC can only be called from Client to Server in an Actor that is OWNED by the Client.
A class that is owned by the client is, for example, the PlayerController.

A possessed Pawn/Character is also owned by the Client.

If you try to call a “RunOnServer” RPC on a Server owned client or on an Actor that another Client owns (so not the one make
the actual RPC call), the RPC will be dropped and won’t reach the Server.

Since your events fire correctly, you should’ve done this correctly.
Have you tried printing the velocity after changing it?

Does the Velocity change for the other Clients and Server and the pawn still don’t move?

The default movement replication is (i think) limited to the standard CharacterMovementComponent.
Other movement things need to be replicated by hand.

But yeah, in fact, your code should work, so you might want to debug the velocity variable.

Alright, yeah. I tried printing the velocity and it shows the that only the owning client is being changed:


So I tried remaking the blueprint in an entirely new pawn, with no changes except adding a camera, capsule collision, a floating pawn movement and turning off “Replicate Movement”(So no gravity, friction or WASD movement that was inside the other pawn)

Now this is the only blueprint logic that’s inside the pawn:


But now things got even weirder. The print strings now show that the server and the other client changed velocity, but not the owning client. Yet only the owning client moves when I click.

Click 1


Click 2


Click 3


Click 4


Click 5


This seems to add even more confusion to the mix but it might also give a clue to what’s happening. I still have no idea why this is happening:/ But thanks for the help so far:)

Ok, I’ve tried experimenting some more and I think I know exactly what’s wrong, I just don’t know how to fix it.

It seems that the reason this is not working is because only the owning client can change the velocity of the actor and move the controllers pitch and yaw position. The “Set Velocity” can be called on the server and another client, but since the server and that other client is not the owning client, nothing happens. It seems as though this has been hard coded into the pawn to prevent cheating or something, but with an authoritative server that does it’s own logic that should not be a problem. My blueprint only sends inputs to the server, and the server should perform it’s own logic and send transformation coordinates back. So I just have to find a way to allow the server to set the velocity of other clients.

I made a system to replicate an actor’s transformation and found that you can set the transformation of an actor on the server and other clients even though you’re not the owning client. Since only the client could move, I replicated the client’s transformation coordinates, sent it to the server and had the server set the actor transform on all the other clients.


This works perfectly with the exception of some stuttering, but that can be fixed with interpolation of the transform positions. I also know that the other glaring problem with this is that the client can easily exploit this and just tell the server custom coordinates to let them fly, this is just to demonstrate that setting the transformation on clients other than the owning client works.

Here’s a Youtube video showing it off:

But my ideal solution would be to do this instead:


If the server can perform all the logic on it’s own and just send transform coordinates back, this should work. I’m also going to write logic that compares the client’s own transformation with server’s transformation and taking into account lag with a circle buffer that logs the last 60 transformation coordinates along with timestamps.

But as I said the problem is that the server cannot set the velocity of the actor or move the controllers pitch and yaw if it’s not the owner of that actor and therefore not perform all the logic on it’s own. So the blueprint above just replicates that the actors are standing still mid air.

-Headstub

Alright, I’ve fixed the set velocity problem. I replaced the “Floating Pawn Movement” component with a “Projectile Movement” component which doesn’t seem to have the restrictions I talked about above. Setting the velocity on client and server works perfectly now.


The only problem left is replicating the Controller Pitch and Yaw. In the Pawn Blueprint the “Add Controller Pitch Input” says this in the tooltip:


It says that it will only execute if local PlayerController, so I moved that part of the blueprint into the PlayerController Blueprint’s event graph instead . It does not say that on the “Add Pitch Input” in the player controller, but it seems that is what’s happening there too:


Here’s the entire blueprint of the Player Controller:


Here’s a video demonstrating the problem:

So the problem is that only the owning client can change the controller Pitch and Yaw. It might look like the server’s controller input is being replicated properly, but that’s only because the server is sending it’s transformation position to the other clients and having them set it. I’ve made it so clients only send input to the server and the server sends back the transform position of other players(server’s player included). Since the server can’t change the controller rotation of it’s clients, the rotation sent in the transform to the clients are just the same rotation they spawned in.

Doesn anyone know how to fix this?

-Headstub

Okay, I solved it. Leaving this up here in case anyone has the same problems I’ve had.

PlayerController Blueprint Replication for Pawn:

The Blueprints are fairly self explanatory, with the exception of the linetrace I do on the server to determine what the player is looking at.

Hope this helps!

Thanks @eXi for replying. You confirmed that the logic should work and pointed me in the right direction to find out what was wrong with the “Set Velocity”

Is there a way to mark the thread as solved? Or is that only on the AnswersHub?

-Headstub

1 Like

Glad you found the solution. Couldn’t stick to the problem, since i’m busy learning for my exams.

You can’t mark threads as solved. Just leave it like this (:

Sorry to hijack a solved thread, but is there anywhere I can learn about movement-related replication, client-prediction etc.? (c++ if possible)

My world just collapsed when I found out that the only “network-ready” MovementComponents in UE4 are for characters and vehicles.

My plans include flying drones, hover tanks and replicated spectator-movement. But now I have no idea how to do it.

Any links to tutorials etc. would be much appreciated. A finished network version of the flying pawn movement to start with would be even better.

I would recommend reading Valve’s wiki article on the subject. It’s really well explained and in depth. I’m still trying to wrap my head around it though.

Here’s also a good video showing off how some of these principles work in CS:GO

Hi,

 I am a begginner to UE and have just started studying Networking.  I had the same issue regarding client to server replication when using pawns and the float pawn movement component because I understand they do not replicate to the server automatically,  I would need to send the server updates that occurr on the client but I have found out that the Character class has built in support for client replication.  My question is: Why would you not use Character and character movement for your solution and/or why Do you want to bypass this mechanism ?

Thank you