diff --git a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs index d1ac2fd4e..5a24ea621 100644 --- a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs +++ b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs @@ -86,6 +86,9 @@ public class PredictedRigidbody : NetworkBehaviour public Material localGhostMaterial; public Material remoteGhostMaterial; + [Tooltip("Performance optimization: only create/destroy ghosts every n-th frame is enough.")] + public int checkGhostsEveryNthFrame = 4; + [Tooltip("How fast to interpolate to the target position, relative to how far we are away from it.\nHigher value will be more jitter but sharper moves, lower value will be less jitter but a little too smooth / rounded moves.")] public float positionInterpolationSpeed = 15; // 10 is a little too low for billiards at least public float rotationInterpolationSpeed = 10; @@ -386,6 +389,10 @@ protected virtual bool IsMoving() => void UpdateGhosting() { + // perf: enough to check ghosts every few frames. + // PredictionBenchmark: only checking every 4th frame: 585 => 600 FPS + if (Time.frameCount % checkGhostsEveryNthFrame != 0) return; + // client only uses ghosts on demand while interacting. // this way 1000 GameObjects don't need +1000 Ghost GameObjects all the time! diff --git a/Assets/Mirror/Examples/BenchmarkPrediction/Readme.md b/Assets/Mirror/Examples/BenchmarkPrediction/Readme.md index fecdc7063..9573d41f1 100644 --- a/Assets/Mirror/Examples/BenchmarkPrediction/Readme.md +++ b/Assets/Mirror/Examples/BenchmarkPrediction/Readme.md @@ -17,3 +17,4 @@ Not Predicted: 1000 FPS Client, 2500 FPS Server Predicted: 2024-03-13: 500 FPS Client, 1700 FPS Server 2024-03-13: 580 FPS Client, 1700 FPS Server // micro optimizations + 2024-03-14: 590 FPS Client, 1700 FPS Server // UpdateGhosting() every 4th frame