|
UE4 网络概念
总览
Ue4 网络设计概念客户端是服务器的模拟,服务器有所有客户端play的场景,带物理
1, 服务器复制数据给客户端
2, 客户端只和服务器对话
3, 可以通过RPCs 互相调用
网络复制
1, C++ replication
GameState是GameMode的复制
PlayerState是PlayerController的复制
a) Actor上 Replicate属性
b) UPROPERTY 宏中 Replicated 和ReplicatedUsing
UPROPERTY(Transient, Replicated)
GetLifetimeReplicatedProps收集复制属性
void AActor::GetLifetimeReplicatedProps( TArray< FLifetimeProperty > & OutLifetimeProps ) const
{
UBlueprintGeneratedClass* BPClass = Cast<UBlueprintGeneratedClass>(GetClass());
if (BPClass != NULL)
{
BPClass->GetLifetimeBlueprintReplicationList(OutLifetimeProps);
}
DOREPLIFETIME( AActor, bReplicateMovement );
DOREPLIFETIME( AActor, Role );
DOREPLIFETIME( AActor, RemoteRole );
DOREPLIFETIME( AActor, Owner );
DOREPLIFETIME( AActor, bHidden );
DOREPLIFETIME( AActor, bTearOff );
DOREPLIFETIME( AActor, bCanBeDamaged );
DOREPLIFETIME_CONDITION( AActor, AttachmentReplication, COND_Custom );
DOREPLIFETIME( AActor, Instigator );
DOREPLIFETIME_CONDITION( AActor, ReplicatedMovement, COND_SimulatedOrPhysics );
} c) 条件触发复制
DOREPLIFETIME_CONDITION(AActor,ReplicatedMovement,COND_SimulatedOrPhysics );
2, 函数复制
UFunction修饰宏Reliable,Unreliable, Server,Client NetMulticast等
Reliable 需要回复 错误重发
Unreliable 不需要回复, 错误不会重发
NetMulticast 广播给所有客户端
BlueprintAuthorityOnly 只有网络才会运行
BlueprintCosmetic 将不会运行在服务器上
3, 蓝图复制
a) Actor复制

b) 属性复制

c) 属性回复

d) 蓝图函数运行在服务器

基础网络架构概念
UNetDriver
服务器上包含多个Connection
客户端上只有1个Connection
UNetConnection
包含多个channel列表用于复制
UChannel
转发数据给Object
UControlChannel
UActorChannel |
|