Actor
开启Replicate
UE中, 对于需要Replicate
的Actor
,
需要将AActor.bReplicates
设置为true
.
方法1:
SpawnActor
之后调用AActor.SetReplicates
将其变成可Replicate
.
方法2:
在构造函数中将AActor.bReplicates
设置为true
.
AActor.bReplicates
控制的是哪里的流程?
对于动态创建的Actor
,
在将其添加到ReplicationGraph
的时候,
会检测其是否需要Replicate
.
--UWorld::SpawnActor() |--UWorld::AddNetworkActor() | |--//
遍历所有NetDriver, 并将Actor添加到其中 |
|--Driver->AddNetworkActor(Actor); | |
|--UNetDriver::AddNetworkActor() | | |
|--GetNetworkObjectList().FindOrAdd(Actor, this); | | | |--//
向ReplicationGraph中添加NetworkActor | | |
|--ReplicationDriver->AddNetworkActor(Actor); //
UReplicationGraph::AddNetworkActor | | | | |--//
检测是否需要进行Replicate | | | |
|--IsActorValidForReplicationGather() | | | | | |--AActor.GetIsReplicated() // 检测AActor的Replication
| | | | |--//
添加Actor对应的描述信息FGlobalActorReplicationInfo | | | |
|--FGlobalActorReplicationInfo& GlobalInfo =
GlobalActorReplicationInfoMap.Get(Actor); | | | | |--//
设置Dormant属性 | | | | |--GlobalInfo.bWantsToBeDormant =
Actor->NetDormancy > DORM_Awake; | | | |
|--UReplicationGraph::RouteAddNetworkActorToNodes() | | | | | |--//
针对ActorInfo.Actor->bAlwaysRelevant, 添加到AlwaysRelevantNode中
| | | | | |--AlwaysRelevantNode->NotifyAddNetworkActor(ActorInfo);
| | | | | |--// 针对ActorInfo.Actor->bOnlyRelevantToOwner,
添加到ActorsWithoutNetConnection中 | | | | |
|--ActorsWithoutNetConnection.Add(ActorInfo.Actor); | | | | | |--//
其他情况添加到GridNode中 | | | | |
|--GridNode->AddActor_Dormancy(ActorInfo, GlobalInfo); | | | | |
| |--UReplicationGraphNode_GridSpatialization2D::AddActor_Dormancy
| | | | | | |--// 如果要想要休眠, 调用AddActorInternal_Static函数 |
| | | | | |--AddActorInternal_Static(ActorInfo, ActorRepInfo, true);
| | | | | | | |--如果Actor没有Init,
则添加到UReplicationGraphNode_GridSpatialization2D.PendingStaticSpatializedActors中.
| | | | | | | |--否则添加到Static中 | | | | | | |
|--UReplicationGraphNode_GridSpatialization2D.AddActorInternal_Static_Implementation()
| | | | | | |
|--UReplicationGraphNode_GridSpatialization2D.AddActorInternal_Static_Implementation()
| | | | | | |--// 否则, 调用AddActorInternal_Dynamic | | | | |
| |--AddActorInternal_Dynamic(ActorInfo); | | | | | | | |--//
放入了UReplicationGraphNode_GridSpatialization2D.DynamicSpatializedActors中
| | | | | | | |--DynamicSpatializedActors.Emplace(ActorInfo.Actor,
ActorInfo);
|
ActorComponent
开启Replicate
UE中, 对于需要Replicate
的ActorComponent
,
需要将UActorComponent.bReplicates
设置为true
.
1
| UActorComponent.SetIsReplicatedByDefault
|
自定义UObject
开启Replicate
参考:自定义UObject进行Replicate