[NETWORKING] How to replicate a teleportation movement

After looking at this tutorial https://www.unrealengine.com/en-US/b…king-tutorials
I decided to try and add a teleportation movement in a replicated scenario as suggested by this article https://docs.unrealengine.com/latest…ractermovement

Now , tell me if I’m wrong , it seems to me that things are as follows :

  • if I execute the teleport locally , the server will warp the client back because it is seen as an error
  • if I create an event set as “execute on server” (which in turn will execute the teleport) the server will execute the teleport for the client and then, upon checking, it will correct the client position to the new one . This is not the right approach because it’s just a correction , not a real execution and all cosmetic effects are lost .
  • the second guide I linked says we can execute the teleport locally and then call the server event which will execute the teleport also on its side , the two ending position will coincide therefore no correction will happen , and since the client executed the teleport locally as well , cosmetic effects will work .
    here comes my questions :
    1- first of all, when I play , I have a server window and a client window , it’s true that now the server executes the teleport correctly BUT if I teleport the actor in the server’s window , it will teleport TWICE! I thought “well the server doesn’t play” but I thought that the server window worked as listener with a client attached , it should work just as the other client ! Moreover if I play with a dedicated server , each client can teleport but the other won’t see the cosmetic effects because the event is set to “run on server” and not multicast . If I switch it to multicast , its as if the server doesn’t run it anymore, because not only the other clients can’t see each other teleporting, but every time I teleport I get warped back , which really upsets me because i thought Multicast would execute on the server AND on all the other clients.
    2- the Approach 4 of the second link talks about how to address this but it is very very generic and also in C++ . Now , I will soon need it as well but how can one obtain the right behaviour with just blueprints ?

as you can see I’m a bit confused and also very much new to this world of Unreal and Replication, sorry and thanks for help

edit: i attached the screenshots of the blueprint

Hi I’ll try to say something even if I didn’t follow all that you just said! :slight_smile:

One thing is that in UE if you are using a ‘Character’ class with the built in movement it has movement replication build in already.
If you ticked that checkbox in your Character BP? Also you need to have spawned the character in a way so that it replicates over for that to work I think.

Now I am not using that myself so not completely sure what happens if you teleport on the ‘remote’ (ie not the Authority/server) you’ll have to test that. But if you teleport on the Server/Authority then I would think that the clients/remotes would do the same shortly after automatically.

So what you could do is that when the player triggers the command you first have a switch node for hasAuthority and then if it is true then you just run your regular teleport function.
If it is false then you ask the Server to do the teleport with an RPC(the ‘run on server’). (and let the automatic movement replication take care of the clients/remotes)
The problem with this is that it adds a round trip latency when triggered on the remotes.

Let me know if this sounds like something you could try out? Or if your setup is different?

Cheers

Hi , thank you for helping!
I tried doing what you said, interpreting the hasAuthority true as the “Authority” pin and false as the “Remote” pin. So, if it is the Server it just teleports, if it is the Remote client it will call the teleport on the server.
Quoting from the guide I linked :
Analysis: This works, but it’s far from ideal. When the player presses the T key teleport, the command is sent to the server, but nothing happens locally. This can leave players feeling like the controls are unresponsive, and the player will not immediately know whether the teleport command worked or not. When the server receives the command, it moves the Character, but does not tell the client. On the next time the client sends an update, the server will see the client’s reported location as being 10 meters off, and will send a correction. The correction will cause the client to move (smoothly) to the server’s expected location, effectively causing the teleport to succeed, although it wouldn’t look right. If we had set “p.NetShowCorrections” to 1, we would be notified of this as a network correction. In addition, if we want to polish the ability with things like particle or sound effects, those effects will not show up correctly since the actual ability only runs on the server. Although the client knows when the ability is attempted (and the command is sent to the server), there is no report of it succeeding or failing, just a correction that shows up shortly afterward.

TL;DR: when the client run the teleport on the server, it will get teleported as a correction side effect, and no visual effects will be played.

What I would like to achieve: the client teleports, its immediate and with effects, the other clients and the server all see the teleportation WITH the visual effects as well. In my case the visual effect to be replicated is the LineTraceByChannel set to persistent. I’m starting to think that maybe that’s the problem, since I’m not spawning any effect or sound emitter It does not get replicated amongst the other clients.

Hmm…yeah probably this would be better answered by someone who is actually using the Character component and its auto move replication as I decided not to do that for my project.
I have my own movement so that I can have control over how I execute things locally on the remote client and on the server. Maybe there’s a way to do that even with the built in movement replication but someone else would have to tell you how that could work.

What I do (normal movement, not teleportation) is that I both set off a local move function and I send a move command to the server. I have NO auto movement replication.
That way I get immediate and responsive action for the remote player. But since I want both server and client to be in as similar place as possible I also have a gradual sync from server to client. I send position coordinates from the server that I ‘softly’ lerp back into. If that make sense?

Maybe in your case if you were to do this you could do the sync lerping only when the player starts to locomote again, walking or running. That way you’d avoid him/her sliding in place when standing still.

EDIT: And this is a useful read when doing this stuff, https://docs.unrealengine.com/latest…g/Actors/RPCs/