Component Replication归属权

创建一个Component后, 其由哪个Actor负责传输呢? 放到其Owner的ActorChannel里面进行传输.

查看如下代码, UTestRepFlowSpawnedCmp的传输由ABasePlayerController负责. 即其归属于ABasePlayerController的ActorChannel. UTestRepFlowSpawnedCmp对应的FObjectReplicator存储在ABasePlayerController ActorChannelUActorChannel.ReplicationMap中.

原因: 关键函数NewObject中经过层层调用, 最终调用了AActor.AddOwnedComponent, 将该ActorComponent放入了其UActorComponent.OwnerPrivateAActor.ReplicatedComponents中.

AActor.ReplicateSubobjects中, 遍历所有AActor.ReplicatedComponents进行Replication.

延伸: 当其Outer不是Actor怎么办呢? 递归寻找其Outer, 直到找到一个为Actor类型的为止.

总结: ActorComponent的网络归属跟Outer有关, 跟谁在使用它无关.