By default, NavigationSystem in UWorld is null unless we are a server, according to UNavigationSystem* UNavigationSystem::CreateNavigationSystem(UWorld* WorldOwner)
So i changed that function to still make it on clients, but then trying to generate paths in clients crashes indtNavMesh::getTileCountAt because m_posLookup is null ?
I want to use Click to move functionality by pathing in the client, there’s no need to involve the server in this (and we cannot, especially since i allow normal direct movement to immediately cancel pathing).
How do i enable navmesh loading and NavigationSystem capabilities on clients ? (I dont need AI on clients, but i do need pathing.)
At least I’d want to be able to draw the path on the client without requesting it from the server (think of RTS games where you click repeatedly out of habit, to move, you certainly dont want that making a roundtrip to the server each time), so I’d need UNavigationComponent::FindPathToActor and UNavigationComponent::FindPathToLocation to work on clients (this should certainly be possible, and is not a ludicrous request that defies networking principles)
Even if you want to move some actor locally, its position would be corrected to previous value right after next net update.
You should perform RPC to server, then server will calculate movement with its navmesh. After all, object location will be changed on server and replicated to your client.
It wouldn’t. Pathfinding from the UPathFollowingComponent is applied via the UNavMovement::RequestDirectMove, which you could override to do things like AddInputVector, which would work on the AutonomousProxy version of PlayerCharacter (basically pathing by emulating controller inputs, which will work on non-servers).
Anyway, how about you disregard all that, and let’s just say i want to DRAW THE PATH on the client without getting it from the server. So i just want UNavigationComponent::FindPathToActor and UNavigationComponent::FindPathToLocation to work. This should certianly be possible on clients, i mean, the navmesh is present in the map files after all.
Turns out this was because the ARecastNavMesh wasnt set to load from map on clients, so a default, uninitialized one got made on the client post world load, which had some null ptrs => crash.
To enable navigation on clients:
in UNavigationSystem::CreateNavigationSystem remove the #if and #endif lines and remove && WorldOwner->GetNetMode() != NM_Client
in ANavigationData::ANavigationData change bNetLoadOnClient = false; to bNetLoadOnClient = true;
This makes it work in PIE client, at least, there might need to be additional changes to make it work on actual client exe.
Additionally, to make pathing work on clients, you can have it just simulate controller inputs by overriding UCharacterMovementComponent like this:
bool UCharMvtComponent::ApplyRequestedMove(float DeltaTime,float MaxAccel,float MaxSpeed,float Friction,float BrakingDeceleration,FVector& OutAcceleration,float& OutRequestedSpeed)
{
if (IsUserPathing)
{
//just simulate controller inputs if the pathing was requested by client
if (bHasRequestedVelocity)
AddInputVector(RequestedVelocity / MaxSpeed);
return false;
}
return UCharacterMovementComponent::ApplyRequestedMove(DeltaTime,MaxAccel,MaxSpeed,Friction,BrakingDeceleration,OutAcceleration,OutRequestedSpeed);
}
Hi guys im trying to do pathfinding for a project and I was wondering if ye could point me to the right files which I would have to override to implement my own(D *lite) in this case.
In the DefaultEngine.ini, you can actually change bAllowClientSideNavigation to true. This at the very least makes the ANavigationData load on client. It also allows CreatNavigationSystem to create the NavSys. I haven’t tested it just yet, and I’m in 4.9.
EDIT: Just tested it. It works! I know there’s that #if statement, but if you’re game has listen clients then you’ll also compile block.