Multiplayer Topdown-Game - Navmesh won't be replicated to clients?

Hi,

I’m working on a little multiplayer game and to get into the topic I watched this tutorial series (which is by the way very nice): Unreal Engine 4 Networking

This series gave me some basic knowledge and I’m currently trying to setup a multiplayer mode for my own game. My game is based on the top down template where you can simply click on the floor to make your character run to the clickposition. I did a quick setup by deleting the character from the scene and adding 2 player start locations to the scene instead. After that I set the “Number of players” to “2” in the play options:

Then I started the game. Unfortunately it’s not possible to move the player character on the client but it works on the server (left: server, right: client)

To make sure that the input of player 2 gets handled correctly, I added a simple option to rotate the camera with simple key presses (by pressing spacebar the camera rotates until space is released) and this works for both players (or: server + client).

So by knowing that the inputs work in general, I guess that the navmesh is not replicated for player 2 but I can’t find an option to do this :frowning: Does someone know a solution for this?

Thanks and best regards,
Daniel

The SimpleWalkToX just works with an AI controller on multiplayer games.

Have a look at this topic at answerhub: https://answers.unrealengine.com/questions/34074/does-ue4-have-client-side-prediction-built-in.html

Thanks for your help, guys!

I’m quite confused why unreal doesn’t support this feature by default. The solution from the other thread obviously seems to work (altough i didn’t test it by myself) but it is - as the author stated - a very hacky way to achieve a solution for a relatively simple task.
Building the character controls in such a hacky way may lead to unpredictable problems in the further development steps of a game and I’m not sure if that’s a solid foundation for a “real game”. So is there a cleaner way to get things done?

Don’t get me wrong - I’m happy that there IS actually a solution for this issue but it’s not ideal as the author himself stated and there must be a better way to do this (I mean we’re talking about the Unreal Engine and not about some c-class tool ;D)

Best regards,
Daniel

Here’s what I’ve got so far

Hi,

I’m trying to setup a similar approach to solve the problem but there are some problems. It works in a single player game but there are some errors in the multiplayer version. So to summarize the main idea:

  • The player is represented by a default pawn that only contains a spring arm and a camera
  • the player controller spawns an AI-player (which contains the model and all the animations and is the visual representation of the player), an AI controller for the AI-player, which feeds the blackboard of the AI-player with all necessary data (for example a click location that is used as a “move to” target in the behavior tree)
  • the player controller sets the player’s pawns position (or in other words: the player’s camera) to the AI-player’s position so that your camera always follows your player model

Here you can see a visual version of the theory and the blueprint of the player controller:

4b63d7a5797a37dc94d5807a918f71f32a0fe5d6.jpeg



This works as expected in the single player version and the model moves to the click location properly.
If i start a simulated multiplayer game in the editor, two players get spawned:

BUT only the server’s player can be controlled and the log window shows these error messages caused by the client:

Do you have any idea why it doesn’t work in a multiplayer game? In the single player version there are no errors in the log or anything else which is really strange :frowning: (by the way: the replication properties of each class are left to the default settings)

Thanks and best regards,
Daniel

Check out pallys series Unreal Engine 4 RTS Series Part 1 The Camera: Unreal Engine 4 RTS Series Part 1 The Camera - YouTube

Thought I’ll add a few cents. Definitely on the right track. The reason why it doesn’t work in multiplayer is because AIController only exists on the server. Was just helping another guy on reddit/r/unrealengine regarding a similar issue with click and move for multiplayer. Spent a bit of time making a rough tutorial on it. (About 16 mins long, definitely could be better edited, and presented)
Demonstration: https://www.youtube.com/watch?v=sWr1cvOyZYU
Tutorial: https://www.youtube.com/watch?v=vNjxEdMYSCI (16 min rough draft)

Hi Tinyted,

thanks for your videos! They’re really helpful and I think it’s a good start for many of the users out there with similar problems.

I’ve managaed to get things done and the controls work for server and client but I’ve encountered a slight stuttering on the client side while everything works fine on the server side.
My input is setup like in epic’s top down template where you affect the character’s movement as long as you hold down LMB so that the character follows your cursor. This works without any delay on the server but you can see that the character’s movement is not perfectly smooth on the client.
I guess this has something to do with the navigation function that is executed on the server. Maybe this step leads to a little delay which is unfortunately noticeable?

The movement of the character gets smoother by increasing the replication rate per second in the Blueprint from default 100 to 2000 but even with such a high value the movement on the client side is not 100% smooth and you can still see some stuttering.
I also tried to use different movement nodes in the AI controller (Move to Location, AI Move to, Simple Move to) but this makes no difference.

My game is based on a smooth and fast gameplay and I need to get rid of that slight stutter effect for an optimal gaming experience. So if you have any ideas how to improve the character movement on the client, please let me know :slight_smile:

@twinnaz06: Thanks for the link! This was also very useful to understand how to setup such controls in general :slight_smile:

Thank you and best regards,
Daniel

Hey Polygon, would you happen to be able to get a video of that stuttering? And the related blueprint.

Does the stuttering happen whenever you change the cursor position while holding it down. Or does just the fact that holding it down in one spot already creates a stuttering effect.

I’ve seen some really weird slow movement if you just take the Top-Down template, and let the server perform the simple move to location that it uses. I’m not sure if that’s the stuttering effect you’re talking about, or if it’s something else. My own pet project isn’t an RTS style like gameplay, so I actually haven’t played around with a lot of the move to nodes. (Only happened to make the tutorial because I saw someone having issues with it, and gave a quick try to see if I could solve the issue)

EDIT: Just did a quick test to implement a Hold down RMB to move, and think I may have found the potential cause of your issue.

Quick follow up in regards to the Hold down to move issue.
(Video for those that prefer video: https://youtu.be/RoU-mFDLlZ4, it’s absolutely unedited, since I just did it in a rush)

The reason for the stuttering is because the Server has an instance of all player controllers. Thus if you don’t check if the instance is a local controller, the server will execute things for the client also. And if the server doesn’t have the cursor information, or the mouse held down info, it’s going to stop the movement. So what ends up happening is:
CLIENT: MOVE!
SERVER: STOP!
and you get a back and forth of stuttering.
Increasing replication rate, if I’m not mistaken actually increases the time between each replication. Thus decreasing the move and stop cycle, and making it “smoother”.

The simple solution is to check if the controller is a local one, if it is, then execute the relevant code in stopping or moving. (You still have to tell the server to stop and move).

Thank you very much for your help, Tinyted!

I will upload a video and screenshots of my blueprints this evening as soon as I’m back from work. Your theory sounds plausible to me and I’m really looking forward for your feedback on my upcoming uploads :slight_smile:

Best regards,
Daniel

I finally managed to gather all the needed information and here we go :slight_smile:

So the logic is like this:

  1. Custom Game Mode sets “PlayerPresence” (Pawn that only contains a camera component) as the default pawn and also sets “PlayerMobaController” as the default player controller

  2. “PlayerPresence” spawns an AIcharacter (the model with all the animation stuff on it) and an AIcontroller that does the via a simple Move to Location node

  3. PlayerMobaController receives input, the server does the movement and the PlayerPresence follows the AI’s position

In the following video you can see the stuttering effect on the right (client) side while the server’s AI character moves totally smooth:

http://www.polyflow.de/temp/stutterissue.mp4

And here are the blueprints:

b24d6b44418d95ae8a10edb0a1670d232e30e203.jpeg
d6659c1b3b2849bd56bdc4ae3a4ef5e5f39145fb.jpeg
13fb6bcaeb2614c08e56fca2c3eb99630f161cf0.jpeg

I’m not sure but I think it might be that is has something to do with the camera alignment and that the stuttering is not in the AI movement itself. I’ve played around a little bit and tried different versions with a lerp, without a lerp, with a spring arm, with spring arm delay, etc… but the issue is still noticeable, no matter which way I try :frowning:

So hopefully you have an idea :slight_smile:

Thanks and best regards,
Daniel

Hi,

I’ve done some more testing and it’s not related to the camera movement. the AI character seems to move slightly edgy and blocky on the client. I’m not sure why the movement on the server is smooth while it’s not on the client but I could imagine that it’s somehow related to the fact that the movement is done on the server and maybe this causes some kind of very subtile (but noticeable) delay in the calculation of the AI position/animation?

The problem gets worse if I decrease the “Replication Rate” in the Character’s defaults from default 100 to lower values like 20 or even 5 so I guess it’s somehow related to this rate. Unfortunately the problem can’t be avoided by increasing this value from 100 to higher values, which totally doesn’t make any sense to me.

It’s horrible to be this close to the goal and then struggling with such a small but extremely annoying problem.

By the way: I tried also the check if the controller/player is local like tinyted mentioned in his latest video but this had no effect :frowning:

Best regards,
Daniel

Hello,

I had this problem and fixed it. To describe the issue; in dedicated, the owning client would falsely predict his own movements and get the forced network update RPC producing a jitter movement without correct rotation.

The simple solution is to enable client navmesh in your project settings and to call move to on the owning client and server only… (see image)

I have provided a paste that you can put in your ThirdPerson character template project and see it working.

Press T to navigate to the spot in the middle of the screen.

This is not a great solution, but it will get you moving.