Closed coolyoshi closed 3 years ago
Hey @coolyoshi, have you been able to solve this?
Hey Nick, might have a solution which I verified correctly turns off anim BPs on client. However I think I might need to setup my server before I can verify if I got any performance gains.
In RTSVisionManager.cpp Tick
Before the loop:
int ScreenSizeX = 0;
int ScreenSizeY = 0;
if (GetNetMode() != NM_DedicatedServer) {
LocalPlayerController->GetViewportSize(ScreenSizeX, ScreenSizeY);
ScreenSizeX += 100;
ScreenSizeY += 100;
}
In the loop (Updated):
if (GetNetMode() != NM_DedicatedServer)
{
// Update client vision.
ERTSVisionState NewVision = IsValid(LocalVisionInfo)
? LocalVisionInfo->GetVision(TileLocation.X, TileLocation.Y)
: ERTSVisionState::VISION_Visible;
VisibleActor.VisibleComponent->SetClientVisionState(NewVision);
ACharacter* Char = Cast<ACharacter>(VisibleActor.Actor);
if (NewVision == ERTSVisionState::VISION_Visible && Char != nullptr && LocalPlayerState != nullptr) {
FVector2D ScreenLocation;
LocalPlayerController->ProjectWorldLocationToScreen(VisibleActor.Actor->GetActorLocation(), ScreenLocation);
if (ScreenLocation.X >= -100 && ScreenLocation.X <= (ScreenSizeX) &&
ScreenLocation.Y >= -100 && ScreenLocation.Y <= (ScreenSizeY)) {
Char->GetMesh()->SetComponentTickEnabled(true);
}
else {
Char->GetMesh()->SetComponentTickEnabled(false);
}
}
else {
Char->GetMesh()->SetComponentTickEnabled(false);
}
}
Character movement component tick can also be turned off when unit isn't in viewport. In order to make it work properly also need to set NetworkSmoothingMode to disabled and re-enable it when unit goes back into viewport. Not sure if this is the best way for optimization but it does seem to work.
@npruehs followed your guide on replication graph and it seems to work well! Just wondering if you might know a way the client can tell the server to reduce the NetUpdateFrequency for a particular actor, and reduce the NetUpdateFrequency for only one player without affecting other players? I'm trying to find ways to optimize bandwidth usage for actors that are outside the client's viewport but still visible and so far this is the only idea I can think of
Nvm I heard it's not possible so ended up setting netupdate frequency to 0.00001 for all units and using ForceNetUpdate calls
Update: Closing issue because these methods haven't been fully tested. Don't want to mislead people just incase.
Actually nvm