2.0 KiB
2.0 KiB
title, type, tags, sources, last_updated
| title | type | tags | sources | last_updated | |
|---|---|---|---|---|---|
| Network Prediction | concept |
|
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