Files
nexus/wiki/concepts/Network-Prediction.md
2026-04-26 12:02:53 +08:00

46 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Network Prediction"
type: concept
tags: []
sources: [unreal-multiplayer-architect]
last_updated: 2026-04-26
---
## Definition
网络预测是 UE5 多人游戏中减少客户端感知延迟的核心技术。客户端在发送输入到服务器的同时本地执行游戏逻辑预测结果当服务器确认结果返回时客户端对比并调和Reconcile任何差异。
## Why It Matters
即使服务器在 100ms 后才返回结果,客户端通过预测可以让玩家感受到即时响应:
```
客户端发送输入 → 本地预测执行 → 显示预测结果(立即)→ 服务器执行 → 客户端调和100ms后
```
## Prediction in UE5
- **Movement Prediction**:角色移动在客户端本地预测
- **Ability Prediction (GAS)**`FPredictionKey` 标记所有预测变更,服务器确认或回滚
- **Reconciliation**:服务器权威结果与客户端预测结果对比时,自动校正客户端状态
## Key Methods
- `NetMulticast Unreliable` — 服务器向所有客户端广播,用于触发预测性的视觉效果
- `FPredictionKey` — GAS 中的预测键,标记可预测的能力和属性变更
- `p.NetShowCorrections 1` — 调试命令,可视化调和事件
## Prediction Pitfalls
- 过度预测会导致大量回滚Rollback影响游戏体验
- 仅预测确定性输入(移动、射击)——不预测随机事件
- 在高延迟(>200ms环境下需要特别调优预测容差
## Connection to Other Concepts
- [[Server-Authoritative Model]] — 预测依赖服务器最终权威结果
- [[Actor Replication]] — 复制的状态是预测和调和的数据基础
- [[RPC (Remote Procedure Call)]] — 客户端通过 Server RPC 发送输入触发预测
## Relationship to Agent
[[UnrealMultiplayerArchitect]] 强调:"Desync events (reconciliations) < 1 per player per 30 seconds at 200ms ping" 是成功指标,网络预测的质量直接影响该指标。
## Aliases
- Client-Side Prediction
- Rollback Prediction
- Reconciliation