So I’m trying to move the player on the server, but on the client the player isn’t moving at all. I’ve set up a minimal example:
And the player doesn’t move at all when the set actor location function is called (the player isn’t at 0,0,0 so the change should be seen). I’m guessing that I’m not understanding some part of replication, but as far as I know it should work
If I run “SetActorLocation” anywhere before “Server Move In Direction”, meaning I run it on the client, then the actor is moved properly as it should.
I tried passing the player (reference to self) as a parameter in the replicated function both as a reference and as a non-reference and printed the display name on both sides (client and server). In the blueprint below the display name is BP_TilePlayer_C1 which is what it then passes on to the server, but on the server side this value will get printed as BP_TilePlayer_C. Shouldn’t they be the same since C1 is the object that was passed to the server, because I suppose this means the server isn’t modifying the correct actor.
So I reparented my player as a character and now it works just like it should (the first two images works). I used a pawn because my game is tile based and don’t as such I don’t need all the functionality of a character (other than the animation functionality, but I’m using static meshes as placeholders). Anyway, anyone know why it didn’ t work when my player was a “Pawn” and not a “Character”?
If your Pawn is controlled by the server then your function only runs on the server and is not replicated to all other clients. therefore, you’ll have to multicast the direction or possibly better: the location or transform. Add an Authority/Remote switch at the client’s event. Authority (Server version of the actor) should then run a “multicast” event and remote should run the normal server event as you did.
Characters have a build in movement replication system that works without any preparations or manually replications.
In the picture I’m predicting the pitch and yaw of a grabbed object and then only replicate the rotation to the server or to everyone else. But you can also just replicate the input of the calculation function and run the function on every machine individually.
You need to go into the character components and click on replicate movement for the mesh/ visible components. That should be all there is to it.