Is it possible to leverage the NavigationSystem clientside?

In a multiplayer game, I have a need to use FindPathToLocationSynchronously on clients so I can draw predicted movement paths locally. Unfortunately, AI controllers don’t exist on clients. So I was hoping (in C++) to leverage the NavigationSystem into my player controller. I’m currently digging through engine code to see if I can figure this out but it’s not looking great. I imagine this has been done before so I was hoping to find an answer here.

Thanks

Edit: I found the project setting “Allow Client Side Navigation” which now allows me to access the navigation system in the player controller with

UNavigationSystemV1* NavSystem = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());

Just had to include
#include “NavigationPath.h”
#include “NavigationSystem.h”

1 Like

Aren’t you opening yourself up to client/server mismatches in the same navigation operation?

Surely it would be better to just replicate the path across to the clients?

Well, I am drawing the path clientside in realtime. Currently just using debug lines but I’ll make it something cleaner later. The idea is that as the player moves their cursor, we draw the path that the AI will take to get there so that when they click, they have already confirmed the route that will be taken.

In order to replicate this, I would have to send RPCs to the server at a very frequent interval and get an array of vectors back. That seems like it would be pretty taxing network-wise and any lag would be extremely noticeable visually.

You’re right that there could be issues though. If an obstacle is not shown in the correct location clientside, their pathfinding will generate incorrectly. If this turns out to be a big issue, we may have to scrap the live drawing of the path and instead do something like … click once to see the path (which will do the RPC and get the vectors from the server) and click again to confirm it and move.

1 Like

What’s to stop you setting this array up as a simple replicated array and a boolean for bDrawPathing? Then you only need to send RPCs for the start and end.

The server doesn’t know the client’s cursor position so I’ll need to keep sending that every time I want to re-draw the path.

Edit: If there is a better way to handle this, I’d love to hear it. But it seems since I rely on the cursor position there’s not a lot I can do.

1 Like

It’s definitely a complex issue to solve.

Perhaps even one that isn’t going to be necessary to solve unless you specifically encounter a problem with your proposed method.

I would keep it on the backlog just to make sure it’s checked later on down the line.